1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-14 11:57:37 +00:00

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

This commit is contained in:
Nikita Vaniasin 2023-09-13 09:44:44 +02:00 committed by GitHub
parent 7def39ed6c
commit 6e2ff839c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 237 additions and 2 deletions

View file

@ -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

View file

@ -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) -->

View file

@ -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 |

View file

@ -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 |

View file

@ -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)"

View file

@ -0,0 +1,39 @@
//
// DISCLAIMER
//
// Copyright 2016-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 metric_descriptions
import "github.com/arangodb/kube-arangodb/pkg/util/metrics"
var (
arangodbOperatorResourcesArangodeploymentreplicationActive = metrics.NewDescription("arangodb_operator_resources_arangodeploymentreplication_active", "Defines if ArangoDeploymentReplication is configured and running", []string{`namespace`, `name`}, nil)
)
func init() {
registerDescription(arangodbOperatorResourcesArangodeploymentreplicationActive)
}
func ArangodbOperatorResourcesArangodeploymentreplicationActive() metrics.Description {
return arangodbOperatorResourcesArangodeploymentreplicationActive
}
func ArangodbOperatorResourcesArangodeploymentreplicationActiveGauge(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorResourcesArangodeploymentreplicationActive().Gauge(value, namespace, name)
}

View file

@ -0,0 +1,39 @@
//
// DISCLAIMER
//
// Copyright 2016-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 metric_descriptions
import "github.com/arangodb/kube-arangodb/pkg/util/metrics"
var (
arangodbOperatorResourcesArangodeploymentreplicationFailed = metrics.NewDescription("arangodb_operator_resources_arangodeploymentreplication_failed", "Defines if ArangoDeploymentReplication is in Failed phase", []string{`namespace`, `name`}, nil)
)
func init() {
registerDescription(arangodbOperatorResourcesArangodeploymentreplicationFailed)
}
func ArangodbOperatorResourcesArangodeploymentreplicationFailed() metrics.Description {
return arangodbOperatorResourcesArangodeploymentreplicationFailed
}
func ArangodbOperatorResourcesArangodeploymentreplicationFailedGauge(value float64, namespace string, name string) metrics.Metric {
return ArangodbOperatorResourcesArangodeploymentreplicationFailed().Gauge(value, namespace, name)
}

View file

@ -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{}
@ -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
@ -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) {

View file

@ -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
}

View file

@ -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),
)
}

View file

@ -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
}