forked from backube/volsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
129 lines (115 loc) · 3.77 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright 2020 The VolSync authors.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package controllers
import (
"time"
volsyncv1alpha1 "github.com/backube/volsync/api/v1alpha1"
"github.com/go-logr/logr"
"github.com/prometheus/client_golang/prometheus"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)
const (
metricsNamespace = "volsync"
)
// volsyncMetrics holds references to fully qualified instances of the metrics
type volsyncMetrics struct {
MissedIntervals prometheus.Counter
OutOfSync prometheus.Gauge
SyncDurations prometheus.Observer
}
var (
metricLabels = []string{
"obj_name", // Name of the replication CR
"obj_namespace", // Namespace containing the CR
"role", // Direction: "source" or "destination"
"method", // Synchronization method (rsync, rclone, etc.)
}
missedIntervals = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "missed_intervals_total",
Namespace: metricsNamespace,
Help: "The number of times a synchronization failed to complete before the next scheduled start",
},
metricLabels,
)
outOfSync = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "volume_out_of_sync",
Namespace: metricsNamespace,
Help: "Set to 1 if the volume is not properly synchronized",
},
metricLabels,
)
syncDurations = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Name: "sync_duration_seconds",
Namespace: metricsNamespace,
Help: "Duration of the synchronization interval in seconds",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
MaxAge: 24 * time.Hour,
},
metricLabels,
)
)
func newVolSyncMetrics(labels prometheus.Labels) volsyncMetrics {
return volsyncMetrics{
MissedIntervals: missedIntervals.With(labels),
OutOfSync: outOfSync.With(labels),
SyncDurations: syncDurations.With(labels),
}
}
func init() {
// Register custom metrics with the global prometheus registry
metrics.Registry.MustRegister(missedIntervals, outOfSync, syncDurations)
}
//nolint:funlen
func (r *ReplicationSourceReconciler) countReplicationMethods(instance *volsyncv1alpha1.ReplicationSource,
logger logr.Logger) int {
var numOfReplication int
logger.Info("Counting number of Reconciliation methods", "instance", instance)
if instance.Spec.Rsync != nil {
numOfReplication++
}
if instance.Spec.Rclone != nil {
numOfReplication++
}
if instance.Spec.Restic != nil {
numOfReplication++
}
if instance.Spec.External != nil {
numOfReplication++
}
logger.Info("Counting over ", "Number of Replication Methods: ", numOfReplication)
return numOfReplication
}
//nolint:funlen
func (r *ReplicationDestinationReconciler) countReplicationMethods(instance *volsyncv1alpha1.ReplicationDestination,
logger logr.Logger) int {
var numOfReplication int
logger.Info("Counting number of Reconciliation methods", "instance", instance)
if instance.Spec.Rsync != nil {
numOfReplication++
}
if instance.Spec.Rclone != nil {
numOfReplication++
}
if instance.Spec.Restic != nil {
numOfReplication++
}
if instance.Spec.External != nil {
numOfReplication++
}
logger.Info("Counting over ", "Number of Replication Methods: ", numOfReplication)
return numOfReplication
}