Skip to content
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

feat: expose operator metrics #928

Merged
merged 39 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
17f065f
upgrade golangci-lint
jaideepr97 Apr 18, 2023
a72c846
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Apr 19, 2023
b63520b
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 1, 2023
57b99fa
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 4, 2023
bbd373b
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 4, 2023
ef1549b
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 9, 2023
3dc6561
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 10, 2023
16f85f6
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 12, 2023
238fa7c
wip: add new metrics
jaideepr97 May 25, 2023
f43dcb5
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 25, 2023
caf2b9b
add new metrics server
jaideepr97 May 26, 2023
3a79f5f
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 May 26, 2023
94f4a78
update service/servicemonitor
jaideepr97 May 30, 2023
e5f5637
Merge branch 'master' of github.com:argoproj-labs/argocd-operator int…
jaideepr97 May 30, 2023
85c170b
inject all metrics into default registry, remove extra metrics server…
jaideepr97 Jun 7, 2023
c858fba
Merge branch 'master' of github.com:argoproj-labs/argocd-operator int…
jaideepr97 Jun 7, 2023
98cfb73
revert change to service in 0.6.0 bundle folder
jaideepr97 Jun 7, 2023
f7bed3f
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Jun 7, 2023
9306ef2
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Jun 8, 2023
4b28b5f
address lint issue
jaideepr97 Jun 9, 2023
0d4d2db
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Jun 15, 2023
9382d65
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Jun 29, 2023
d29ce02
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Jul 3, 2023
a884695
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Jul 6, 2023
390d426
fix merge conflicts
jaideepr97 Jul 7, 2023
455a82c
Merge branch 'master' of github.com:argoproj-labs/argocd-operator int…
jaideepr97 Jul 20, 2023
93516ee
manifest fixes
jaideepr97 Jul 20, 2023
c9e95d1
remove servicemonitor from bundle
jaideepr97 Jul 20, 2023
31335e5
Merge branch 'master' of github.com:argoproj-labs/argocd-operator
jaideepr97 Jul 20, 2023
b94d1f8
fix manifest issues
jaideepr97 Jul 20, 2023
21d1573
remove kube-rbac-proxy container
jaideepr97 Jul 25, 2023
b9cba3d
resolve merge conflicts
jaideepr97 Jul 25, 2023
e7b16ed
add total reconciliations counter, change bucket sizes for histogram
jaideepr97 Jul 26, 2023
bbb5bde
add kuttl test and docs
jaideepr97 Jul 26, 2023
00d4fd9
undo manifest changes
jaideepr97 Jul 26, 2023
9dec2ca
geenrate manifets with old operator-sdk version
jaideepr97 Jul 26, 2023
98b1036
change ci workflow to run opreator on cluster instead of locally
jaideepr97 Jul 27, 2023
30292f4
revert changes to github actions workflows; remove operator-metrics e…
jaideepr97 Jul 27, 2023
3f3b277
remove extra metrics server and move reconciliation count outside of …
jaideepr97 Aug 1, 2023
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
Prev Previous commit
Next Next commit
add total reconciliations counter, change bucket sizes for histogram
Signed-off-by: Jaideep Rao <jaideep.r97@gmail.com>
  • Loading branch information
jaideepr97 committed Jul 26, 2023
commit e7b16ed4c859de6151e8a24c9e4d0611baa20b26
16 changes: 10 additions & 6 deletions controllers/argocd/argocd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

argoproj "github.com/argoproj-labs/argocd-operator/api/v1alpha1"
"github.com/prometheus/client_golang/prometheus"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -110,8 +111,8 @@ func (r *ReconcileArgoCD) Reconcile(ctx context.Context, request ctrl.Request) (
if _, ok := ActiveInstanceMap[request.Namespace]; !ok {
if newPhase != "" {
ActiveInstanceMap[request.Namespace] = newPhase
ActiveInstancesByPhase.WithLabelValues(newPhase).Add(1)
ActiveInstancesTotal.Add(1)
ActiveInstancesByPhase.WithLabelValues(newPhase).Inc()
ActiveInstancesTotal.Inc()
}
} else {
// If we discover an existing instance's phase has changed since we last saw it
Expand All @@ -120,18 +121,21 @@ func (r *ReconcileArgoCD) Reconcile(ctx context.Context, request ctrl.Request) (
// total instance count remains the same
if oldPhase := ActiveInstanceMap[argocd.Namespace]; oldPhase != newPhase {
ActiveInstanceMap[argocd.Namespace] = newPhase
ActiveInstancesByPhase.WithLabelValues(newPhase).Add(1)
ActiveInstancesByPhase.WithLabelValues(oldPhase).Add(-1)
ActiveInstancesByPhase.WithLabelValues(newPhase).Inc()
ActiveInstancesByPhase.WithLabelValues(oldPhase).Dec()
}
ActiveInstanceReconciliationCount.WithLabelValues(argocd.Namespace).Inc()
}

if argocd.GetDeletionTimestamp() != nil {

// Argo CD instance marked for deletion; remove entry from activeInstances map and decrement active instance count
// by phase as well as total
delete(ActiveInstanceMap, argocd.Namespace)
ActiveInstancesByPhase.WithLabelValues(newPhase).Add(-1)
ActiveInstancesTotal.Add(-1)
ActiveInstancesByPhase.WithLabelValues(newPhase).Dec()
ActiveInstancesTotal.Dec()
ActiveInstanceReconciliationCount.DeleteLabelValues(argocd.Namespace)
ReconcileTime.DeletePartialMatch(prometheus.Labels{"namespace": argocd.Namespace})

if argocd.IsDeletionFinalizerPresent() {
if err := r.deleteClusterResources(argocd); err != nil {
Expand Down
17 changes: 12 additions & 5 deletions controllers/argocd/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ var (
},
)

ActiveInstanceReconciliationCount = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "active_argocd_instance_reconciliation_count",
Help: "Number of reconciliations performed for a given instance",
},
[]string{"namespace"},
)

// ReconcileTime is a prometheus metric which keeps track of the duration
// of reconciliations for a given instance
ReconcileTime = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "controller_runtime_reconcile_time_seconds_per_instance",
Help: "Length of time per reconciliation per instance",
Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0,
1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40, 50, 60},
Name: "controller_runtime_reconcile_time_seconds_per_instance",
Help: "Length of time per reconciliation per instance",
Buckets: []float64{0.05, 0.075, 0.1, 0.15, 0.2, 0.22, 0.24, 0.26, 0.28, 0.3, 0.32, 0.34, 0.37, 0.4, 0.42, 0.44, 0.48, 0.5, 0.55, 0.6, 0.75, 0.9, 1.00},
}, []string{"namespace"})
)

Expand All @@ -47,5 +54,5 @@ func StartMetricsServer(port int) chan error {
}

func init() {
metrics.Registry.MustRegister(ActiveInstancesTotal, ActiveInstancesByPhase, ReconcileTime)
metrics.Registry.MustRegister(ActiveInstancesTotal, ActiveInstancesByPhase, ActiveInstanceReconciliationCount, ReconcileTime)
}