Skip to content

[Feature] Add basic metrics for ArangoDeploymentReplication CR (GT-242) #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- (Bugfix) Fix GZIP encoding in case of small responses
- (Bugfix) Fix PVC Rotation Discovery
- (Feature) Allow to pass EphemeralStorage Resource to the Pods
- (Feature) Add basic metrics for ArangoDeploymentReplication CR

## [1.2.32](https://github.com/arangodb/kube-arangodb/tree/1.2.32) (2023-08-07)
- (Feature) Backup lifetime - remove Backup once its lifetime has been reached
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@
| [arangodb_operator_resources_arangodeployment_status_restores](./arangodb_operator_resources_arangodeployment_status_restores.md) | arangodb_operator | resources | Counter | Counter for deployment status restored |
| [arangodb_operator_resources_arangodeployment_uptodate](./arangodb_operator_resources_arangodeployment_uptodate.md) | arangodb_operator | resources | Gauge | Defines if ArangoDeployment is uptodate |
| [arangodb_operator_resources_arangodeployment_validation_errors](./arangodb_operator_resources_arangodeployment_validation_errors.md) | arangodb_operator | resources | Counter | Counter for deployment validation errors |
| [arangodb_operator_resources_arangodeploymentreplication_active](./arangodb_operator_resources_arangodeploymentreplication_active.md) | arangodb_operator | resources | Gauge | Defines if ArangoDeploymentReplication is configured and running |
| [arangodb_operator_resources_arangodeploymentreplication_failed](./arangodb_operator_resources_arangodeploymentreplication_failed.md) | arangodb_operator | resources | Gauge | Defines if ArangoDeploymentReplication is in Failed phase |

<!-- END(metricsTable) -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# arangodb_operator_resources_arangodeploymentreplication_active (Gauge)

## Description

Defines if ArangoDeploymentReplication is configured and running

## Labels

| Label | Description |
|:---------:|:--------------------------------|
| namespace | DeploymentReplication Namespace |
| name | DeploymentReplication Name |
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# arangodb_operator_resources_arangodeploymentreplication_failed (Gauge)

## Description

Defines if ArangoDeploymentReplication is in Failed phase

## Labels

| Label | Description |
|:---------:|:--------------------------------|
| namespace | DeploymentReplication Namespace |
| name | DeploymentReplication Name |
18 changes: 18 additions & 0 deletions internal/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ namespaces:
description: "Deployment Namespace"
- key: name
description: "Deployment Name"
arangodeploymentreplication_active:
shortDescription: "Defines if ArangoDeploymentReplication is configured and running"
description: "Defines if ArangoDeploymentReplication is configured and running"
type: "Gauge"
labels:
- key: namespace
description: "DeploymentReplication Namespace"
- key: name
description: "DeploymentReplication Name"
arangodeploymentreplication_failed:
shortDescription: "Defines if ArangoDeploymentReplication is in Failed phase"
description: "Defines if ArangoDeploymentReplication is in Failed phase"
type: "Gauge"
labels:
- key: namespace
description: "DeploymentReplication Namespace"
- key: name
description: "DeploymentReplication Name"
members:
unexpected_container_exit_codes:
shortDescription: "Counter of unexpected restarts in pod (Containers/InitContainers/EphemeralContainers)"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pkg/replication/deployment_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type DeploymentReplication struct {
status api.DeploymentReplicationStatus // Internal status of the CR
config Config
deps Dependencies
metrics Metrics

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

dr.log = logger.WrapObj(dr)

localInventory.Add(dr)

go dr.run()

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

// Delete the deployment replication.
// Called when the local storage was deleted by the user.
// Called when the CR was deleted by the user.
func (dr *DeploymentReplication) Delete() {
dr.log.Info("deployment replication is deleted by user")
if atomic.CompareAndSwapInt32(&dr.stopped, 0, 1) {
Expand Down
61 changes: 61 additions & 0 deletions pkg/replication/inventory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package replication

import (
"sync"

"github.com/arangodb/kube-arangodb/pkg/metrics/collector"
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
)

func init() {
localInventory = inventory{
deploymentReplications: map[string]map[string]*DeploymentReplication{},
}
collector.GetCollector().RegisterMetric(&localInventory)
}

var localInventory inventory

type inventory struct {
lock sync.Mutex
deploymentReplications map[string]map[string]*DeploymentReplication
}

func (i *inventory) CollectMetrics(in metrics.PushMetric) {
for _, drs := range i.deploymentReplications {
for _, dr := range drs {
dr.CollectMetrics(in)
}
}
}

func (i *inventory) Add(dr *DeploymentReplication) {
i.lock.Lock()
defer i.lock.Unlock()

name, namespace := dr.apiObject.GetName(), dr.apiObject.GetNamespace()
if _, ok := i.deploymentReplications[namespace]; !ok {
i.deploymentReplications[namespace] = map[string]*DeploymentReplication{}
}
i.deploymentReplications[namespace][name] = dr
}
44 changes: 44 additions & 0 deletions pkg/replication/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package replication

import (
"github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
)

type Metrics struct {
DeploymentReplication struct {
Active, Failed bool
}
}

func (dr *DeploymentReplication) CollectMetrics(m metrics.PushMetric) {
name, namespace := dr.apiObject.GetName(), dr.apiObject.GetNamespace()

m.Push(metric_descriptions.ArangodbOperatorResourcesArangodeploymentreplicationActiveGauge(
util.BoolSwitch[float64](dr.metrics.DeploymentReplication.Active, 1, 0), namespace, name),
)
m.Push(metric_descriptions.ArangodbOperatorResourcesArangodeploymentreplicationFailedGauge(
util.BoolSwitch[float64](dr.metrics.DeploymentReplication.Failed, 1, 0), namespace, name),
)
}
6 changes: 5 additions & 1 deletion pkg/replication/sync_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ func (dr *DeploymentReplication) inspectDeploymentReplication(lastInterval time.
dr.log.Err(err).Warn("Failed to add finalizers")
}

isFailed := dr.status.Phase.IsFailed()
dr.metrics.DeploymentReplication.Failed = isFailed
dr.metrics.DeploymentReplication.Active = dr.status.Conditions.IsTrue(api.ConditionTypeConfigured)

// Is the deployment in failed state, if so, give up.
if dr.status.Phase.IsFailed() {
if isFailed {
dr.log.Debug("Deployment replication is in Failed state.")
return nextInterval
}
Expand Down