Skip to content
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
35 changes: 29 additions & 6 deletions internal/controller/metricstorage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,12 @@ func (r *MetricStorageReconciler) createScrapeConfigs(
return ctrl.Result{}, err
}

// ScrapeConfig for InstanceHA metrics
err = r.createInstanceHAScrapeConfig(ctx, instance, helper, serviceLabels)
if err != nil {
return ctrl.Result{}, err
}

instance.Status.Conditions.MarkTrue(telemetryv1.ScrapeConfigReadyCondition, condition.ReadyMessage)
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -1112,6 +1118,25 @@ func (r *MetricStorageReconciler) createOVSDBServerSBScrapeConfig(
)
}

// createInstanceHAScrapeConfig creates a scrape configuration for InstanceHA metrics
// This function discovers InstanceHA metrics services using label selectors
func (r *MetricStorageReconciler) createInstanceHAScrapeConfig(
ctx context.Context,
instance *telemetryv1.MetricStorage,
helper *helper.Helper,
serviceLabels map[string]string,
) error {
labelSelector := map[string]string{
"metrics": "enabled",
"service": "instanceha",
}
instancehaCfgName := fmt.Sprintf("%s-instanceha", telemetry.ServiceName)
return r.createServiceScrapeConfigFromLabelSelector(
ctx, instance, helper, serviceLabels,
labelSelector, "metrics", instancehaCfgName, "InstanceHA",
)
}

func (r *MetricStorageReconciler) createDashboardObjects(ctx context.Context, instance *telemetryv1.MetricStorage, helper *helper.Helper, eventHandler handler.EventHandler, serviceLabels map[string]string) (ctrl.Result, error) {
Log := r.GetLogger(ctx)
uiPluginObj := &obsui.UIPlugin{
Expand Down Expand Up @@ -1492,13 +1517,11 @@ func (r *MetricStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl
return nil
}

ovnMetricsServiceWatchFn := func(_ context.Context, o client.Object) []reconcile.Request {
metricsServiceWatchFn := func(_ context.Context, o client.Object) []reconcile.Request {
result := []reconcile.Request{}

// Watch OVN metrics services
if labels := o.GetLabels(); labels != nil {
if labels["metrics"] == "enabled" && (labels["service"] == "ovn-northd" || labels["service"] == "ovn-controller-metrics" || labels["service"] == "ovsdbserver-nb" || labels["service"] == "ovsdbserver-sb") {
// get all metricstorage CRs in the same namespace
if labels["metrics"] == "enabled" && (labels["service"] == "ovn-northd" || labels["service"] == "ovn-controller-metrics" || labels["service"] == "ovsdbserver-nb" || labels["service"] == "ovsdbserver-sb" || labels["service"] == "instanceha") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything against leaving this just with "if labels["metrics"]" instead of having to maintain a (maybe) growing list of services that do not offer too much advantages

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you tell me :) I just didn't want to abstract this too much and I thought it could prevent some "rogue" service running in the same namespace from getting a scrapeconfig when it shouldn't.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, lets leave this pattern for now and we can remove the labels maybe in a subsequent patch

metricStorages := &telemetryv1.MetricStorageList{}
listOpts := []client.ListOption{
client.InNamespace(o.GetNamespace()),
Expand All @@ -1513,7 +1536,7 @@ func (r *MetricStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl
Namespace: o.GetNamespace(),
Name: cr.Name,
}
Log.Info(fmt.Sprintf("OVN metrics service %s changed, reconciling MetricStorage CR %s", o.GetName(), cr.Name))
Log.Info(fmt.Sprintf("Metrics service %s changed, reconciling MetricStorage CR %s", o.GetName(), cr.Name))
result = append(result, reconcile.Request{NamespacedName: name})
}
}
Expand Down Expand Up @@ -1587,7 +1610,7 @@ func (r *MetricStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl
Watches(&corev1.Service{},
handler.EnqueueRequestsFromMapFunc(prometheusServiceWatchFn)).
Watches(&corev1.Service{},
handler.EnqueueRequestsFromMapFunc(ovnMetricsServiceWatchFn)).
handler.EnqueueRequestsFromMapFunc(metricsServiceWatchFn)).
Watches(
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
Expand Down
21 changes: 21 additions & 0 deletions test/kuttl/tests/metricstorage/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ spec:
---
apiVersion: monitoring.rhobs/v1alpha1
kind: ScrapeConfig
metadata:
labels:
service: metricStorage
name: telemetry-instanceha
ownerReferences:
- kind: MetricStorage
name: telemetry-kuttl
spec:
scrapeInterval: 30s
metricRelabelings:
- action: labeldrop
regex: pod
- action: labeldrop
regex: namespace
- action: labeldrop
regex: job
- action: labeldrop
regex: publisher
---
apiVersion: monitoring.rhobs/v1alpha1
kind: ScrapeConfig
metadata:
labels:
service: metricStorage
Expand Down
17 changes: 17 additions & 0 deletions test/kuttl/tests/metricstorage/01-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ spec:
pvcStorageRequest: 20G
networkAttachments: []
---
# Required, so that the instanceha scrapeconfig is created
apiVersion: v1
kind: Service
metadata:
name: instanceha-0-metrics
labels:
metrics: enabled
service: instanceha
spec:
ports:
- name: metrics
port: 8080
protocol: TCP
targetPort: 8080
selector:
service: instanceha
---
# Required, so that the mysqld_exporter scrapeconfig is created
apiVersion: telemetry.openstack.org/v1beta1
kind: Ceilometer
Expand Down
21 changes: 21 additions & 0 deletions test/kuttl/tests/metricstorage/04-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,24 @@ metadata:
name: telemetry-kuttl
spec:
scrapeInterval: 40s
---
apiVersion: monitoring.rhobs/v1alpha1
kind: ScrapeConfig
metadata:
labels:
service: metricStorage
name: telemetry-instanceha
ownerReferences:
- kind: MetricStorage
name: telemetry-kuttl
spec:
scrapeInterval: 40s
metricRelabelings:
- action: labeldrop
regex: pod
- action: labeldrop
regex: namespace
- action: labeldrop
regex: job
- action: labeldrop
regex: publisher