Skip to content

Commit 4756b18

Browse files
MrFreezeexjrajahalme
authored andcommitted
clustermesh: homogenize ClusterMesh metrics based on watch store
Report per cluster metrics using the watch store for endpoints, global services, MCS service exports like we are doing already for remote nodes. This doesn't include identities unfortunately which doesn't use the watch store. We are no longer attempting to report Global Services and Global Service Export count. Note that those global count were not accounting the local cluster which was misleading. Signed-off-by: Arthur Outhenin-Chalandre <git@mrfreezeex.fr>
1 parent 3ab6ebf commit 4756b18

13 files changed

Lines changed: 99 additions & 79 deletions

File tree

Documentation/observability/metrics.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,11 @@ Clustermesh
371371
=============================================== ============================================================ ========== =================================================================
372372
Name Labels Default Description
373373
=============================================== ============================================================ ========== =================================================================
374-
``clustermesh_global_services`` ``source_cluster``, ``source_node_name`` Enabled The total number of global services in the cluster mesh
374+
``clustermesh_remote_cluster_services`` ``source_cluster``, ``source_node_name``, ``target_cluster`` Enabled The total number of services per remote cluster
375+
``clustermesh_remote_cluster_endpoints`` ``source_cluster``, ``source_node_name``, ``target_cluster`` Enabled The total number of endpoints per remote cluster
376+
``clustermesh_remote_cluster_nodes`` ``source_cluster``, ``source_node_name``, ``target_cluster`` Enabled The total number of nodes per remote cluster
375377
``clustermesh_remote_clusters`` ``source_cluster``, ``source_node_name`` Enabled The total number of remote clusters meshed with the local cluster
376378
``clustermesh_remote_cluster_failures`` ``source_cluster``, ``source_node_name``, ``target_cluster`` Enabled The total number of failures related to the remote cluster
377-
``clustermesh_remote_cluster_nodes`` ``source_cluster``, ``source_node_name``, ``target_cluster`` Enabled The total number of nodes in the remote cluster
378379
``clustermesh_remote_cluster_last_failure_ts`` ``source_cluster``, ``source_node_name``, ``target_cluster`` Enabled The timestamp of the last failure of the remote cluster
379380
``clustermesh_remote_cluster_readiness_status`` ``source_cluster``, ``source_node_name``, ``target_cluster`` Enabled The readiness status of the remote cluster
380381
=============================================== ============================================================ ========== =================================================================
@@ -867,6 +868,16 @@ Name Labels
867868
``serviceimport_info`` ``serviceimport``, ``namespace`` Enabled Information about ServiceImport in the local cluster
868869
==================================== ============================================================ ========== ===========================================================
869870

871+
Clustermesh
872+
~~~~~~~~~~~
873+
874+
============================================== ======================================= ========== ==================================================================
875+
Name Labels Default Description
876+
============================================== ======================================= ========== ==================================================================
877+
``clustermesh_remote_cluster_services`` ``source_cluster``, ``target_cluster`` Enabled The total number of services per remote cluster
878+
``clustermesh_remote_cluster_service_exports`` ``source_cluster``, ``target_cluster`` Enabled The total number of MCS-API service exports per remote cluster
879+
============================================== ======================================= ========== ==================================================================
880+
870881

871882
Hubble
872883
------

Documentation/operations/upgrade.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ Bugtool Options
356356

357357
Added Metrics
358358
~~~~~~~~~~~~~
359+
* ``cilium_agent_clustermesh_remote_cluster_endpoints`` was added and report
360+
the total number of endpoints per remote cluster in a ClusterMesh environment.
359361

360362
Removed Metrics
361363
~~~~~~~~~~~~~~~
@@ -381,6 +383,15 @@ As well, any remaining Operator k8s workqueue metrics that use the label ``queue
381383

382384
* ``k8s_client_rate_limiter_duration_seconds`` no longer has labels ``path`` and ``method``.
383385

386+
The following metrics:
387+
* ``cilium_agent_clustermesh_global_services``
388+
* ``cilium_operator_clustermesh_global_services``
389+
* ``cilium_operator_clustermesh_global_service_exports``
390+
now report per cluster metric instead of a "global" count and were renamed to respectively:
391+
* ``cilium_agent_clustermesh_remote_cluster_services``
392+
* ``cilium_operator_clustermesh_remote_cluster_services``
393+
* ``cilium_operator_clustermesh_remote_cluster_service_exports``
394+
384395
Deprecated Metrics
385396
~~~~~~~~~~~~~~~~~~
386397

pkg/clustermesh/clustermesh.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ func (cm *ClusterMesh) NewRemoteCluster(name string, status common.StatusFunc) c
211211
),
212212
&clusterServiceObserver{serviceMerger: cm.conf.ServiceMerger},
213213
store.RWSWithOnSyncCallback(func(ctx context.Context) { close(rc.synced.services) }),
214+
store.RWSWithEntriesMetric(cm.conf.Metrics.TotalServices.WithLabelValues(cm.conf.ClusterInfo.Name, cm.nodeName, rc.name)),
214215
)
215216

216217
rc.ipCacheWatcher = ipcache.NewIPIdentityWatcher(
217218
cm.conf.Logger,
218219
name, cm.conf.IPCache, cm.conf.StoreFactory, source.ClusterMesh,
219220
store.RWSWithOnSyncCallback(func(ctx context.Context) { close(rc.synced.ipcache) }),
221+
store.RWSWithEntriesMetric(cm.conf.Metrics.TotalEndpoints.WithLabelValues(cm.conf.ClusterInfo.Name, cm.nodeName, rc.name)),
220222
)
221223
rc.ipCacheWatcherExtraOpts = cm.conf.IPCacheWatcherExtraOpts
222224

pkg/clustermesh/common/services.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/cilium/cilium/pkg/kvstore/store"
1414
"github.com/cilium/cilium/pkg/lock"
1515
"github.com/cilium/cilium/pkg/logging/logfields"
16-
"github.com/cilium/cilium/pkg/metrics/metric"
1716
)
1817

1918
type GlobalService struct {
@@ -30,16 +29,12 @@ type GlobalServiceCache struct {
3029
logger *slog.Logger
3130
mutex lock.RWMutex
3231
byName map[types.NamespacedName]*GlobalService
33-
34-
// metricTotalGlobalServices is the gauge metric for total of global services
35-
metricTotalGlobalServices metric.Gauge
3632
}
3733

38-
func NewGlobalServiceCache(logger *slog.Logger, metricTotalGlobalServices metric.Gauge) *GlobalServiceCache {
34+
func NewGlobalServiceCache(logger *slog.Logger) *GlobalServiceCache {
3935
return &GlobalServiceCache{
40-
logger: logger,
41-
byName: map[types.NamespacedName]*GlobalService{},
42-
metricTotalGlobalServices: metricTotalGlobalServices,
36+
logger: logger,
37+
byName: map[types.NamespacedName]*GlobalService{},
4338
}
4439
}
4540

@@ -101,7 +96,6 @@ func (c *GlobalServiceCache) OnUpdate(svc *serviceStore.ClusterService) {
10196
logfields.ServiceName, svc,
10297
logfields.ClusterName, svc.Cluster,
10398
)
104-
c.metricTotalGlobalServices.Set(float64(len(c.byName)))
10599
}
106100

107101
c.logger.Debug(
@@ -137,7 +131,6 @@ func (c *GlobalServiceCache) delete(globalService *GlobalService, clusterName st
137131
logfields.ClusterName, clusterName,
138132
)
139133
delete(c.byName, serviceNN)
140-
c.metricTotalGlobalServices.Set(float64(len(c.byName)))
141134
}
142135

143136
return true

pkg/clustermesh/common/services_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/stretchr/testify/require"
1111

1212
serviceStore "github.com/cilium/cilium/pkg/clustermesh/store"
13-
"github.com/cilium/cilium/pkg/metrics"
1413
)
1514

1615
type fakeUpstream struct {
@@ -32,7 +31,7 @@ func TestRemoteServiceObserver(t *testing.T) {
3231
}
3332
svc1 := serviceStore.ClusterService{Cluster: "remote", Namespace: "namespace", Name: "name", IncludeExternal: false, Shared: true}
3433
svc2 := serviceStore.ClusterService{Cluster: "remote", Namespace: "namespace", Name: "name"}
35-
cache := NewGlobalServiceCache(hivetest.Logger(t), metrics.NoOpGauge)
34+
cache := NewGlobalServiceCache(hivetest.Logger(t))
3635

3736
var upstream fakeUpstream
3837
observer := NewSharedServicesObserver(hivetest.Logger(t), cache, upstream.OnUpdate, upstream.OnDelete)

pkg/clustermesh/endpointslicesync/endpointslice_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
slim_metav1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1"
3232
"github.com/cilium/cilium/pkg/k8s/utils"
3333
"github.com/cilium/cilium/pkg/loadbalancer"
34-
"github.com/cilium/cilium/pkg/metrics/metric"
3534
)
3635

3736
const (
@@ -113,7 +112,7 @@ func Test_meshEndpointSlice_Reconcile(t *testing.T) {
113112
}
114113
defer hive.Stop(tlog, context.Background())
115114

116-
globalService := common.NewGlobalServiceCache(hivetest.Logger(t), metric.NewGauge(metric.GaugeOpts{}))
115+
globalService := common.NewGlobalServiceCache(hivetest.Logger(t))
117116
podInformer := newMeshPodInformer(logger, globalService)
118117
nodeInformer := newMeshNodeInformer(logger)
119118
controller, serviceInformer, endpointsliceInformer := newEndpointSliceMeshController(

pkg/clustermesh/mcsapi/serviceimport_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
mcsapitypes "github.com/cilium/cilium/pkg/clustermesh/mcsapi/types"
2828
"github.com/cilium/cilium/pkg/clustermesh/operator"
29-
"github.com/cilium/cilium/pkg/metrics/metric"
3029
)
3130

3231
const (
@@ -503,7 +502,7 @@ func Test_mcsServiceImport_Reconcile(t *testing.T) {
503502
WithStatusSubresource(&mcsapiv1alpha1.ServiceImport{}).
504503
WithScheme(testScheme()).
505504
Build()
506-
globalServiceExports := operator.NewGlobalServiceExportCache(metric.NewGauge(metric.GaugeOpts{}))
505+
globalServiceExports := operator.NewGlobalServiceExportCache()
507506
remoteClusterServiceSource := &remoteClusterServiceExportSource{Logger: hivetest.Logger(t)}
508507
for _, svcExport := range remoteSvcImportTestFixtures {
509508
globalServiceExports.OnUpdate(svcExport)

pkg/clustermesh/metrics.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import (
99
)
1010

1111
type Metrics struct {
12-
// TotalNodes tracks the number of total nodes in a remote cluster.
12+
// TotalNodes tracks the number of total nodes per remote cluster.
1313
TotalNodes metric.Vec[metric.Gauge]
1414

15-
// TotalGlobalServices tracks the total number of global services.
16-
TotalGlobalServices metric.Vec[metric.Gauge]
15+
// TotalServices tracks the number of total services per remote cluster.
16+
TotalServices metric.Vec[metric.Gauge]
17+
18+
// TotalEndpoints tracks the number of total IPs per remote cluster.
19+
TotalEndpoints metric.Vec[metric.Gauge]
1720
}
1821

1922
func NewMetrics() Metrics {
@@ -26,12 +29,20 @@ func NewMetrics() Metrics {
2629
Help: "The total number of nodes in the remote cluster",
2730
}, []string{metrics.LabelSourceCluster, metrics.LabelSourceNodeName, metrics.LabelTargetCluster}),
2831

29-
TotalGlobalServices: metric.NewGaugeVec(metric.GaugeOpts{
30-
ConfigName: metrics.Namespace + "_" + subsystem + "_global_services",
32+
TotalServices: metric.NewGaugeVec(metric.GaugeOpts{
33+
ConfigName: metrics.Namespace + "_" + subsystem + "_remote_cluster_services",
34+
Namespace: metrics.Namespace,
35+
Subsystem: subsystem,
36+
Name: "remote_cluster_services",
37+
Help: "The total number of services in the remote cluster",
38+
}, []string{metrics.LabelSourceCluster, metrics.LabelSourceNodeName, metrics.LabelTargetCluster}),
39+
40+
TotalEndpoints: metric.NewGaugeVec(metric.GaugeOpts{
41+
ConfigName: metrics.Namespace + "_" + subsystem + "_remote_cluster_endpoints",
3142
Namespace: metrics.Namespace,
3243
Subsystem: subsystem,
33-
Name: "global_services",
34-
Help: "The total number of global services in the cluster mesh",
35-
}, []string{metrics.LabelSourceCluster, metrics.LabelSourceNodeName}),
44+
Name: "remote_cluster_endpoints",
45+
Help: "The total number of endpoints in the remote cluster",
46+
}, []string{metrics.LabelSourceCluster, metrics.LabelSourceNodeName, metrics.LabelTargetCluster}),
3647
}
3748
}

pkg/clustermesh/operator/clustermesh.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/cilium/cilium/pkg/clustermesh/common"
1919
mcsapitypes "github.com/cilium/cilium/pkg/clustermesh/mcsapi/types"
2020
serviceStore "github.com/cilium/cilium/pkg/clustermesh/store"
21+
"github.com/cilium/cilium/pkg/clustermesh/types"
2122
"github.com/cilium/cilium/pkg/clustermesh/wait"
2223
"github.com/cilium/cilium/pkg/dial"
2324
"github.com/cilium/cilium/pkg/kvstore/store"
@@ -29,10 +30,11 @@ type clusterMesh struct {
2930
// common implements the common logic to connect to remote clusters.
3031
common common.ClusterMesh
3132

32-
cfg ClusterMeshConfig
33-
cfgMCSAPI MCSAPIConfig
34-
logger *slog.Logger
35-
Metrics Metrics
33+
cfg ClusterMeshConfig
34+
cfgMCSAPI MCSAPIConfig
35+
logger *slog.Logger
36+
clusterInfo types.ClusterInfo
37+
metrics Metrics
3638

3739
// globalServices is a list of all global services. The datastructure
3840
// is protected by its own mutex inside the structure.
@@ -97,15 +99,15 @@ func newClusterMesh(lc cell.Lifecycle, params clusterMeshParams) (*clusterMesh,
9799
params.Logger.Info("Operator ClusterMesh component enabled")
98100

99101
cm := clusterMesh{
100-
cfg: params.Cfg,
101-
cfgMCSAPI: params.CfgMCSAPI,
102-
logger: params.Logger,
103-
globalServices: common.NewGlobalServiceCache(params.Logger, params.Metrics.TotalGlobalServices.WithLabelValues(params.ClusterInfo.Name)),
104-
globalServiceExports: NewGlobalServiceExportCache(
105-
params.Metrics.TotalGlobalServiceExports.WithLabelValues(params.ClusterInfo.Name),
106-
),
107-
storeFactory: params.StoreFactory,
108-
syncTimeoutConfig: params.TimeoutConfig,
102+
cfg: params.Cfg,
103+
cfgMCSAPI: params.CfgMCSAPI,
104+
logger: params.Logger,
105+
clusterInfo: params.ClusterInfo,
106+
metrics: params.Metrics,
107+
globalServices: common.NewGlobalServiceCache(params.Logger),
108+
globalServiceExports: NewGlobalServiceExportCache(),
109+
storeFactory: params.StoreFactory,
110+
syncTimeoutConfig: params.TimeoutConfig,
109111
}
110112
cm.common = common.NewClusterMesh(common.Configuration{
111113
Logger: params.Logger,
@@ -223,6 +225,7 @@ func (cm *clusterMesh) newRemoteCluster(name string, status common.StatusFunc) c
223225
},
224226
),
225227
store.RWSWithOnSyncCallback(func(ctx context.Context) { rc.synced.services.Stop() }),
228+
store.RWSWithEntriesMetric(cm.metrics.TotalServices.WithLabelValues(cm.clusterInfo.Name, rc.name)),
226229
)
227230

228231
rc.remoteServiceExports = cm.storeFactory.NewWatchStore(
@@ -245,6 +248,7 @@ func (cm *clusterMesh) newRemoteCluster(name string, status common.StatusFunc) c
245248
},
246249
),
247250
store.RWSWithOnSyncCallback(func(ctx context.Context) { rc.synced.serviceExports.Stop() }),
251+
store.RWSWithEntriesMetric(cm.metrics.TotalServiceExports.WithLabelValues(cm.clusterInfo.Name, name)),
248252
)
249253

250254
return rc

pkg/clustermesh/operator/metrics.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ import (
99
)
1010

1111
type Metrics struct {
12-
// TotalGlobalServices tracks the total number of global services.
13-
TotalGlobalServices metric.Vec[metric.Gauge]
14-
// TotalGlobalServiceExports tracks the total number of global service exports.
15-
TotalGlobalServiceExports metric.Vec[metric.Gauge]
12+
// TotalServices tracks the number of total global services per remote cluster.
13+
TotalServices metric.Vec[metric.Gauge]
14+
// TotalServiceExports tracks the number of total MCS-API service exports per remote cluster.
15+
TotalServiceExports metric.Vec[metric.Gauge]
1616
}
1717

1818
func NewMetrics() Metrics {
1919
return Metrics{
20-
TotalGlobalServices: metric.NewGaugeVec(metric.GaugeOpts{
20+
TotalServices: metric.NewGaugeVec(metric.GaugeOpts{
2121
Namespace: metrics.CiliumOperatorNamespace,
2222
Subsystem: subsystem,
23-
Name: "global_services",
24-
Help: "The total number of global services in the cluster mesh",
25-
}, []string{metrics.LabelSourceCluster}),
26-
TotalGlobalServiceExports: metric.NewGaugeVec(metric.GaugeOpts{
23+
Name: "remote_cluster_services",
24+
Help: "The total number of services in the remote cluster",
25+
}, []string{metrics.LabelSourceCluster, metrics.LabelTargetCluster}),
26+
TotalServiceExports: metric.NewGaugeVec(metric.GaugeOpts{
2727
Namespace: metrics.CiliumOperatorNamespace,
2828
Subsystem: subsystem,
29-
Name: "global_service_exports",
30-
Help: "The total number of MCS-API global service exports in the cluster mesh",
31-
}, []string{metrics.LabelSourceCluster}),
29+
Name: "remote_cluster_service_exports",
30+
Help: "The total number of MCS-API service exports in the remote cluster",
31+
}, []string{metrics.LabelSourceCluster, metrics.LabelTargetCluster}),
3232
}
3333
}

0 commit comments

Comments
 (0)