Skip to content

Commit f18fb1d

Browse files
committed
feat: Add component level metrics configuration for ServiceMonitors
Assisted by: Cursor Signed-off-by: Jayendra Parsai <jparsai@redhat.com>
1 parent 64c4c8b commit f18fb1d

15 files changed

Lines changed: 1195 additions & 32 deletions

File tree

api/v1alpha1/argocd_conversion.go

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (src *ArgoCD) ConvertTo(dstRaw conversion.Hub) error {
7777
dst.Spec.OIDCConfig = src.Spec.OIDCConfig
7878
dst.Spec.Monitoring = v1beta1.ArgoCDMonitoringSpec(src.Spec.Monitoring)
7979
dst.Spec.NodePlacement = (*v1beta1.ArgoCDNodePlacementSpec)(src.Spec.NodePlacement)
80-
dst.Spec.Notifications = v1beta1.ArgoCDNotifications(src.Spec.Notifications)
80+
dst.Spec.Notifications = *ConvertAlphaToBetaNotifications(&src.Spec.Notifications)
8181
dst.Spec.Prometheus = *ConvertAlphaToBetaPrometheus(&src.Spec.Prometheus)
8282
dst.Spec.RBAC = v1beta1.ArgoCDRBACSpec(src.Spec.RBAC)
8383
dst.Spec.Redis = *ConvertAlphaToBetaRedis(&src.Spec.Redis)
@@ -154,7 +154,7 @@ func (dst *ArgoCD) ConvertFrom(srcRaw conversion.Hub) error {
154154
dst.Spec.OIDCConfig = src.Spec.OIDCConfig
155155
dst.Spec.Monitoring = ArgoCDMonitoringSpec(src.Spec.Monitoring)
156156
dst.Spec.NodePlacement = (*ArgoCDNodePlacementSpec)(src.Spec.NodePlacement)
157-
dst.Spec.Notifications = ArgoCDNotifications(src.Spec.Notifications)
157+
dst.Spec.Notifications = *ConvertBetaToAlphaNotifications(&src.Spec.Notifications)
158158
dst.Spec.Prometheus = *ConvertBetaToAlphaPrometheus(&src.Spec.Prometheus)
159159
dst.Spec.RBAC = ArgoCDRBACSpec(src.Spec.RBAC)
160160
dst.Spec.Redis = *ConvertBetaToAlphaRedis(&src.Spec.Redis)
@@ -199,6 +199,7 @@ func ConvertAlphaToBetaController(src *ArgoCDApplicationControllerSpec) *v1beta1
199199
AppSync: src.AppSync,
200200
Sharding: v1beta1.ArgoCDApplicationControllerShardSpec(src.Sharding),
201201
Env: src.Env,
202+
Metrics: v1beta1.ArgoCDMetricsSpec(src.Metrics),
202203
}
203204
}
204205
return dst
@@ -239,6 +240,7 @@ func ConvertAlphaToBetaRepo(src *ArgoCDRepoSpec) *v1beta1.ArgoCDRepoSpec {
239240
Version: src.Version,
240241
VolumeMounts: src.VolumeMounts,
241242
Volumes: src.Volumes,
243+
Metrics: v1beta1.ArgoCDMetricsSpec(src.Metrics),
242244
}
243245
}
244246
return dst
@@ -373,6 +375,7 @@ func ConvertAlphaToBetaServer(src *ArgoCDServerSpec) *v1beta1.ArgoCDServerSpec {
373375
Service: v1beta1.ArgoCDServerServiceSpec(src.Service),
374376
Env: src.Env,
375377
ExtraCommandArgs: src.ExtraCommandArgs,
378+
Metrics: v1beta1.ArgoCDMetricsSpec(src.Metrics),
376379
}
377380
}
378381
return dst
@@ -464,6 +467,7 @@ func ConvertBetaToAlphaController(src *v1beta1.ArgoCDApplicationControllerSpec)
464467
AppSync: src.AppSync,
465468
Sharding: ArgoCDApplicationControllerShardSpec(src.Sharding),
466469
Env: src.Env,
470+
Metrics: ArgoCDMetricsSpec(src.Metrics),
467471
}
468472
}
469473
return dst
@@ -529,6 +533,46 @@ func ConvertBetaToAlphaPrometheus(src *v1beta1.ArgoCDPrometheusSpec) *ArgoCDProm
529533
return dst
530534
}
531535

536+
func ConvertAlphaToBetaNotifications(src *ArgoCDNotifications) *v1beta1.ArgoCDNotifications {
537+
var dst *v1beta1.ArgoCDNotifications
538+
if src != nil {
539+
dst = &v1beta1.ArgoCDNotifications{
540+
Replicas: src.Replicas,
541+
Enabled: src.Enabled,
542+
SourceNamespaces: src.SourceNamespaces,
543+
Env: src.Env,
544+
Image: src.Image,
545+
Version: src.Version,
546+
Resources: src.Resources,
547+
LogLevel: src.LogLevel,
548+
Logformat: src.Logformat,
549+
LogFormat: src.LogFormat,
550+
Metrics: v1beta1.ArgoCDMetricsSpec(src.Metrics),
551+
}
552+
}
553+
return dst
554+
}
555+
556+
func ConvertBetaToAlphaNotifications(src *v1beta1.ArgoCDNotifications) *ArgoCDNotifications {
557+
var dst *ArgoCDNotifications
558+
if src != nil {
559+
dst = &ArgoCDNotifications{
560+
Replicas: src.Replicas,
561+
Enabled: src.Enabled,
562+
SourceNamespaces: src.SourceNamespaces,
563+
Env: src.Env,
564+
Image: src.Image,
565+
Version: src.Version,
566+
Resources: src.Resources,
567+
LogLevel: src.LogLevel,
568+
Logformat: src.Logformat,
569+
LogFormat: src.LogFormat,
570+
Metrics: ArgoCDMetricsSpec(src.Metrics),
571+
}
572+
}
573+
return dst
574+
}
575+
532576
func ConvertBetaToAlphaSSO(src *v1beta1.ArgoCDSSOSpec) *ArgoCDSSOSpec {
533577
var dst *ArgoCDSSOSpec
534578
if src != nil {
@@ -597,6 +641,7 @@ func ConvertBetaToAlphaServer(src *v1beta1.ArgoCDServerSpec) *ArgoCDServerSpec {
597641
Service: ArgoCDServerServiceSpec(src.Service),
598642
Env: src.Env,
599643
ExtraCommandArgs: src.ExtraCommandArgs,
644+
Metrics: ArgoCDMetricsSpec(src.Metrics),
600645
}
601646
}
602647
return dst
@@ -710,6 +755,7 @@ func ConvertBetaToAlphaRepo(src *v1beta1.ArgoCDRepoSpec) *ArgoCDRepoSpec {
710755
Version: src.Version,
711756
VolumeMounts: src.VolumeMounts,
712757
Volumes: src.Volumes,
758+
Metrics: ArgoCDMetricsSpec(src.Metrics),
713759
}
714760
}
715761
return dst

api/v1alpha1/argocd_conversion_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,41 @@ func TestAlphaToBetaConversion(t *testing.T) {
793793
}
794794
}),
795795
},
796+
{
797+
name: "ArgoCD Example - Component Metrics",
798+
input: makeTestArgoCDAlpha(func(cr *ArgoCD) {
799+
cr.Spec.Controller.Metrics = ArgoCDMetricsSpec{
800+
Interval: "60s",
801+
ScrapeTimeout: "30s",
802+
}
803+
cr.Spec.Repo.Metrics = ArgoCDMetricsSpec{
804+
Interval: "90s",
805+
}
806+
cr.Spec.Server.Metrics = ArgoCDMetricsSpec{
807+
ScrapeTimeout: "15s",
808+
}
809+
cr.Spec.Notifications.Metrics = ArgoCDMetricsSpec{
810+
Interval: "45s",
811+
ScrapeTimeout: "20s",
812+
}
813+
}),
814+
expectedOutput: makeTestArgoCDBeta(func(cr *v1beta1.ArgoCD) {
815+
cr.Spec.Controller.Metrics = v1beta1.ArgoCDMetricsSpec{
816+
Interval: "60s",
817+
ScrapeTimeout: "30s",
818+
}
819+
cr.Spec.Repo.Metrics = v1beta1.ArgoCDMetricsSpec{
820+
Interval: "90s",
821+
}
822+
cr.Spec.Server.Metrics = v1beta1.ArgoCDMetricsSpec{
823+
ScrapeTimeout: "15s",
824+
}
825+
cr.Spec.Notifications.Metrics = v1beta1.ArgoCDMetricsSpec{
826+
Interval: "45s",
827+
ScrapeTimeout: "20s",
828+
}
829+
}),
830+
},
796831
}
797832

798833
for _, test := range tests {
@@ -1175,6 +1210,41 @@ func TestBetaToAlphaConversion(t *testing.T) {
11751210
}
11761211
}),
11771212
},
1213+
{
1214+
name: "ArgoCD Example - Component Metrics",
1215+
input: makeTestArgoCDBeta(func(cr *v1beta1.ArgoCD) {
1216+
cr.Spec.Controller.Metrics = v1beta1.ArgoCDMetricsSpec{
1217+
Interval: "60s",
1218+
ScrapeTimeout: "30s",
1219+
}
1220+
cr.Spec.Repo.Metrics = v1beta1.ArgoCDMetricsSpec{
1221+
Interval: "90s",
1222+
}
1223+
cr.Spec.Server.Metrics = v1beta1.ArgoCDMetricsSpec{
1224+
ScrapeTimeout: "15s",
1225+
}
1226+
cr.Spec.Notifications.Metrics = v1beta1.ArgoCDMetricsSpec{
1227+
Interval: "45s",
1228+
ScrapeTimeout: "20s",
1229+
}
1230+
}),
1231+
expectedOutput: makeTestArgoCDAlpha(func(cr *ArgoCD) {
1232+
cr.Spec.Controller.Metrics = ArgoCDMetricsSpec{
1233+
Interval: "60s",
1234+
ScrapeTimeout: "30s",
1235+
}
1236+
cr.Spec.Repo.Metrics = ArgoCDMetricsSpec{
1237+
Interval: "90s",
1238+
}
1239+
cr.Spec.Server.Metrics = ArgoCDMetricsSpec{
1240+
ScrapeTimeout: "15s",
1241+
}
1242+
cr.Spec.Notifications.Metrics = ArgoCDMetricsSpec{
1243+
Interval: "45s",
1244+
ScrapeTimeout: "20s",
1245+
}
1246+
}),
1247+
},
11781248
}
11791249
for _, test := range tests {
11801250
t.Run(test.name, func(t *testing.T) {

api/v1alpha1/argocd_types.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ type ArgoCDApplicationControllerSpec struct {
108108

109109
// Env lets you specify environment for application controller pods
110110
Env []corev1.EnvVar `json:"env,omitempty"`
111+
112+
// Metrics defines the metrics configuration for the Application Controller ServiceMonitor.
113+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
111114
}
112115

113116
// ArgoCDApplicationControllerShardSpec defines the options available for enabling sharding for the Application Controller component.
@@ -353,6 +356,20 @@ type ArgoCDNotifications struct {
353356
// LogFormat refers to the log format used by the argocd-notifications. Defaults to ArgoCDDefaultLogFormat if not configured. Valid options are text or json.
354357
// +kubebuilder:validation:Enum=text;json
355358
LogFormat string `json:"logFormat,omitempty"`
359+
360+
// Metrics defines the metrics configuration for the Notifications ServiceMonitor.
361+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
362+
}
363+
364+
// ArgoCDMetricsSpec defines the metrics configuration for a component's ServiceMonitor.
365+
type ArgoCDMetricsSpec struct {
366+
// Interval specifies the Prometheus scrape interval for this component's ServiceMonitor.
367+
// If empty, Prometheus uses its default scrape interval.
368+
Interval string `json:"interval,omitempty"`
369+
370+
// ScrapeTimeout specifies the Prometheus scrape timeout for this component's ServiceMonitor.
371+
// If empty, Prometheus uses the global scrape timeout.
372+
ScrapeTimeout string `json:"scrapeTimeout,omitempty"`
356373
}
357374

358375
// ArgoCDPrometheusSpec defines the desired state for the Prometheus component.
@@ -492,6 +509,9 @@ type ArgoCDRepoSpec struct {
492509
// server deployment. If the image field is omitted from a SidecarContainer,
493510
// the image for the repo server will be used.
494511
SidecarContainers []corev1.Container `json:"sidecarContainers,omitempty"`
512+
513+
// Metrics defines the metrics configuration for the Repo Server ServiceMonitor.
514+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
495515
}
496516

497517
// ArgoCDRouteSpec defines the desired state for an OpenShift Route.
@@ -585,6 +605,9 @@ type ArgoCDServerSpec struct {
585605
// ExtraCommandArgs will not be added, if one of these commands is already part of the server command
586606
// with same or different value.
587607
ExtraCommandArgs []string `json:"extraCommandArgs,omitempty"`
608+
609+
// Metrics defines the metrics configuration for the Server ServiceMonitor.
610+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
588611
}
589612

590613
// ArgoCDServerServiceSpec defines the Service options for Argo CD Server component.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta1/argocd_types.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ type ArgoCDApplicationControllerSpec struct {
137137

138138
// RespectRBAC restricts controller from discovering/syncing specific resources, Defaults is empty if not configured. Valid options are strict and normal.
139139
RespectRBAC string `json:"respectRBAC,omitempty"`
140+
141+
// Metrics defines the metrics configuration for the Application Controller ServiceMonitor.
142+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
140143
}
141144

142145
func (a *ArgoCDApplicationControllerSpec) IsEnabled() bool {
@@ -438,6 +441,20 @@ type ArgoCDNotifications struct {
438441
// LogFormat refers to the log format used by the argocd-notifications. Defaults to ArgoCDDefaultLogFormat if not configured. Valid options are text or json.
439442
// +kubebuilder:validation:Enum=text;json
440443
LogFormat string `json:"logFormat,omitempty"`
444+
445+
// Metrics defines the metrics configuration for the Notifications ServiceMonitor.
446+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
447+
}
448+
449+
// ArgoCDMetricsSpec defines the metrics configuration for a component's ServiceMonitor.
450+
type ArgoCDMetricsSpec struct {
451+
// Interval specifies the Prometheus scrape interval for this component's ServiceMonitor.
452+
// If empty, Prometheus uses its default scrape interval.
453+
Interval string `json:"interval,omitempty"`
454+
455+
// ScrapeTimeout specifies the Prometheus scrape timeout for this component's ServiceMonitor.
456+
// If empty, Prometheus uses the global scrape timeout.
457+
ScrapeTimeout string `json:"scrapeTimeout,omitempty"`
441458
}
442459

443460
// ArgoCDPrometheusSpec defines the desired state for the Prometheus component.
@@ -606,6 +623,9 @@ type ArgoCDRepoSpec struct {
606623

607624
// Custom certificates to inject into the repo server container and its plugins to trust source hosting sites
608625
SystemCATrust *ArgoCDSystemCATrustSpec `json:"systemCATrust,omitempty"`
626+
627+
// Metrics defines the metrics configuration for the Repo Server ServiceMonitor.
628+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
609629
}
610630

611631
func (a *ArgoCDRepoSpec) IsEnabled() bool {
@@ -740,6 +760,9 @@ type ArgoCDServerSpec struct {
740760

741761
// Custom labels to pods deployed by the operator
742762
Labels map[string]string `json:"labels,omitempty"`
763+
764+
// Metrics defines the metrics configuration for the Server ServiceMonitor.
765+
Metrics ArgoCDMetricsSpec `json:"metrics,omitempty"`
743766
}
744767

745768
func (a *ArgoCDServerSpec) IsEnabled() bool {

0 commit comments

Comments
 (0)