From 7019ed9aa323c41825a4dbb9cda6b87d7193dc78 Mon Sep 17 00:00:00 2001 From: DJ Gill Date: Thu, 8 Feb 2024 12:02:26 -0500 Subject: [PATCH] Add Initial Prom Metrics For Load Balancer Count (#166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add inital prom metrics for lb count Signed-off-by: Dejon Gill * Sepearate create/delete counts Signed-off-by: Dejon Gill * lbdata can be nil here use the id from the event (#168) Signed-off-by: Matt Siwiec * metadata status integration (#167) Signed-off-by: Matt Siwiec * Add guard on create deployment if lb location is in operator watched locations (#170) * √√ on create deployment if lb location is in operator watched locations Signed-off-by: Matt Siwiec * changes test needs location Signed-off-by: Matt Siwiec --------- Signed-off-by: Matt Siwiec * Publish Metering Event on Metadata Status Update (#172) * publish metering event Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * use changeset instead of eventtype Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * use EventMessage Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * remove extraneous config, add warn Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * bump go Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> * Update Dockerfile Signed-off-by: sthwang-metal <126002920+sthwang-metal@users.noreply.github.com> * Update Dockerfile Signed-off-by: sthwang-metal <126002920+sthwang-metal@users.noreply.github.com> * Update Dockerfile Signed-off-by: sthwang-metal <126002920+sthwang-metal@users.noreply.github.com> --------- Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> Signed-off-by: sthwang-metal <126002920+sthwang-metal@users.noreply.github.com> * Allow trailing comments in blocks for TODOs Signed-off-by: Dejon Gill * linter Signed-off-by: Dejon Gill --------- Signed-off-by: Dejon Gill Signed-off-by: Matt Siwiec Signed-off-by: Stephen Hwang <126002920+sthwang-metal@users.noreply.github.com> Signed-off-by: sthwang-metal <126002920+sthwang-metal@users.noreply.github.com> Co-authored-by: Matt Siwiec Co-authored-by: sthwang-metal <126002920+sthwang-metal@users.noreply.github.com> --- .golangci.yml | 2 ++ internal/srv/app_test.go | 1 + internal/srv/changes.go | 4 ++++ internal/srv/changes_test.go | 2 -- internal/srv/handlers.go | 2 ++ internal/srv/prom.go | 25 +++++++++++++++++++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 internal/srv/prom.go diff --git a/.golangci.yml b/.golangci.yml index 28aad9b8..b174449f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,8 @@ linters-settings: goimports: local-prefixes: go.infratographer.com/load-balancer-operator + wsl: + allow-trailing-comment: true linters: enable: diff --git a/internal/srv/app_test.go b/internal/srv/app_test.go index abd2cc34..e3eb2dd5 100644 --- a/internal/srv/app_test.go +++ b/internal/srv/app_test.go @@ -503,6 +503,7 @@ func (suite *srvTestSuite) TestAttachRoleBinding() { t.Fatal(err) } } + err = attachRoleBinding(srv.Context, cli, tcase.namespace) if tcase.expectErr { diff --git a/internal/srv/changes.go b/internal/srv/changes.go index c5343a4c..d8f79136 100644 --- a/internal/srv/changes.go +++ b/internal/srv/changes.go @@ -12,6 +12,8 @@ func (s *Server) processLoadBalancerChangeCreate(ctx context.Context, lb *loadBa return err } + numberLoadBalancersCreatedGauge.Inc() + return nil } @@ -25,6 +27,8 @@ func (s *Server) processLoadBalancerChangeDelete(ctx context.Context, lb *loadBa return err } + numberLoadBalancersDeletedGauge.Inc() + return nil } diff --git a/internal/srv/changes_test.go b/internal/srv/changes_test.go index 6d34072f..878cd962 100644 --- a/internal/srv/changes_test.go +++ b/internal/srv/changes_test.go @@ -106,7 +106,6 @@ func (suite *srvTestSuite) TestProcessLoadBalancerChangeCreate() { //nolint:gove } else { assert.Nil(suite.T(), err) } - // TODO: check if the namespace was created // TODO: check if the helm release exists }) @@ -197,7 +196,6 @@ func (suite *srvTestSuite) TestProcessLoadBalancerDelete() { //nolint:govet assert.Error(suite.T(), err) } else { assert.Nil(suite.T(), err) - // TODO: check if the release is missing // TODO: check if the namespace is missing } diff --git a/internal/srv/handlers.go b/internal/srv/handlers.go index 8d03c6db..ecccc452 100644 --- a/internal/srv/handlers.go +++ b/internal/srv/handlers.go @@ -142,8 +142,10 @@ func prepareLoadBalancer[M Message](ctx context.Context, msg M, s *Server) (*loa err = errLoadBalancerInit span.RecordError(err) span.SetStatus(codes.Error, err.Error()) + return nil, err } + span.SetAttributes(attribute.Bool("lbdata-lookup", true)) } diff --git a/internal/srv/prom.go b/internal/srv/prom.go new file mode 100644 index 00000000..736ef54d --- /dev/null +++ b/internal/srv/prom.go @@ -0,0 +1,25 @@ +package srv + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +const subsystem = "load_balancer_operator" + +var ( + numberLoadBalancersCreatedGauge = promauto.NewGauge( + prometheus.GaugeOpts{ + Subsystem: subsystem, + Name: "load_balancers_created", + Help: "Total count of load balancers created", + }, + ) + numberLoadBalancersDeletedGauge = promauto.NewGauge( + prometheus.GaugeOpts{ + Subsystem: subsystem, + Name: "load_balancers_deleted", + Help: "Total count of load balancers deleted", + }, + ) +)