File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff 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
160162func (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
216220func (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
288294func (c * State ) Lookup (path logicalcluster.Path ) (Result , bool ) {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments