Skip to content
Open
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
2 changes: 2 additions & 0 deletions controller/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ func (c *liveStateCache) getCluster(cluster *appv1.Cluster) (clustercache.Cluste
c.lock.RUnlock()

if cacheSettings.ignoreResourceUpdatesEnabled && oldRes != nil && newRes != nil && skipResourceUpdate(resInfo(oldRes), resInfo(newRes)) {
gvk := ref.GroupVersionKind()
c.metricsServer.IncClusterEventsIgnoredCount(cluster.Server, gvk.Group, gvk.Kind)
// Additional check for debug level so we don't need to evaluate the
// format string in case of non-debug scenarios
if log.GetLevel() >= log.DebugLevel {
Expand Down
14 changes: 14 additions & 0 deletions controller/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type MetricsServer struct {
orphanedResourcesGauge *prometheus.GaugeVec
k8sRequestCounter *prometheus.CounterVec
clusterEventsCounter *prometheus.CounterVec
clusterEventsIgnoredCounter *prometheus.CounterVec
redisRequestCounter *prometheus.CounterVec
reconcileHistogram *prometheus.HistogramVec
redisRequestHistogram *prometheus.HistogramVec
Expand Down Expand Up @@ -118,6 +119,11 @@ var (
Help: "Number of processes k8s resource events.",
}, append(descClusterDefaultLabels, "group", "kind"))

clusterEventsIgnoredCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "argocd_cluster_events_ignored_total",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can call this argocd_resource_updates_ignored_total?

Suggested change
Name: "argocd_cluster_events_ignored_total",
Name: "argocd_resource_updates_ignored_total",

Help: "Number of k8s resource events ignored by ignoreResourceUpdates rules.",
}, append(descClusterDefaultLabels, "group", "kind"))

redisRequestCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "argocd_redis_request_total",
Expand Down Expand Up @@ -204,6 +210,7 @@ func NewMetricsServer(addr string, appLister applister.ApplicationLister, appFil
registry.MustRegister(orphanedResourcesGauge)
registry.MustRegister(reconcileHistogram)
registry.MustRegister(clusterEventsCounter)
registry.MustRegister(clusterEventsIgnoredCounter)
registry.MustRegister(redisRequestCounter)
registry.MustRegister(redisRequestHistogram)
registry.MustRegister(resourceEventsProcessingHistogram)
Expand All @@ -226,6 +233,7 @@ func NewMetricsServer(addr string, appLister applister.ApplicationLister, appFil
orphanedResourcesGauge: orphanedResourcesGauge,
reconcileHistogram: reconcileHistogram,
clusterEventsCounter: clusterEventsCounter,
clusterEventsIgnoredCounter: clusterEventsIgnoredCounter,
redisRequestCounter: redisRequestCounter,
redisRequestHistogram: redisRequestHistogram,
resourceEventsProcessingHistogram: resourceEventsProcessingHistogram,
Expand Down Expand Up @@ -283,6 +291,11 @@ func (m *MetricsServer) IncClusterEventsCount(server, group, kind string) {
m.clusterEventsCounter.WithLabelValues(server, group, kind).Inc()
}

// IncClusterEventsIgnoredCount increments the number of cluster events ignored by ignoreResourceUpdates rules
func (m *MetricsServer) IncClusterEventsIgnoredCount(server, group, kind string) {
m.clusterEventsIgnoredCounter.WithLabelValues(server, group, kind).Inc()
}

// IncKubernetesRequest increments the kubernetes requests counter for an application
func (m *MetricsServer) IncKubernetesRequest(app *argoappv1.Application, server, statusCode, verb, resourceKind, resourceNamespace string) {
var namespace, name, project string
Expand Down Expand Up @@ -339,6 +352,7 @@ func (m *MetricsServer) SetExpiration(cacheExpiration time.Duration) error {
m.orphanedResourcesGauge.Reset()
m.k8sRequestCounter.Reset()
m.clusterEventsCounter.Reset()
m.clusterEventsIgnoredCounter.Reset()
m.redisRequestCounter.Reset()
m.reconcileHistogram.Reset()
m.redisRequestHistogram.Reset()
Expand Down
29 changes: 29 additions & 0 deletions controller/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,35 @@ workqueue_unfinished_work_seconds{controller="test",name="test"}
assertMetricsPrinted(t, expectedMetrics, body)
}

func TestMetricsClusterEventsIgnored(t *testing.T) {
cancel, appLister := newFakeLister(t.Context())
defer cancel()
mockDB := mocks.NewArgoDB(t)
metricsServ, err := NewMetricsServer("localhost:8082", appLister, appFilter, noOpHealthCheck, []string{}, []string{}, mockDB)
require.NoError(t, err)

expectedMetrics := `
# HELP argocd_cluster_events_ignored_total Number of k8s resource events ignored by ignoreResourceUpdates rules.
# TYPE argocd_cluster_events_ignored_total counter
argocd_cluster_events_ignored_total{group="apps",kind="Deployment",server="https://localhost:6443"} 3
argocd_cluster_events_ignored_total{group="",kind="Pod",server="https://localhost:6443"} 1
`

metricsServ.IncClusterEventsIgnoredCount("https://localhost:6443", "apps", "Deployment")
metricsServ.IncClusterEventsIgnoredCount("https://localhost:6443", "apps", "Deployment")
metricsServ.IncClusterEventsIgnoredCount("https://localhost:6443", "apps", "Deployment")
metricsServ.IncClusterEventsIgnoredCount("https://localhost:6443", "", "Pod")

req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/metrics", http.NoBody)
require.NoError(t, err)
rr := httptest.NewRecorder()
metricsServ.Handler.ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)
body := rr.Body.String()
t.Log(body)
assertMetricsPrinted(t, expectedMetrics, body)
}

func TestGoMetrics(t *testing.T) {
cancel, appLister := newFakeLister(t.Context())
defer cancel()
Expand Down
1 change: 1 addition & 0 deletions docs/operator-manual/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Metrics about applications. Scraped at the `argocd-metrics:8082/metrics` endpoin
| `argocd_cluster_cache_age_seconds` | gauge | Cluster cache age in seconds. |
| `argocd_cluster_connection_status` | gauge | The k8s cluster current connection status. |
| `argocd_cluster_events_total` | counter | Number of processes k8s resource events. |
| `argocd_cluster_events_ignored_total` | counter | Number of k8s resource events ignored by `ignoreResourceUpdates` rules. |
| `argocd_cluster_info` | gauge | Information about cluster. |
| `argocd_redis_request_duration` | histogram | Redis requests duration. |
| `argocd_redis_request_total` | counter | Number of redis requests executed during application reconciliation |
Expand Down
Loading