Skip to content

Commit 6e2ff83

Browse files
[Feature] Add basic metrics for ArangoDeploymentReplication CR (GT-242) (#1402)
1 parent 7def39e commit 6e2ff83

11 files changed

+237
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- (Bugfix) Fix GZIP encoding in case of small responses
1616
- (Bugfix) Fix PVC Rotation Discovery
1717
- (Feature) Allow to pass EphemeralStorage Resource to the Pods
18+
- (Feature) Add basic metrics for ArangoDeploymentReplication CR
1819

1920
## [1.2.32](https://github.com/arangodb/kube-arangodb/tree/1.2.32) (2023-08-07)
2021
- (Feature) Backup lifetime - remove Backup once its lifetime has been reached

docs/generated/metrics/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@
3232
| [arangodb_operator_resources_arangodeployment_status_restores](./arangodb_operator_resources_arangodeployment_status_restores.md) | arangodb_operator | resources | Counter | Counter for deployment status restored |
3333
| [arangodb_operator_resources_arangodeployment_uptodate](./arangodb_operator_resources_arangodeployment_uptodate.md) | arangodb_operator | resources | Gauge | Defines if ArangoDeployment is uptodate |
3434
| [arangodb_operator_resources_arangodeployment_validation_errors](./arangodb_operator_resources_arangodeployment_validation_errors.md) | arangodb_operator | resources | Counter | Counter for deployment validation errors |
35+
| [arangodb_operator_resources_arangodeploymentreplication_active](./arangodb_operator_resources_arangodeploymentreplication_active.md) | arangodb_operator | resources | Gauge | Defines if ArangoDeploymentReplication is configured and running |
36+
| [arangodb_operator_resources_arangodeploymentreplication_failed](./arangodb_operator_resources_arangodeploymentreplication_failed.md) | arangodb_operator | resources | Gauge | Defines if ArangoDeploymentReplication is in Failed phase |
3537

3638
<!-- END(metricsTable) -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# arangodb_operator_resources_arangodeploymentreplication_active (Gauge)
2+
3+
## Description
4+
5+
Defines if ArangoDeploymentReplication is configured and running
6+
7+
## Labels
8+
9+
| Label | Description |
10+
|:---------:|:--------------------------------|
11+
| namespace | DeploymentReplication Namespace |
12+
| name | DeploymentReplication Name |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# arangodb_operator_resources_arangodeploymentreplication_failed (Gauge)
2+
3+
## Description
4+
5+
Defines if ArangoDeploymentReplication is in Failed phase
6+
7+
## Labels
8+
9+
| Label | Description |
10+
|:---------:|:--------------------------------|
11+
| namespace | DeploymentReplication Namespace |
12+
| name | DeploymentReplication Name |

internal/metrics.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ namespaces:
201201
description: "Deployment Namespace"
202202
- key: name
203203
description: "Deployment Name"
204+
arangodeploymentreplication_active:
205+
shortDescription: "Defines if ArangoDeploymentReplication is configured and running"
206+
description: "Defines if ArangoDeploymentReplication is configured and running"
207+
type: "Gauge"
208+
labels:
209+
- key: namespace
210+
description: "DeploymentReplication Namespace"
211+
- key: name
212+
description: "DeploymentReplication Name"
213+
arangodeploymentreplication_failed:
214+
shortDescription: "Defines if ArangoDeploymentReplication is in Failed phase"
215+
description: "Defines if ArangoDeploymentReplication is in Failed phase"
216+
type: "Gauge"
217+
labels:
218+
- key: namespace
219+
description: "DeploymentReplication Namespace"
220+
- key: name
221+
description: "DeploymentReplication Name"
204222
members:
205223
unexpected_container_exit_codes:
206224
shortDescription: "Counter of unexpected restarts in pod (Containers/InitContainers/EphemeralContainers)"

pkg/generated/metric_descriptions/arangodb_operator_resources_arangodeploymentreplication_active.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/generated/metric_descriptions/arangodb_operator_resources_arangodeploymentreplication_failed.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/replication/deployment_replication.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type DeploymentReplication struct {
8585
status api.DeploymentReplicationStatus // Internal status of the CR
8686
config Config
8787
deps Dependencies
88+
metrics Metrics
8889

8990
eventCh chan *deploymentReplicationEvent
9091
stopCh chan struct{}
@@ -111,6 +112,8 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeploymentReplic
111112

112113
dr.log = logger.WrapObj(dr)
113114

115+
localInventory.Add(dr)
116+
114117
go dr.run()
115118

116119
return dr, nil
@@ -126,7 +129,7 @@ func (dr *DeploymentReplication) Update(apiObject *api.ArangoDeploymentReplicati
126129
}
127130

128131
// Delete the deployment replication.
129-
// Called when the local storage was deleted by the user.
132+
// Called when the CR was deleted by the user.
130133
func (dr *DeploymentReplication) Delete() {
131134
dr.log.Info("deployment replication is deleted by user")
132135
if atomic.CompareAndSwapInt32(&dr.stopped, 0, 1) {

pkg/replication/inventory.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package replication
22+
23+
import (
24+
"sync"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/metrics/collector"
27+
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
28+
)
29+
30+
func init() {
31+
localInventory = inventory{
32+
deploymentReplications: map[string]map[string]*DeploymentReplication{},
33+
}
34+
collector.GetCollector().RegisterMetric(&localInventory)
35+
}
36+
37+
var localInventory inventory
38+
39+
type inventory struct {
40+
lock sync.Mutex
41+
deploymentReplications map[string]map[string]*DeploymentReplication
42+
}
43+
44+
func (i *inventory) CollectMetrics(in metrics.PushMetric) {
45+
for _, drs := range i.deploymentReplications {
46+
for _, dr := range drs {
47+
dr.CollectMetrics(in)
48+
}
49+
}
50+
}
51+
52+
func (i *inventory) Add(dr *DeploymentReplication) {
53+
i.lock.Lock()
54+
defer i.lock.Unlock()
55+
56+
name, namespace := dr.apiObject.GetName(), dr.apiObject.GetNamespace()
57+
if _, ok := i.deploymentReplications[namespace]; !ok {
58+
i.deploymentReplications[namespace] = map[string]*DeploymentReplication{}
59+
}
60+
i.deploymentReplications[namespace][name] = dr
61+
}

pkg/replication/metrics.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package replication
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
25+
"github.com/arangodb/kube-arangodb/pkg/util"
26+
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
27+
)
28+
29+
type Metrics struct {
30+
DeploymentReplication struct {
31+
Active, Failed bool
32+
}
33+
}
34+
35+
func (dr *DeploymentReplication) CollectMetrics(m metrics.PushMetric) {
36+
name, namespace := dr.apiObject.GetName(), dr.apiObject.GetNamespace()
37+
38+
m.Push(metric_descriptions.ArangodbOperatorResourcesArangodeploymentreplicationActiveGauge(
39+
util.BoolSwitch[float64](dr.metrics.DeploymentReplication.Active, 1, 0), namespace, name),
40+
)
41+
m.Push(metric_descriptions.ArangodbOperatorResourcesArangodeploymentreplicationFailedGauge(
42+
util.BoolSwitch[float64](dr.metrics.DeploymentReplication.Failed, 1, 0), namespace, name),
43+
)
44+
}

0 commit comments

Comments
 (0)