Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add operator metrics #24

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading