Skip to content

Commit

Permalink
add operator metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-haley committed May 18, 2024
1 parent 76ced78 commit 8a8dc58
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.20 as builder
FROM golang:1.22 as builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
4 changes: 4 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ spec:
- -zap-devel
image: ghcr.io/benthosdev/benthos-captain:latest
name: manager
ports:
- containerPort: 8080
name: metrics
protocol: TCP
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
8 changes: 4 additions & 4 deletions config/rbac/auth_proxy_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ metadata:
namespace: system
spec:
ports:
- name: https
port: 8443
protocol: TCP
targetPort: https
- name: https
port: 8443
protocol: TCP
targetPort: https
selector:
control-plane: controller-manager
24 changes: 24 additions & 0 deletions internal/controller/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package metrics

import (
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

var (
PipelineReconciles = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "benthos_captain",
Name: "reconciles",
Help: "reconciles per Benthos pipeline",
}, []string{"pipeline"})

PipelineFailedReconciles = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "benthos_captain",
Name: "failed_reconciles",
Help: "failed reconciles per Benthos pipeline",
}, []string{"pipeline"})
)

func init() {
metrics.Registry.MustRegister(PipelineReconciles, PipelineFailedReconciles)
}
4 changes: 4 additions & 0 deletions internal/controller/pipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

captainv1 "github.com/benthosdev/benthos-captain/api/v1alpha1"
"github.com/benthosdev/benthos-captain/internal/controller/metrics"
"github.com/benthosdev/benthos-captain/internal/pkg/resource"
)

Expand Down Expand Up @@ -72,6 +73,8 @@ func (r *PipelineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return reconcile.Result{}, err
}

metrics.PipelineReconciles.WithLabelValues(pipeline.Name).Inc()

scope := &PipelineScope{
Log: &log,
Ctx: ctx,
Expand Down Expand Up @@ -258,6 +261,7 @@ func (r *PipelineReconciler) createOrPatchDeployment(scope *PipelineScope) (ctrl
return nil
})
if err != nil {
metrics.PipelineFailedReconciles.WithLabelValues(name).Inc()
return reconcile.Result{}, errors.Wrapf(err, "Failed to reconcile deployment %s", name)
}
scope.Log.Info("Succesfully reconciled deployment", "name", name, "operation", op)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const DefaultImage = "jeffail/benthos:4.22"
const DefaultImage = "jeffail/benthos:4.27"

func NewDeployment(name string, namespace string, scope captainv1.PipelineSpec) *appsv1.Deployment {
labels := map[string]string{
Expand Down

0 comments on commit 8a8dc58

Please sign in to comment.