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

add metrics #21

Merged
merged 9 commits into from
Dec 21, 2022
Merged

add metrics #21

merged 9 commits into from
Dec 21, 2022

Conversation

anvddriesch
Copy link
Contributor

@anvddriesch anvddriesch commented Dec 20, 2022

towards giantswarm/roadmap#1809

this adds a metric containing info about dex app registrations

@anvddriesch anvddriesch requested a review from a team December 20, 2022 09:46
@@ -29,6 +30,11 @@ type ProviderCredential struct {
Credentials map[string]string `yaml:"credentials"`
}

type ProviderApp struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of just the connector, we return this struct now that also contains the time of secret expiry. We can also use it to add more properties later in case that's needed.

@@ -0,0 +1,89 @@
package azure
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved some secret related functions to its own file.

"gopkg.in/yaml.v2"
)

type azureSecret struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also adding a struct for the secret since returning a bunch of strings is messy and error prone.

"app_registration_name",
}

AppInfo = prometheus.NewGaugeVec(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the prometheus metric. We create a row for each dex app registration. Its value is the expiry date of the client secret.


// Gauge for secret expiry time
var (
infoLabels = []string{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the labels we set on the metrics.

default:
return dexConfig, microerror.Maskf(invalidConfigError, "Owner %s is not known.", provider.GetOwner())
}
AppInfo.WithLabelValues(s.app.Name, s.app.Namespace, provider.GetOwner(), provider.GetType(), provider.GetName(), appConfig.Name).Set(float64(providerApp.SecretEndDateTime.Unix()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Metric is updated for each registered provider in each loop.

@@ -179,3 +180,8 @@ func (r *AppReconciler) NewProvider(p provider.ProviderCredential) (provider.Pro
}
return nil, microerror.Maskf(invalidConfigError, "%s is not a valid provider name.", p.Name)
}

func init() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function registers the metric

@anvddriesch
Copy link
Contributor Author

I tested this and it works fine. Example of a grafana table showing some of the labels:

Screenshot from 2022-12-20 21-13-10

@anvddriesch anvddriesch requested review from a team and removed request for a team December 20, 2022 12:57
@anvddriesch anvddriesch merged commit 88ace02 into main Dec 21, 2022
@anvddriesch anvddriesch deleted the metrics branch December 21, 2022 08:05
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.

2 participants