kubedb / project

KubeDB Enhancement & Issues
Apache License 2.0
1 stars 0 forks source link

*: MetricRelabelings feature KubeDB managed ServiceMonitors #1

Open tamalsaha opened 5 months ago

tamalsaha commented 5 months ago

We have been cleaning up our metrics from prometheus and I found out that we are not able to define metricRelabelings for service monitor created by kubedb mysql. It would be great to have that feature.

E.g. in bitnami mysql helm chart you can see an implementation example. There is metrics.serviceMonitor.metricRelabelings value available which can be defined as follows:

metrics:
  serviceMonitor:
    metricRelabelings:
       - action: keep
         regex: (mysql_global_status_aborted_clients|....)
         sourceLabels:
           - __name__

So in your case the metricRelabelings should be definiable in here:

$ kubectl explain mysql.spec.monitor.prometheus.serviceMonitor
GROUP:      [kubedb.com](http://kubedb.com/)
KIND:       MySQL
VERSION:    v1alpha2

FIELD: serviceMonitor <Object>

DESCRIPTION:
    <empty>
FIELDS:
  interval      <string>
  labels        <map[string]string>
tamalsaha commented 5 months ago

Historically, we have avoided making the service monitor too customizable because I am worried the the MySQL crd will become an amalgamation of both MySQL and ServiceMonitor crds. What we have recommended users to do is this:

Create the MySQL crd with the monitoring agent "prometheus.io" instead of "prometheus.io/operator". This will inject the prometheus exporter sidecar but not create the ServiceMonitor. Then users can create the ServiceMonitor separately and use all the fields from the ServiceMonitor crd that they seem fit.

apiVersion: kubedb.com/v1alpha2
kind: MySQL
metadata:
  name: coreos-prom-mysql
  namespace: demo
spec:
  version: "8.0.35"
  terminationPolicy: WipeOut
  storage:
    storageClassName: "standard"
    accessModes:
    - ReadWriteOnce
    resources:
      requests:
        storage: 1Gi
  monitor:
    agent: [prometheus.io](http://prometheus.io/)
    prometheus:
      serviceMonitor:
        labels:
          release: prometheus
        interval: 10s