11//
22// DISCLAIMER
33//
4- // Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+ // Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55//
66// Licensed under the Apache License, Version 2.0 (the "License");
77// you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import (
2424 "sync"
2525
2626 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+ "github.com/arangodb/kube-arangodb/pkg/deployment/agency/state"
2728 "github.com/arangodb/kube-arangodb/pkg/deployment/features"
2829 "github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
2930 "github.com/arangodb/kube-arangodb/pkg/metrics/collector"
@@ -76,8 +77,8 @@ func (i *inventory) CollectMetrics(in metrics.PushMetric) {
7677
7778 deployment .CollectMetrics (in )
7879
79- if state := deployment .acs .CurrentClusterCache (); state != nil {
80- t := state .GetThrottles ()
80+ if cacheInspector := deployment .acs .CurrentClusterCache (); cacheInspector != nil {
81+ t := cacheInspector .GetThrottles ()
8182
8283 for _ , c := range definitions .AllComponents () {
8384 in .Push (i .operatorStateRefreshMetric .Gauge (float64 (t .Get (c ).Count ()), deployment .GetNamespace (), deployment .GetName (), string (c )))
@@ -92,58 +93,59 @@ func (i *inventory) CollectMetrics(in metrics.PushMetric) {
9293 }
9394
9495 if spec .Mode .Get ().HasAgents () {
95- agency , agencyOk := deployment .GetAgencyCache ()
96- if ! agencyOk {
97- in .Push (i .deploymentAgencyStateMetric .Gauge (0 , deployment .GetNamespace (), deployment .GetName ()))
98- continue
99- }
100-
101- in .Push (i .deploymentAgencyStateMetric .Gauge (1 , deployment .GetNamespace (), deployment .GetName ()))
102-
10396 if spec .Mode .Get () == api .DeploymentModeCluster {
104- for db , collections := range agency .Current .Collections {
105- dbName := db
106- if features .SensitiveInformationProtection ().Enabled () {
107- dbName = "UNKNOWN"
108-
109- if v , ok := agency .Plan .Databases [db ]; ok && v .ID != "" {
110- dbName = v .ID
97+ applied := deployment .WithAgencyCache (func (st state.State ) {
98+ for db , collections := range st .Current .Collections {
99+ dbName := db
100+ if features .SensitiveInformationProtection ().Enabled () {
101+ dbName = "UNKNOWN"
102+
103+ if v , ok := st .Plan .Databases [db ]; ok && v .ID != "" {
104+ dbName = v .ID
105+ }
111106 }
112- }
113107
114- for collection , shards := range collections {
115- for shard , details := range shards {
116- for id , server := range details .Servers {
117- collectionName := "UNKNOWN"
118- if features .SensitiveInformationProtection ().Enabled () {
119- collectionName = collection
120- } else {
121- if _ , ok := agency .Plan .Collections [db ]; ok {
122- if _ , ok := agency .Plan .Collections [db ][collection ]; ok {
123- collectionName = agency .Plan .Collections [db ][collection ].GetName (collectionName )
108+ for collection , shards := range collections {
109+ for shard , details := range shards {
110+ for id , server := range details .Servers {
111+ collectionName := "UNKNOWN"
112+ if features .SensitiveInformationProtection ().Enabled () {
113+ collectionName = collection
114+ } else {
115+ if _ , ok := st .Plan .Collections [db ]; ok {
116+ if _ , ok := st .Plan .Collections [db ][collection ]; ok {
117+ collectionName = st .Plan .Collections [db ][collection ].GetName (collectionName )
118+ }
124119 }
125120 }
126- }
127121
128- m := []string {
129- deployment .GetNamespace (),
130- deployment .GetName (),
131- dbName ,
132- collectionName ,
133- shard ,
134- string (server ),
135- }
122+ m := []string {
123+ deployment .GetNamespace (),
124+ deployment .GetName (),
125+ dbName ,
126+ collectionName ,
127+ shard ,
128+ string (server ),
129+ }
136130
137- if id == 0 {
138- in .Push (i .deploymentShardLeadersMetric .Gauge (1 , m ... ))
131+ if id == 0 {
132+ in .Push (i .deploymentShardLeadersMetric .Gauge (1 , m ... ))
133+ }
134+ in .Push (i .deploymentShardsMetric .Gauge (1 , m ... ))
139135 }
140- in .Push (i .deploymentShardsMetric .Gauge (1 , m ... ))
141136 }
142137 }
143138 }
139+ })
140+
141+ if ! applied {
142+ in .Push (i .deploymentAgencyStateMetric .Gauge (0 , deployment .GetNamespace (), deployment .GetName ()))
143+ continue
144144 }
145+
145146 }
146147 }
148+ in .Push (i .deploymentAgencyStateMetric .Gauge (1 , deployment .GetNamespace (), deployment .GetName ()))
147149 }
148150 }
149151}
0 commit comments