Skip to content

Commit aecb4bb

Browse files
authored
Merge pull request #732 from zeeke/metrics-exporter-rules
[metrics 4/x] Metrics exporter rules
2 parents 8526311 + b49cf15 commit aecb4bb

File tree

13 files changed

+277
-3
lines changed

13 files changed

+277
-3
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
{{ if and .IsPrometheusOperatorInstalled .PrometheusOperatorDeployRules }}
3+
apiVersion: monitoring.coreos.com/v1
4+
kind: PrometheusRule
5+
metadata:
6+
name: sriov-vf-rules
7+
namespace: {{.Namespace}}
8+
spec:
9+
groups:
10+
- name: sriov-network-metrics-operator.rules
11+
interval: 30s
12+
rules:
13+
- expr: |
14+
sriov_vf_tx_packets * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
15+
record: network:sriov_vf_tx_packets
16+
- expr: |
17+
sriov_vf_rx_packets * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
18+
record: network:sriov_vf_rx_packets
19+
- expr: |
20+
sriov_vf_tx_bytes * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
21+
record: network:sriov_vf_tx_bytes
22+
- expr: |
23+
sriov_vf_rx_bytes * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
24+
record: network:sriov_vf_rx_bytes
25+
- expr: |
26+
sriov_vf_tx_dropped * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
27+
record: network:sriov_vf_tx_dropped
28+
- expr: |
29+
sriov_vf_rx_dropped * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
30+
record: network:sriov_vf_rx_dropped
31+
- expr: |
32+
sriov_vf_rx_broadcast * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
33+
record: network:sriov_vf_rx_broadcast
34+
- expr: |
35+
sriov_vf_rx_multicast * on (pciAddr) group_left(pod,namespace,dev_type) sriov_kubepoddevice
36+
record: network:sriov_vf_rx_multicast
37+
{{ end }}
38+

controllers/sriovoperatorconfig_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func (r *SriovOperatorConfigReconciler) syncMetricsExporter(ctx context.Context,
241241
data.Data["IsOpenshift"] = r.PlatformHelper.IsOpenshiftCluster()
242242

243243
data.Data["IsPrometheusOperatorInstalled"] = strings.ToLower(os.Getenv("METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED")) == trueString
244+
data.Data["PrometheusOperatorDeployRules"] = strings.ToLower(os.Getenv("METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULES")) == trueString
244245
data.Data["PrometheusOperatorServiceAccount"] = os.Getenv("METRICS_EXPORTER_PROMETHEUS_OPERATOR_SERVICE_ACCOUNT")
245246
data.Data["PrometheusOperatorNamespace"] = os.Getenv("METRICS_EXPORTER_PROMETHEUS_OPERATOR_NAMESPACE")
246247

controllers/sriovoperatorconfig_controller_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
380380
It("should deploy extra configuration when the Prometheus operator is installed", func() {
381381
DeferCleanup(os.Setenv, "METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED", os.Getenv("METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED"))
382382
os.Setenv("METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED", "true")
383+
DeferCleanup(os.Setenv, "METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULES", os.Getenv("METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULES"))
384+
os.Setenv("METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULES", "true")
383385

384386
err := util.WaitForNamespacedObject(&rbacv1.Role{}, k8sClient, testNamespace, "prometheus-k8s", util.RetryInterval, util.APITimeout)
385387
Expect(err).ToNot(HaveOccurred())
@@ -394,6 +396,14 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
394396
Version: "v1",
395397
},
396398
client.ObjectKey{Namespace: testNamespace, Name: "sriov-network-metrics-exporter"})
399+
400+
assertResourceExists(
401+
schema.GroupVersionKind{
402+
Group: "monitoring.coreos.com",
403+
Kind: "PrometheusRule",
404+
Version: "v1",
405+
},
406+
client.ObjectKey{Namespace: testNamespace, Name: "sriov-vf-rules"})
397407
})
398408
})
399409
})

deploy/operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ spec:
7878
value: $METRICS_EXPORTER_KUBE_RBAC_PROXY_IMAGE
7979
- name: METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED
8080
value: "$METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED"
81+
- name: METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULES
82+
value: "$METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULES"
8183
- name: METRICS_EXPORTER_PROMETHEUS_OPERATOR_SERVICE_ACCOUNT
8284
value: $METRICS_EXPORTER_PROMETHEUS_OPERATOR_SERVICE_ACCOUNT
8385
- name: METRICS_EXPORTER_PROMETHEUS_OPERATOR_NAMESPACE

deploy/role.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ rules:
2929
- monitoring.coreos.com
3030
resources:
3131
- servicemonitors
32+
- prometheusrules
3233
verbs:
3334
- get
3435
- create
36+
- update
37+
- delete
3538
- apiGroups:
3639
- apps
3740
resourceNames:

deployment/sriov-network-operator-chart/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ We have introduced the following Chart parameters.
8989
| `operator.metricsExporter.prometheusOperator.enabled` | bool | false | Wheter the operator shoud configure Prometheus resources or not (e.g. `ServiceMonitors`). |
9090
| `operator.metricsExporter.prometheusOperator.serviceAccount` | string | `prometheus-k8s` | The service account used by the Prometheus Operator. This is used to give Prometheus the permission to list resource in the SR-IOV operator namespace |
9191
| `operator.metricsExporter.prometheusOperator.namespace` | string | `monitoring` | The namespace where the Prometheus Operator is installed. Setting this variable makes the operator deploy `monitoring.coreos.com` resources. |
92+
| `operator.metricsExporter.prometheusOperator.deployRules` | bool | false | Whether the operator should deploy `PrometheusRules` to scrape namespace version of metrics. |
9293

9394
#### Admission Controllers parameters
9495

deployment/sriov-network-operator-chart/templates/operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ spec:
8383
{{- if .Values.operator.metricsExporter.prometheusOperator.enabled }}
8484
- name: METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED
8585
value: {{ .Values.operator.metricsExporter.prometheusOperator.enabled | quote}}
86+
- name: METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULES
87+
value: {{ .Values.operator.metricsExporter.prometheusOperator.deployRules | quote}}
8688
- name: METRICS_EXPORTER_PROMETHEUS_OPERATOR_SERVICE_ACCOUNT
8789
value: {{ .Values.operator.metricsExporter.prometheusOperator.serviceAccount }}
8890
- name: METRICS_EXPORTER_PROMETHEUS_OPERATOR_NAMESPACE

deployment/sriov-network-operator-chart/templates/role.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ rules:
3232
- monitoring.coreos.com
3333
resources:
3434
- servicemonitors
35+
- prometheusrules
3536
verbs:
3637
- get
3738
- create
39+
- update
40+
- delete
3841
- apiGroups:
3942
- apps
4043
resourceNames:

deployment/sriov-network-operator-chart/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ operator:
3535
enabled: false
3636
serviceAccount: "prometheus-k8s"
3737
namespace: "monitoring"
38+
deployRules: false
3839
admissionControllers:
3940
enabled: false
4041
certificates:

hack/run-e2e-conformance-virtual-ocp.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export DEV_MODE=TRUE
191191
export CLUSTER_HAS_EMULATED_PF=TRUE
192192
export OPERATOR_LEADER_ELECTION_ENABLE=true
193193
export METRICS_EXPORTER_PROMETHEUS_OPERATOR_ENABLED=true
194+
export METRICS_EXPORTER_PROMETHEUS_DEPLOY_RULE=true
194195
export METRICS_EXPORTER_PROMETHEUS_OPERATOR_SERVICE_ACCOUNT=${METRICS_EXPORTER_PROMETHEUS_OPERATOR_SERVICE_ACCOUNT:-"prometheus-k8s"}
195196
export METRICS_EXPORTER_PROMETHEUS_OPERATOR_NAMESPACE=${METRICS_EXPORTER_PROMETHEUS_OPERATOR_NAMESPACE:-"openshfit-monitoring"}
196197

0 commit comments

Comments
 (0)