Skip to content

Commit 756d992

Browse files
Merge pull request #747 from karelyatin/OSPRH-12570
Add OVN Northd metric scrape config
2 parents 36dbec6 + 3b9a6bc commit 756d992

File tree

7 files changed

+128
-6
lines changed

7 files changed

+128
-6
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/onsi/ginkgo/v2 v2.20.1
77
github.com/onsi/gomega v1.34.1
88
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250821143610-c8ef7b9a21ec
9-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250730071847-837b07f8d72f
9+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03
1010
github.com/rhobs/observability-operator v0.3.1
1111
k8s.io/api v0.29.15
1212
k8s.io/apimachinery v0.29.15

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
7474
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
7575
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250821143610-c8ef7b9a21ec h1:Jvz2BuTWCvjeCbDzpPzlPMrUQpEe04Rzi8LPNxeW0Ts=
7676
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250821143610-c8ef7b9a21ec/go.mod h1:Dv8qpmBIQy3Jv/EyQnOyc0w61X8vyfxpjcIQONP5CwY=
77-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250730071847-837b07f8d72f h1:DW8aNjEtDFrWiZ6vWuOXwdRB4eBD0n+bA9foQkOEx6U=
78-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250730071847-837b07f8d72f/go.mod h1:P+7F1wiwZUxOy4myYXFyc/uBtGATDFpk3yAllXe1Vzk=
77+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03 h1:9VanDdvg1APf9B1nzGElLvWr6dM5GsSayMLSV/nJZnE=
78+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03/go.mod h1:Z+rmtn3qhuPZfx2EDVmloUh2MkYbvDMgcpJneRYerS0=
7979
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
8080
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8181
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

config/rbac/role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ rules:
280280
- list
281281
- patch
282282
- watch
283+
- apiGroups:
284+
- ovn.openstack.org
285+
resources:
286+
- ovnnorthds
287+
verbs:
288+
- get
289+
- list
290+
- watch
283291
- apiGroups:
284292
- rabbitmq.com
285293
resources:

controllers/metricstorage_controller.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import (
6262

6363
networkv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
6464
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
65+
ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
6566
telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
6667
availability "github.com/openstack-k8s-operators/telemetry-operator/pkg/availability"
6768
ceilometer "github.com/openstack-k8s-operators/telemetry-operator/pkg/ceilometer"
@@ -127,6 +128,7 @@ func (r *MetricStorageReconciler) GetLogger(ctx context.Context) logr.Logger {
127128
//+kubebuilder:rbac:groups=monitoring.rhobs,resources=alertmanagers,verbs=get;list;watch;update;patch;delete
128129
//+kubebuilder:rbac:groups=network.openstack.org,resources=ipsets,verbs=get;list;watch
129130
//+kubebuilder:rbac:groups=rabbitmq.com,resources=rabbitmqclusters,verbs=get;list;watch
131+
//+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovnnorthds,verbs=get;list;watch
130132
//+kubebuilder:rbac:groups=observability.openshift.io,resources=uiplugins,verbs=get;list;watch;create;patch
131133
//+kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete
132134
//+kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch
@@ -860,6 +862,11 @@ func (r *MetricStorageReconciler) createScrapeConfigs(
860862
if err != nil {
861863
return ctrl.Result{}, err
862864
}
865+
// ScrapeConfig for OVN Northd metrics
866+
err = r.createOVNNorthdScrapeConfig(ctx, instance, helper, serviceLabels)
867+
if err != nil {
868+
return ctrl.Result{}, err
869+
}
863870

864871
instance.Status.Conditions.MarkTrue(telemetryv1.ScrapeConfigReadyCondition, condition.ReadyMessage)
865872
return ctrl.Result{}, nil
@@ -934,6 +941,72 @@ func (r *MetricStorageReconciler) createComputeScrapeConfig(
934941
return nil
935942
}
936943

944+
func (r *MetricStorageReconciler) createOVNNorthdScrapeConfig(
945+
ctx context.Context,
946+
instance *telemetryv1.MetricStorage,
947+
helper *helper.Helper,
948+
serviceLabels map[string]string,
949+
) error {
950+
Log := r.GetLogger(ctx)
951+
952+
// Discover OVN Northd metrics services using label selectors
953+
// This matches the labels set in controllers/ovnnorthd_controller.go:647-649
954+
serviceList := &corev1.ServiceList{}
955+
listOpts := []client.ListOption{
956+
client.InNamespace(instance.Namespace),
957+
client.MatchingLabels{
958+
"type": "metrics",
959+
"service": "ovn-northd",
960+
},
961+
}
962+
err := helper.GetClient().List(ctx, serviceList, listOpts...)
963+
if err != nil {
964+
Log.Info(fmt.Sprintf("Cannot get OVN Northd metrics services. Scrape configs not created. Error: %s", err))
965+
return nil
966+
}
967+
968+
if len(serviceList.Items) == 0 {
969+
Log.Info("No OVN Northd metrics services found")
970+
return nil
971+
}
972+
973+
// Create targets from discovered services
974+
var ovnNorthdTargets []string
975+
for _, svc := range serviceList.Items {
976+
// Find the metrics port (should be named "metrics" with port 1981)
977+
for _, port := range svc.Spec.Ports {
978+
if port.Name == "metrics" {
979+
serviceRoute := fmt.Sprintf("%s.%s.svc", svc.Name, svc.Namespace)
980+
target := net.JoinHostPort(serviceRoute, strconv.Itoa(int(port.Port)))
981+
ovnNorthdTargets = append(ovnNorthdTargets, target)
982+
Log.Info(fmt.Sprintf("Found OVN Northd metrics service: %s", target))
983+
break
984+
}
985+
}
986+
}
987+
988+
if len(ovnNorthdTargets) == 0 {
989+
Log.Info("No valid OVN Northd metrics targets found")
990+
return nil
991+
}
992+
993+
// Create scrape config for OVN Northd metrics
994+
ovnNorthdCfgName := fmt.Sprintf("%s-ovn-northd", telemetry.ServiceName)
995+
desiredScrapeConfig := metricstorage.ScrapeConfig(
996+
instance,
997+
serviceLabels,
998+
ovnNorthdTargets,
999+
instance.Spec.PrometheusTLS.Enabled(),
1000+
)
1001+
err = r.createServiceScrapeConfig(ctx, instance, Log, "OVN Northd",
1002+
ovnNorthdCfgName, desiredScrapeConfig)
1003+
if err != nil {
1004+
return err
1005+
}
1006+
1007+
return nil
1008+
}
1009+
9371010
func (r *MetricStorageReconciler) createDashboardObjects(ctx context.Context, instance *telemetryv1.MetricStorage, helper *helper.Helper, eventHandler handler.EventHandler) (ctrl.Result, error) {
9381011
Log := r.GetLogger(ctx)
9391012
uiPluginObj := &obsui.UIPlugin{
@@ -1347,6 +1420,35 @@ func (r *MetricStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl
13471420
return nil
13481421
}
13491422

1423+
ovnMetricsServiceWatchFn := func(_ context.Context, o client.Object) []reconcile.Request {
1424+
result := []reconcile.Request{}
1425+
1426+
// Only watch OVN northd metrics services
1427+
if labels := o.GetLabels(); labels != nil {
1428+
if labels["type"] == "metrics" && labels["service"] == "ovn-northd" {
1429+
// get all metricstorage CRs in the same namespace
1430+
metricStorages := &telemetryv1.MetricStorageList{}
1431+
listOpts := []client.ListOption{
1432+
client.InNamespace(o.GetNamespace()),
1433+
}
1434+
if err := r.Client.List(context.Background(), metricStorages, listOpts...); err != nil {
1435+
Log.Error(err, "Unable to retrieve MetricStorage CRs %w")
1436+
return nil
1437+
}
1438+
1439+
for _, cr := range metricStorages.Items {
1440+
name := client.ObjectKey{
1441+
Namespace: o.GetNamespace(),
1442+
Name: cr.Name,
1443+
}
1444+
Log.Info(fmt.Sprintf("OVN metrics service %s changed, reconciling MetricStorage CR %s", o.GetName(), cr.Name))
1445+
result = append(result, reconcile.Request{NamespacedName: name})
1446+
}
1447+
}
1448+
}
1449+
return result
1450+
}
1451+
13501452
reconcileAllMetricStoragesWatchFn := func(_ context.Context, o client.Object) []reconcile.Request {
13511453
result := []reconcile.Request{}
13521454

@@ -1412,6 +1514,8 @@ func (r *MetricStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl
14121514
For(&telemetryv1.MetricStorage{}).
14131515
Watches(&corev1.Service{},
14141516
handler.EnqueueRequestsFromMapFunc(prometheusServiceWatchFn)).
1517+
Watches(&corev1.Service{},
1518+
handler.EnqueueRequestsFromMapFunc(ovnMetricsServiceWatchFn)).
14151519
Watches(
14161520
&corev1.Secret{},
14171521
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc),
@@ -1426,6 +1530,11 @@ func (r *MetricStorageReconciler) SetupWithManager(ctx context.Context, mgr ctrl
14261530
&rabbitmqv1.RabbitmqCluster{},
14271531
handler.EnqueueRequestsFromMapFunc(reconcileAllMetricStoragesWatchFn),
14281532
).
1533+
Watches(
1534+
&ovnv1.OVNNorthd{},
1535+
handler.EnqueueRequestsFromMapFunc(reconcileAllMetricStoragesWatchFn),
1536+
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
1537+
).
14291538
Watches(
14301539
&telemetryv1.Ceilometer{},
14311540
handler.EnqueueRequestsFromMapFunc(reconcileAllMetricStoragesWatchFn),

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ require (
1313
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250821143610-c8ef7b9a21ec
1414
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250818180001-057253e3d233
1515
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20250730071847-837b07f8d72f
16-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250730071847-837b07f8d72f
16+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03
1717
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250819151523-e1c898c710cb
18+
github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20250902142123-a16588bf7967
1819
github.com/openstack-k8s-operators/telemetry-operator/api v0.3.1-0.20240529090522-c780bd90b147
1920
github.com/rabbitmq/cluster-operator v1.14.0
2021
github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring v0.71.0-rhobs1

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250818180001
8686
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250818180001-057253e3d233/go.mod h1:qevkmDP/Yr7FTM0ZVe2fABjSjrfkkdZkYeMho71OVG0=
8787
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20250730071847-837b07f8d72f h1:7w9WseH9LSKnLX3UW1AfWPaozN7fimdVoUtOYHnsQKY=
8888
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20250730071847-837b07f8d72f/go.mod h1:0bajRHochTUT6Ecfriw27l3vL0yezVrnUmt3bcIpu4w=
89-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250730071847-837b07f8d72f h1:DW8aNjEtDFrWiZ6vWuOXwdRB4eBD0n+bA9foQkOEx6U=
90-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250730071847-837b07f8d72f/go.mod h1:P+7F1wiwZUxOy4myYXFyc/uBtGATDFpk3yAllXe1Vzk=
89+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03 h1:9VanDdvg1APf9B1nzGElLvWr6dM5GsSayMLSV/nJZnE=
90+
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03/go.mod h1:Z+rmtn3qhuPZfx2EDVmloUh2MkYbvDMgcpJneRYerS0=
9191
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250730071847-837b07f8d72f h1:nGYLHcpM7EjiSzN4bmiLZbxty9u0k0Qzvkqn+1s1TF0=
9292
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250730071847-837b07f8d72f/go.mod h1:nachFP0Yicw/e8ZlqZzvnBN6w9kjMcnqrhaDw36PGjw=
9393
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250730071847-837b07f8d72f h1:/e/jQu3GThcystmZFyzlQq6nOKpORQq84HhcbkKxAq4=
9494
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250730071847-837b07f8d72f/go.mod h1:U3LQ4Nz2+syTPfW66bSLv6OzefLpsqxWLdX9AFotRPA=
9595
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250819151523-e1c898c710cb h1:10W54mDBhON+L5PItSHV3ahOAmZH3Xi4dvEK5yhNLRE=
9696
github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20250819151523-e1c898c710cb/go.mod h1:0dWVKC1svlk2h+vyJGlKDcwgq4yJaovKXBhGZNi5tQ0=
97+
github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20250902142123-a16588bf7967 h1:r5+yw+vAt26OsZfbO0Xa7Ox4MYxMFrKCVgKnY3ZamiM=
98+
github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20250902142123-a16588bf7967/go.mod h1:K6h5wmoAsxwzq7VSItwMg36RVsexLidHNNuSfK5mbSc=
9799
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250717122149-12f70b7f3d8d h1:0KCWljk2IEJ+aWNK+RiGpIdu51KPXrYA5RfyUcV4Mb4=
98100
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250717122149-12f70b7f3d8d/go.mod h1:6Mq2N/KtNFW20L+PQC5qkeK8R8UGadmGBXL8HDY6lcg=
99101
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
4949
"github.com/openstack-k8s-operators/lib-common/modules/common/operator"
5050
mariadbv1beta1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
51+
ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
5152
rabbitmqclusterv1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
5253
monv1 "github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring/v1"
5354
monv1alpha1 "github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring/v1alpha1"
@@ -77,6 +78,7 @@ func init() {
7778
utilruntime.Must(mariadbv1beta1.AddToScheme(scheme))
7879
utilruntime.Must(memcachedv1.AddToScheme(scheme))
7980
utilruntime.Must(heatv1.AddToScheme(scheme))
81+
utilruntime.Must(ovnv1.AddToScheme(scheme))
8082
utilruntime.Must(infranetworkv1.AddToScheme(scheme))
8183
utilruntime.Must(rabbitmqclusterv1.AddToScheme(scheme))
8284
utilruntime.Must(networkv1.AddToScheme(scheme))

0 commit comments

Comments
 (0)