Skip to content

Commit

Permalink
[ event-reporter ]: removed env var EVENT_REPORTER_DETAILED_METRICS a…
Browse files Browse the repository at this point in the history
…fter pr review
  • Loading branch information
oleksandr-codefresh committed Dec 27, 2023
1 parent d4977dc commit 77b8785
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
2 changes: 0 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ const (
EnvEventReporterReplicas = "EVENT_REPORTER_REPLICAS"
// EnvEventReporterShard is the shard number that should be handled by reporter
EnvEventReporterShard = "EVENT_REPORTER_SHARD"
// EnvEventReporterDetailedMetrics is bool value that enables sending details metrics with resource kind, app names, etc.
EnvEventReporterDetailedMetrics = "EVENT_REPORTER_DETAILED_METRICS"
)

// Config Management Plugin related constants
Expand Down
19 changes: 4 additions & 15 deletions event_reporter/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package metrics

import (
"fmt"
argocommon "github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/event_reporter/sharding"
"github.com/argoproj/argo-cd/v2/util/env"
"net/http"
"strconv"
"time"
Expand All @@ -18,7 +16,6 @@ import (
type MetricsServer struct {
*http.Server
shard string
detailedMetricsEnabled bool
redisRequestCounter *prometheus.CounterVec
redisRequestHistogram *prometheus.HistogramVec
queueSizeCounter *prometheus.GaugeVec
Expand All @@ -28,8 +25,6 @@ type MetricsServer struct {
eventProcessingDurationHistogram *prometheus.HistogramVec
}

const notDetailedMetricPlaceholderLabel = "not_reported"

type MetricEventType string

const (
Expand Down Expand Up @@ -94,10 +89,10 @@ var (
eventProcessingDurationHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Name: "cf_e_reporter_event_processing_duration",
Help: "Event processing duration.",
Help: "Application event processing duration.",
Buckets: []float64{0.1, 0.25, .5, 1, 2, 3, 4, 5, 7, 10, 15, 20},
},
[]string{"reporter_shard", "application", "kind", "metric_event_type"},
[]string{"reporter_shard", "application", "metric_event_type"},
)
)

Expand All @@ -122,15 +117,13 @@ func NewMetricsServer(host string, port int) *MetricsServer {
registry.MustRegister(eventProcessingDurationHistogram)

shard := sharding.GetShardNumber()
detailedMetrics := env.ParseBoolFromEnv(argocommon.EnvEventReporterDetailedMetrics, false)

return &MetricsServer{
Server: &http.Server{
Addr: fmt.Sprintf("%s:%d", host, port),
Handler: mux,
},
shard: strconv.FormatInt(int64(shard), 10),
detailedMetricsEnabled: detailedMetrics,
queueSizeCounter: queueSizeCounter,
appEventsCounter: appEventsCounter,
erroredEventsCounter: erroredEventsCounter,
Expand Down Expand Up @@ -164,10 +157,6 @@ func (m *MetricsServer) IncCachedIgnoredEventsCounter(metricEventType MetricEven
m.cachedIgnoredEventsCounter.WithLabelValues(m.shard, string(metricEventType), application).Inc()
}

func (m *MetricsServer) ObserveEventProcessingDurationHistogramDuration(application string, managedResourceKind string, metricEventType MetricEventType, duration time.Duration) {
if m.detailedMetricsEnabled {
m.eventProcessingDurationHistogram.WithLabelValues(m.shard, application, managedResourceKind, string(metricEventType)).Observe(duration.Seconds())
} else {
m.eventProcessingDurationHistogram.WithLabelValues(m.shard, notDetailedMetricPlaceholderLabel, notDetailedMetricPlaceholderLabel, string(metricEventType)).Observe(duration.Seconds())
}
func (m *MetricsServer) ObserveEventProcessingDurationHistogramDuration(application string, metricEventType MetricEventType, duration time.Duration) {
m.eventProcessingDurationHistogram.WithLabelValues(m.shard, application, string(metricEventType)).Observe(duration.Seconds())
}
9 changes: 2 additions & 7 deletions event_reporter/reporter/application_event_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ var (
resourceEventCacheExpiration = time.Minute * time.Duration(env.ParseNumFromEnv(argocommon.EnvResourceEventCacheDuration, 20, 0, math.MaxInt32))
)

const ApplicationKind = "Application"

type applicationEventReporter struct {
cache *servercache.Cache
codefreshClient codefresh.CodefreshClient
Expand Down Expand Up @@ -220,7 +218,7 @@ func (s *applicationEventReporter) StreamApplicationEvents(
return err
}
reconcileDuration := time.Since(startTime)
s.metricsServer.ObserveEventProcessingDurationHistogramDuration(a.Name, ApplicationKind, metrics.MetricChildAppEventType, reconcileDuration)
s.metricsServer.ObserveEventProcessingDurationHistogramDuration(a.Name, metrics.MetricChildAppEventType, reconcileDuration)
} else {
logCtx.Info("processing as root application")
// will get here only for root applications (not managed as a resource by another application)
Expand All @@ -241,7 +239,7 @@ func (s *applicationEventReporter) StreamApplicationEvents(
return fmt.Errorf("failed to send event for root application %s/%s: %w", a.Namespace, a.Name, err)
}
reconcileDuration := time.Since(startTime)
s.metricsServer.ObserveEventProcessingDurationHistogramDuration(a.Name, ApplicationKind, metrics.MetricParentAppEventType, reconcileDuration)
s.metricsServer.ObserveEventProcessingDurationHistogramDuration(a.Name, metrics.MetricParentAppEventType, reconcileDuration)
}

revisionMetadata, _ := s.getApplicationRevisionDetails(ctx, a, getOperationRevision(a))
Expand All @@ -256,14 +254,11 @@ func (s *applicationEventReporter) StreamApplicationEvents(
s.metricsServer.IncCachedIgnoredEventsCounter(metrics.MetricResourceEventType, a.Name)
continue
}
startTime := time.Now()
err := s.processResource(ctx, rs, a, logCtx, ts, desiredManifests, appTree, manifestGenErr, nil, revisionMetadata, appInstanceLabelKey, trackingMethod, nil)
if err != nil {
s.metricsServer.IncErroredEventsCounter(metrics.MetricResourceEventType, metrics.MetricEventUnknownErrorType, a.Name)
return err
}
reconcileDuration := time.Since(startTime)
s.metricsServer.ObserveEventProcessingDurationHistogramDuration(a.Name, rs.Kind, metrics.MetricResourceEventType, reconcileDuration)
}
return nil
}
Expand Down

0 comments on commit 77b8785

Please sign in to comment.