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(controller): add targetRevision in metric app_info #15143

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ebuildy
Copy link
Contributor

@ebuildy ebuildy commented Aug 21, 2023

Add "targetRevision" for argocd_app_info metric.

--> Should fix #4115

This is useful for:

  • production env: check apps are using master branch
  • dev env: check apps are not using master branch
  • alert on drift: "A devops guy could change manually an app revision in order to test some code changes, I want to be alerted after 2 days in order to rollback the app revision to master"

@ebuildy ebuildy force-pushed the feat_controller_app_info_metrics branch from 27a3b50 to 0f21375 Compare August 22, 2023 11:58
@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Attention: Patch coverage is 94.11765% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 49.25%. Comparing base (f87897c) to head (2449b16).
Report is 102 commits behind head on master.

❗ Current head 2449b16 differs from pull request most recent head 9b7215d. Consider uploading reports for the commit 9b7215d to get more accurate results

Files Patch % Lines
cmd/argocd/commands/admin/app.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15143      +/-   ##
==========================================
- Coverage   49.73%   49.25%   -0.49%     
==========================================
  Files         274      274              
  Lines       48948    48119     -829     
==========================================
- Hits        24343    23699     -644     
+ Misses      22230    22076     -154     
+ Partials     2375     2344      -31     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@ashishkcs ashishkcs left a comment

Choose a reason for hiding this comment

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

This looks good and will be nice to have this in.

@ashishkcs
Copy link

@alexmt @jessesuen could you please approve this?

@sosoriov
Copy link

sosoriov commented Oct 4, 2023

What is the current status of this?

@aspyker
Copy link

aspyker commented Oct 15, 2023

Would also like to know if / when this will be merged.

@mikejoh
Copy link

mikejoh commented Nov 29, 2023

We would also like to see this feature added but when reading up on this there's been a discussion regarding the risk of an explosion of metric cardinality due to the uniqueness of the label revision. One person suggested a way of making it optional to add revision as label to argocd_app_info which sounds like a good idea. How about revisiting that in this PR?

@ebuildy
Copy link
Contributor Author

ebuildy commented Nov 29, 2023

We would also like to see this feature added but when reading up on this there's been a discussion regarding the risk of an explosion of metric cardinality due to the uniqueness of the label revision. One person suggested a way of making it optional to add revision as label to argocd_app_info which sounds like a good idea. How about revisiting that in this PR?

I could add a revision whitelist as setting:

metricRevisions: [master, develop]

If branch is not whitelisted -> "other"

what do u think?

@mikejoh
Copy link

mikejoh commented Nov 30, 2023

I could add a revision whitelist as setting:

metricRevisions: [master, develop]

If branch is not whitelisted -> "other"

what do u think?

I think that if we're about to add this label we should keep all possible values. Adding a feature toggle via e.g. a flag and clearly explaning what the flag does would be another approach. In the end maybe a combination of both approaches?

@ebuildy
Copy link
Contributor Author

ebuildy commented Nov 30, 2023

I could add a revision whitelist as setting:
metricRevisions: [master, develop]
If branch is not whitelisted -> "other"
what do u think?

I think that if we're about to add this label we should keep all possible values. Adding a feature toggle via e.g. a flag and clearly explaning what the flag does would be another approach. In the end maybe a combination of both approaches?

Well, the whitelist is a good idea and we could switch off this feature if whitelist is empty.

Possible whitelist values:

  • "" --> switch off
  • "master" --> only master branch, other revisions are labelized as "other"
  • "master,develop"
  • "*" --> switch on, all revisions
  • "master,feat/" --> master, branches matching feat/

@mikejoh
Copy link

mikejoh commented Dec 1, 2023

Well, the whitelist is a good idea and we could switch off this feature if whitelist is empty.

Possible whitelist values:

  • "" --> switch off
  • "master" --> only master branch, other revisions are labelized as "other"
  • "master,develop"
  • "*" --> switch on, all revisions
  • "master,feat/" --> master, branches matching feat/

Yes, this makes sense, by coincidence I saw something similar in kube-state-metrics which exposes a --metric-labels-allowlist flag that does the following:

Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the labels metrics are not exposed. To include them, provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '' can be provided per resource instead to allow any labels, but that has severe performance implications (Example: '=pods=[]'). Additionally, an asterisk () can be provided as a key, which will resolve to all resources, i.e., assuming '--resources=deployments,pods', '==[]' will resolve to '=deployments=[],pods=[*]'.

Note that this flag adds another metric called kube_node_labels, which then can be used with e.g. joins in PromQL. In this case with ArgoCD, adding a separate metric might also be considered?

@ebuildy ebuildy force-pushed the feat_controller_app_info_metrics branch from 3343955 to a5bada1 Compare December 27, 2023 21:06
@ebuildy ebuildy requested a review from a team as a code owner December 27, 2023 21:06
@ebuildy
Copy link
Contributor Author

ebuildy commented Dec 28, 2023

Well, the whitelist is a good idea and we could switch off this feature if whitelist is empty.
Possible whitelist values:

  • "" --> switch off
  • "master" --> only master branch, other revisions are labelized as "other"
  • "master,develop"
  • "*" --> switch on, all revisions
  • "master,feat/" --> master, branches matching feat/

Yes, this makes sense, by coincidence I saw something similar in kube-state-metrics which exposes a --metric-labels-allowlist flag that does the following:

Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the labels metrics are not exposed. To include them, provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '' can be provided per resource instead to allow any labels, but that has severe performance implications (Example: '=pods=[]'). Additionally, an asterisk () can be provided as a key, which will resolve to all resources, i.e., assuming '--resources=deployments,pods', '==[]' will resolve to '=deployments=[],pods=[*]'.

Note that this flag adds another metric called kube_node_labels, which then can be used with e.g. joins in PromQL. In this case with ArgoCD, adding a separate metric might also be considered?

Check latest commits!

@ebuildy ebuildy force-pushed the feat_controller_app_info_metrics branch from 379cde4 to 13a5110 Compare January 7, 2024 23:48
@ebuildy ebuildy marked this pull request as draft January 7, 2024 23:51
@ebuildy ebuildy force-pushed the feat_controller_app_info_metrics branch from 13a5110 to 1afb96b Compare January 7, 2024 23:52
@ebuildy ebuildy force-pushed the feat_controller_app_info_metrics branch from 1afb96b to 56b1bcd Compare January 7, 2024 23:54
@ebuildy ebuildy marked this pull request as ready for review January 7, 2024 23:54
@tibuntu
Copy link

tibuntu commented Mar 13, 2024

Any news on this?

@antonhornquist
Copy link
Contributor

+1. any news on this PR? we'd really appreciate this support.

@@ -384,7 +395,7 @@ func (c *appCollector) collectApps(ch chan<- prometheus.Metric, app *argoappv1.A

autoSyncEnabled := app.Spec.SyncPolicy != nil && app.Spec.SyncPolicy.Automated != nil

addGauge(descAppInfo, 1, strconv.FormatBool(autoSyncEnabled), git.NormalizeGitURL(app.Spec.GetSource().RepoURL), app.Spec.Destination.Server, app.Spec.Destination.Namespace, string(syncStatus), string(healthStatus), operation)
addGauge(descAppInfo, 1, strconv.FormatBool(autoSyncEnabled), git.NormalizeGitURL(app.Spec.GetSource().RepoURL), c.normalizeAppTargetRevision(app.Spec.GetSource().TargetRevision), app.Spec.Destination.Server, app.Spec.Destination.Namespace, string(syncStatus), string(healthStatus), operation)
Copy link
Contributor

@reegnz reegnz Apr 15, 2024

Choose a reason for hiding this comment

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

What would the metric show if targetRevision is not defined in the argocd Application?
You should add HEAD in case targetRevision is not defined (as that's the default).
Displaying an empty string is misleading and most people likely won't have an explicit targetRevision set, so they might be surprised.

For me as a user it would be VERY confusing to have master, main, develop whitelisted by default, and then seeing an empty string for the label, when argocd actually syncs from main. Setting it to HEAD is less confusing, it's the default if targetRevision is not set, and matches existing docs: https://argo-cd.readthedocs.io/en/stable/user-guide/tracking_strategies/#head-branch-tracking

argocd_app_info{autosync_enabled="false",dest_namespace="dummy-namespace",dest_server="https://localhost:6443",health_status="Healthy",name="my-app",namespace="argocd",operation="",project="important-project",repo="https://github.com/argoproj/argocd-example-apps",sync_status="Synced"} 1
argocd_app_info{autosync_enabled="true",dest_namespace="dummy-namespace",dest_server="https://localhost:6443",health_status="Healthy",name="my-app-2",namespace="argocd",operation="sync",project="important-project",repo="https://github.com/argoproj/argocd-example-apps",sync_status="Synced"} 1
argocd_app_info{autosync_enabled="true",dest_namespace="dummy-namespace",dest_server="https://localhost:6443",health_status="Degraded",name="my-app-3",namespace="argocd",operation="delete",project="important-project",repo="https://github.com/argoproj/argocd-example-apps",revision="develop",sync_status="OutOfSync"} 1
argocd_app_info{autosync_enabled="false",dest_namespace="dummy-namespace",dest_server="https://localhost:6443",health_status="Healthy",name="my-app",namespace="argocd",operation="",project="important-project",repo="https://github.com/argoproj/argocd-example-apps",revision="",sync_status="Synced"} 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I think showing an empty string here is misleading, and should show HEAD instead.
Then at least we can say empty string means something that's both not whitelisted branch and not the default HEAD branch.

Comparing my-app and my-app-4:

my-app the user didn't explicitly define a targetRevision, so it's really master or main or whatever the default branch is configured to. This should show HEAD as the metric label.
my-app-4 the user didn't explicitly whitelist the custom branch name so the label is empty. This is fine.

@ebuildy ebuildy marked this pull request as draft April 15, 2024 20:07
@ebuildy
Copy link
Contributor Author

ebuildy commented Apr 15, 2024

hello @reegnz , thanks you for the feedbacks! I have edited the PR to handle "head" .

@ebuildy ebuildy marked this pull request as ready for review April 15, 2024 21:32
@@ -363,6 +363,9 @@ func boolFloat64(b bool) float64 {
}

func (c *appCollector) normalizeAppTargetRevision(in string) string {
if len(in) == 0 {
in = "head"
Copy link
Contributor

@reegnz reegnz Apr 16, 2024

Choose a reason for hiding this comment

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

nitpicking, but git semantics seem to be using all caps HEAD, not lowercase. lowercase head is probably nothing special for git (unless you have a branch called head). At least that's what I'm seeing in all the docs and also ArgoCD UI, uppercase HEAD.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have hesitated, meanwhile it's good to have prom labels lowercased right?

Co-authored-by: Mikael Johansson <[email protected]>
Signed-off-by: Thomas Decaux <[email protected]>
@mikejoh
Copy link

mikejoh commented Apr 19, 2024

@ebuildy There were two variables with a typo:

  • metricsAplicationLabels
  • metricsAplicationRevisions

You fixed the latter one, but there's references to them when the command flags are composed in the same file. That seems to be the reason for the failed builds on the latest commit!

@antonhornquist
Copy link
Contributor

AFAICT still typos r(metricsAplicationLabels), even thought these may be in the codebase since before does it make sense fixing them?

@ebuildy
Copy link
Contributor Author

ebuildy commented Apr 28, 2024

AFAICT still typos r(metricsAplicationLabels), even thought these may be in the codebase since before does it make sense fixing them?

Well, this is here from 3 years now ^^ https://github.com/argoproj/argo-cd/pull/7374/files#diff-21d1e1ae7561765d523f51ae68a0b94580d1a5980378aa8ccbaa2a7581fc0643R52 , I could do another PR later to fix it with pleasure!

@ebuildy ebuildy marked this pull request as draft April 28, 2024 19:11
@ebuildy ebuildy marked this pull request as ready for review May 6, 2024 12:33
@jace-ys
Copy link

jace-ys commented Aug 10, 2024

Any updates on this? Would love to see this merged!

@reegnz
Copy link
Contributor

reegnz commented Aug 12, 2024

AFAICT @ebuildy needs to sign off his commits because the DCO check is failing.
I'm also very eager to get this merged!

@jenting
Copy link
Contributor

jenting commented Sep 26, 2024

Would love to see this PR get reviewed and merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TargetRevision to argocd_app_info metric