Skip to content

Commit c4f16ce

Browse files
authored
Merge pull request #3482 from xrstf/fp-index-metrics
Add kcp_indexed_logicalclusters metric
2 parents 65562e8 + 745d019 commit c4f16ce

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

pkg/index/index.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ func (c *State) UpsertWorkspace(shard string, ws *tenancyv1alpha1.Workspace) {
155155
c.shardClusterWorkspaceMount[shard][clusterName][ws.Name] = ws.Spec
156156
}
157157
}
158+
159+
clustersOnShard.WithLabelValues(shard).Set(float64(len(c.shardClusterWorkspaceName[shard])))
158160
}
159161

160162
func (c *State) DeleteWorkspace(shard string, ws *tenancyv1alpha1.Workspace) {
@@ -211,6 +213,8 @@ func (c *State) DeleteWorkspace(shard string, ws *tenancyv1alpha1.Workspace) {
211213
delete(c.shardClusterWorkspaceNameErrorCode, shard)
212214
}
213215
}
216+
217+
clustersOnShard.WithLabelValues(shard).Set(float64(len(c.shardClusterWorkspaceName[shard])))
214218
}
215219

216220
func (c *State) UpsertLogicalCluster(shard string, logicalCluster *corev1alpha1.LogicalCluster) {
@@ -283,6 +287,8 @@ func (c *State) DeleteShard(shardName string) {
283287
delete(c.shardClusterWorkspaceType, shardName)
284288
delete(c.shardClusterParentCluster, shardName)
285289
delete(c.shardClusterWorkspaceNameErrorCode, shardName)
290+
291+
clustersOnShard.DeleteLabelValues(shardName)
286292
}
287293

288294
func (c *State) Lookup(path logicalcluster.Path) (Result, bool) {

pkg/index/metrics.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2025 The KCP Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package index
18+
19+
import (
20+
"sync"
21+
22+
compbasemetrics "k8s.io/component-base/metrics"
23+
"k8s.io/component-base/metrics/legacyregistry"
24+
)
25+
26+
var (
27+
clustersOnShard = compbasemetrics.NewGaugeVec(
28+
&compbasemetrics.GaugeOpts{
29+
Namespace: "kcp",
30+
Name: "indexed_logicalclusters",
31+
Help: "Number of logicalclusters indexed by kcp-front-proxy or embedded localproxy per shard.",
32+
StabilityLevel: compbasemetrics.ALPHA,
33+
},
34+
[]string{"shard"},
35+
)
36+
)
37+
38+
var registerMetrics sync.Once
39+
40+
// Register metrics.
41+
func Register() {
42+
registerMetrics.Do(func() {
43+
legacyregistry.MustRegister(clustersOnShard)
44+
})
45+
}
46+
47+
func init() {
48+
Register()
49+
}

0 commit comments

Comments
 (0)