Skip to content

Commit

Permalink
Make DaemonSet metrics scrapable (#215)
Browse files Browse the repository at this point in the history
We do this by adding the prometheus service label + port to the container.

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>

Co-authored-by: Alex Kalenyuk <akalenyu@redhat.com>
  • Loading branch information
kubevirt-bot and akalenyu authored Jan 28, 2022
1 parent 794666f commit 6a0f1ab
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/controller/hostpathprovisioner/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ func (r *ReconcileHostPathProvisioner) createCSIDaemonSetObject(cr *hostpathprov
pathMounts := buildVolumeMountsFromStoragePoolInfo(storagePoolPaths)
biDirectional := corev1.MountPropagationBidirectional
labels := getRecommendedLabels()
labels[PrometheusLabelKey] = PrometheusLabelValue
ds := &appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Expand Down Expand Up @@ -557,6 +558,11 @@ func (r *ReconcileHostPathProvisioner) createCSIDaemonSetObject(cr *hostpathprov
Name: "healthz",
Protocol: corev1.ProtocolTCP,
},
{
ContainerPort: 8080,
Name: "metrics",
Protocol: corev1.ProtocolTCP,
},
},
LivenessProbe: &corev1.Probe{
FailureThreshold: 5,
Expand Down
25 changes: 25 additions & 0 deletions pkg/controller/hostpathprovisioner/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ var _ = Describe("Controller reconcile loop", func() {
table.Entry("longNamecr", createStoragePoolWithTemplateLongNameCr(), hashedLongStoragePoolNameDataDir),
)

table.DescribeTable("DaemonSet should have prometheus labels, port", func(cr *hppv1.HostPathProvisioner, volumeMountName string) {
cr, r, cl = createDeployedCr(cr)
ds := &appsv1.DaemonSet{
ObjectMeta: v1.ObjectMeta{
Name: fmt.Sprintf("%s-csi", MultiPurposeHostPathProvisionerName),
Namespace: testNamespace,
},
}
dsNN := client.ObjectKeyFromObject(ds)
err := cl.Get(context.TODO(), dsNN, ds)
Expect(err).NotTo(HaveOccurred())
port := corev1.ContainerPort{
ContainerPort: 8080,
Name: "metrics",
Protocol: corev1.ProtocolTCP,
}
Expect(ds.Spec.Template.Spec.Containers[0].Ports).To(ContainElement(port))
Expect(ds.Labels[PrometheusLabelKey]).To(Equal(PrometheusLabelValue))
Expect(ds.Spec.Template.Labels[PrometheusLabelKey]).To(Equal(PrometheusLabelValue))
},
table.Entry("legacyCr", createLegacyCr(), legacyDataDir),
table.Entry("legacyStoragePoolCr", createLegacyStoragePoolCr(), legacyStoragePoolDataDir),
table.Entry("storagePoolCr", createStoragePoolWithTemplateCr(), localDataDir),
)

table.DescribeTable("Should create daemonset with node placement", func(dsName string) {
req := reconcile.Request{
NamespacedName: types.NamespacedName{
Expand Down
14 changes: 14 additions & 0 deletions pkg/controller/hostpathprovisioner/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ func getAlertRules() []promv1.Rule {
componentAlertLabelKey: componentAlertLabelValue,
},
),
generateAlertRule(
"HPPSharingPoolPathWithOS",
"kubevirt_hpp_pool_path_shared_with_os == 1",
"1m",
map[string]string{
"summary": "HPP pool path sharing a filesystem with OS, fix to prevent HPP PVs from causing disk pressure and affecting node operation",
"runbook_url": runbookURLBasePath + "HPPSharingPoolPathWithOS",
},
map[string]string{
severityAlertLabelKey: "warning",
partOfAlertLabelKey: partOfAlertLabelValue,
componentAlertLabelKey: componentAlertLabelValue,
},
),
}
}

Expand Down

0 comments on commit 6a0f1ab

Please sign in to comment.