Skip to content

Commit

Permalink
Merge pull request #8 from grzegorzgniadek/prom-metrics
Browse files Browse the repository at this point in the history
Prom metrics
  • Loading branch information
grzegorzgniadek authored Aug 19, 2024
2 parents 45bfa78 + 364b214 commit 6fe3c12
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 18 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.6.0-rc
5 changes: 2 additions & 3 deletions charts/interpolator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.0
version: 0.6.0-rc
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.0"

appVersion: "0.6.0-rc"
14 changes: 11 additions & 3 deletions charts/interpolator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



![Version: 0.5.0](https://img.shields.io/badge/Version-0.5.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.5.0](https://img.shields.io/badge/AppVersion-0.5.0-informational?style=flat-square)
![Version: 0.6.0-rc](https://img.shields.io/badge/Version-0.6.0--rc-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.6.0-rc](https://img.shields.io/badge/AppVersion-0.6.0--rc-informational?style=flat-square)

Interpolator Helm Chart

Expand All @@ -23,12 +23,20 @@ Interpolator Helm Chart
| controllerManager.manager.containerSecurityContext.allowPrivilegeEscalation | bool | `false` | |
| controllerManager.manager.containerSecurityContext.capabilities.drop[0] | string | `"ALL"` | |
| controllerManager.manager.image.repository | string | `"ghcr.io/grzegorzgniadek/interpolator-operator"` | |
| controllerManager.manager.image.tag | string | `"0.5.0"` | |
| controllerManager.manager.image.tag | string | `"0.6.0-rc"` | |
| controllerManager.manager.imagePullPolicy | string | `"Always"` | |
| controllerManager.manager.resources.limits.cpu | string | `"200m"` | |
| controllerManager.manager.resources.limits.memory | string | `"128Mi"` | |
| controllerManager.manager.resources.requests.cpu | string | `"10m"` | |
| controllerManager.manager.resources.requests.memory | string | `"64Mi"` | |
| controllerManager.replicas | int | `1` | |
| controllerManager.serviceAccount.annotations | object | `{}` | |
| kubernetesClusterDomain | string | `"cluster.local"` | |
| kubernetesClusterDomain | string | `"cluster.local"` | |
| metricsService.enabled | bool | `true` | |
| metricsService.ports[0].name | string | `"http"` | |
| metricsService.ports[0].port | int | `8080` | |
| metricsService.ports[0].protocol | string | `"TCP"` | |
| metricsService.ports[0].targetPort | int | `8080` | |
| metricsService.type | string | `"ClusterIP"` | |
| prometheusMonitor.enabled | bool | `false` | |
| prometheusMonitor.path | string | `"/metrics"` | |
17 changes: 17 additions & 0 deletions charts/interpolator/templates/metrics-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.prometheusMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "interpolator.fullname" . }}-metrics-monitor
labels:
control-plane: controller-manager
{{- include "interpolator.labels" . | nindent 4 }}
spec:
endpoints:
- path: {{ .Values.prometheusMonitor.path }}
port: http
scheme: http
selector:
matchLabels:
control-plane: controller-manager
{{- end -}}
16 changes: 16 additions & 0 deletions charts/interpolator/templates/metrics-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.metricsService.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: {{ include "interpolator.fullname" . }}-metrics-service
labels:
control-plane: controller-manager
{{- include "interpolator.labels" . | nindent 4 }}
spec:
type: {{ .Values.metricsService.type }}
selector:
control-plane: controller-manager
{{- include "interpolator.selectorLabels" . | nindent 4 }}
ports:
{{- .Values.metricsService.ports | toYaml | nindent 2 }}
{{- end -}}
13 changes: 12 additions & 1 deletion charts/interpolator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ controllerManager:
- ALL
image:
repository: ghcr.io/grzegorzgniadek/interpolator-operator
tag: 0.5.0
tag: 0.6.0-rc
imagePullPolicy: Always
resources:
limits:
Expand All @@ -23,3 +23,14 @@ controllerManager:
serviceAccount:
annotations: {}
kubernetesClusterDomain: cluster.local
metricsService:
enabled: true
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
type: ClusterIP
prometheusMonitor:
enabled: false
path: /metrics
23 changes: 18 additions & 5 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ resources:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml
- ../prometheus

# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
#patches:
Expand All @@ -33,7 +31,7 @@ resources:
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
# kind: Deployment

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand All @@ -46,7 +44,6 @@ resources:

# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
# Uncomment the following replacements to add the cert-manager CA injection annotations
#replacements:
# - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
# kind: Certificate
# group: cert-manager.io
Expand Down Expand Up @@ -143,3 +140,19 @@ resources:
# delimiter: '.'
# index: 1
# create: true
replacements:
- source:
kind: Deployment
name: controller-manager
fieldPath: .metadata.namespace
targets:
- select:
kind: ClusterRoleBinding
name: manager-rolebinding
fieldPaths:
- .subjects.0.namespace
- select:
kind: RoleBinding
name: leader-election-rolebinding
fieldPaths:
- .subjects.0.namespace
4 changes: 3 additions & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
resources:
- manager.yaml
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
- metrics_service.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: ghcr.io/grzegorzgniadek/interpolator-operator
newTag: "0.5.0"
newTag: "0.6.0-rc"
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
control-plane: controller-manager
app.kubernetes.io/name: interpolator-operator
app.kubernetes.io/managed-by: kustomize
name: interpolator-operator-system
name: system
---
apiVersion: apps/v1
kind: Deployment
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ resources:
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
# if you do not want those helpers be installed with your Project.
- interpolator_editor_role.yaml
- interpolator_viewer_role.yaml

- editor_role.yaml
- viewer_role.yaml
File renamed without changes.
10 changes: 10 additions & 0 deletions internal/controller/interpolator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ func (r *InterpolatorReconciler) Reconcile(ctx context.Context, req ctrl.Request

// Fetch the Interpolator instance
interpolator := &interpolatorv1.Interpolator{}
interpolatorList := &interpolatorv1.InterpolatorList{}

if err := r.List(ctx, interpolatorList); err != nil {
log.Error(err, "failed to list custom resources")

return ctrl.Result{}, nil
}
count := len(interpolatorList.Items)
interCount.Set(float64(count))

err := r.Get(ctx, req.NamespacedName, interpolator)
if err != nil {
if apierrors.IsNotFound(err) {
Expand Down
20 changes: 20 additions & 0 deletions internal/controller/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package controller

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

var (
interCount = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "inter_count",
Help: "Count of inter resources",
},
)
)

func init() {
// Register custom metrics with the global prometheus registry
metrics.Registry.MustRegister(interCount)
}

0 comments on commit 6fe3c12

Please sign in to comment.