Skip to content

Commit

Permalink
feat(metrics): Add metrics.users.disabled flag
Browse files Browse the repository at this point in the history
Introduces the `--metrics.users.disabled` flag, to disable user metrics
like the monthly_active_users. It updates the helm chart.

Signed-off-by: oluwole fadeyi <[email protected]>
  • Loading branch information
tfadeyi committed Dec 6, 2023
1 parent 7f92db7 commit 2aac16a
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/chart-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Helm Charts CI
on:
pull_request:
paths:
- "charts/**"
- "deploy/charts/**"
- ".github/workflows/chart-testing.yaml"
- ".github/workflows/setup_environment/action.yaml"

Expand Down Expand Up @@ -62,4 +62,4 @@ jobs:
with:
version: 'latest'
- name: Run chart-testing (install)
run: ct install --config chart-testing.yaml
run: ct install --config chart-testing.yaml --helm-extra-set-args '--set=exporter.tls.enabled=false --set=auth0.domain="${{ secrets.TEST_AUTH0_DOMAIN }}" --set=auth0.clientId="${{ secrets.TEST_AUTH0_CLIENT_ID }}" --set=auth0.clientSecret="${{ secrets.TEST_AUTH0_CLIENT_SECRET }}"'
2 changes: 1 addition & 1 deletion .github/workflows/setup_environment/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ runs:
- uses: actions/setup-python@v2
with:
python-version: 3.7
- uses: helm/chart-testing-action@v2.0.1
- uses: helm/chart-testing-action@v2.6.1

1 change: 1 addition & 0 deletions cmd/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func serveExporterCmd() *cobra.Command {
exporter.ProbePort(opts.ProbePort),
exporter.From(from),
exporter.Logger(log),
exporter.DisableUserMetrics(opts.UserMetricDisabled),
)
return e.Export()
},
Expand Down
11 changes: 9 additions & 2 deletions cmd/options/exporter/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type (
MetricsEndpoint string
HostPort int
// LogLevel used by the exporter's logger (debug, info, warn, error)
LogLevel string
FromFetchTime string
LogLevel string
FromFetchTime string
UserMetricDisabled bool

// probe
ProbePort int
Expand Down Expand Up @@ -207,4 +208,10 @@ func (o *Options) addAppFlags(fs *pflag.FlagSet) {
"probe",
"URL Path under which to expose the probe metrics.",
)
fs.BoolVar(
&o.UserMetricDisabled,
"metrics.users.disabled",
false,
"Disables the metrics related to the tenant's users.",
)
}
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

pkgs.buildGoApplication {
pname = "auth0-simple-exporter";
version = "v0.2.2";
version = "v0.2.6";
pwd = ./.;
src = ./.;
modules = ./gomod2nix.toml;
Expand Down
4 changes: 2 additions & 2 deletions deploy/charts/auth0-exporter/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.2
version: 0.2.6

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.2.2"
appVersion: "0.2.6"

home: https://github.com/tfadeyi/auth0-simple-exporter
maintainers:
Expand Down
5 changes: 4 additions & 1 deletion deploy/charts/auth0-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ on the `/metrics` endpoint.
| auth0.clientSecret | string | `""` | Auth0 management api client-secret. (do not set if static token is already set) |
| auth0.domain | string | `"<change_me>.eu.auth0.com"` | Auth0 tenant's domain. (i.e: <tenant_name>.eu.auth0.com) |
| auth0.token | string | `""` | Auth0 management api static token. (the token can be used instead of client credentials) |
| exporter | object | `{"logLevel":"info","metricsEndpoint":"metrics","namespace":"","port":9301,"pprof":false,"tls":{"auto":false,"certFile":"","createSecret":false,"disabled":false,"hosts":[],"keyFile":"","secretKey":"","secretName":""}}` | Exporter's configuration |
| exporter | object | `{"logLevel":"info","metrics":{"users":{"disabled":false}},"metricsEndpoint":"metrics","namespace":"","port":9301,"pprof":false,"tls":{"auto":false,"certFile":"","createSecret":false,"disabled":false,"hosts":[],"keyFile":"","secretKey":"","secretName":""}}` | Exporter's configuration |
| exporter.metrics | object | `{"users":{"disabled":false}}` | Exporter's metrics configuration |
| exporter.metrics.users | object | `{"disabled":false}` | Tenant Users metrics exported by the exporter |
| exporter.metrics.users.disabled | bool | `false` | Stops the exporter from fetching user info from the Auth0 tenant |
| exporter.metricsEndpoint | string | `"metrics"` | URL Path under which to expose the collected auth0 metrics. |
| exporter.port | int | `9301` | Port where the server will listen. |
| exporter.pprof | bool | `false` | Enabled pprof profiling on the exporter on port :6060. (help: https://jvns.ca/blog/2017/09/24/profiling-go-with-pprof/) |
Expand Down
11 changes: 7 additions & 4 deletions deploy/charts/auth0-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ spec:
- "--web.listen-address"
- "{{- .Values.exporter.port }}"
{{- end }}
{{- if .Values.exporter.tls.disabled }}
{{- if .Values.exporter.metrics.users.disabled }}
- "--metrics.users.disabled"
{{- end }}
{{- if (not .Values.exporter.tls.enabled) }}
- "--tls.disabled"
{{- else if .Values.exporter.tls.auto }}
- "--tls.auto"
Expand All @@ -86,7 +89,7 @@ spec:
- "--tls.cert-file=/etc/tls-certs/cert-file"
- "--tls.key-file=/etc/tls-certs/key-file"
{{- end }}
{{- if and (not .Values.exporter.tls.disabled) (not .Values.exporter.tls.auto) }}
{{- if and .Values.exporter.tls.enabled (default .Values.exporter.tls.auto false) }}
volumeMounts:
- name: tls-certs
mountPath: "/etc/tls-certs/"
Expand All @@ -106,9 +109,9 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if and (not .Values.exporter.tls.disabled) (not .Values.exporter.tls.auto) }}
{{- if and .Values.exporter.tls.enabled (default .Values.exporter.tls.auto false) }}
volumes:
- name: tls-certs
secret:
secretName: {{ include "auth0-exporter.fullname" . }}
secretName: {{ .Values.exporter.tls.secretName }}
{{- end }}
19 changes: 13 additions & 6 deletions deploy/charts/auth0-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ image:
repository: ghcr.io/tfadeyi/auth0-simple-exporter
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "v0.1.1"
tag: "v0.2.6"

# -- specify credentials if pulling from a customer registry
imagePullSecrets: []
Expand Down Expand Up @@ -42,13 +42,20 @@ exporter:
port: 9301
logLevel: info

# -- Exporter's metrics configuration
metrics:
# -- Tenant Users metrics exported by the exporter
users:
# -- Stops the exporter from fetching user info from the Auth0 tenant
disabled: false

# -- Exporter's TLS configuration
tls:
# -- Allow the exporter to use autocert to renew its certificates with letsencrypt.
# (can only be used if the exporter is publicly accessible by the internet)
auto: false
# -- Run exporter without TLS.
disabled: false
enabled: true
# -- The different allowed hosts for the exporter. Only works when --tls.auto has been enabled.
hosts: []
createSecret: false
Expand Down Expand Up @@ -94,11 +101,11 @@ resources:
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
limits:
cpu: 100m
memory: 128Mi
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
cpu: 100m
memory: 128Mi

nodeSelector: {}

Expand Down
3 changes: 2 additions & 1 deletion dev/devshell.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ packages = [
"prometheus", "moq",
"goreleaser", "golangci-lint",
"tmux", "helm-docs",
"go-swag", "ko", "gnumake"
"go-swag", "ko", "gnumake",
"kubernetes-helm"
]

[[commands]]
Expand Down
36 changes: 18 additions & 18 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ schema = 3
version = "v0.0.0-20170810143723-de5bf2ad4578"
hash = "sha256-nL0/0QM0Pec83vBlwXvQ8g5SvvZnCQgzD1apxfHNGlg="
[mod."github.com/auth0/go-auth0"]
version = "v1.2.0"
hash = "sha256-T8AWJ2JCZ5bnXIltl7EZyVpUloUznHJ2jAvo9zA0BEc="
version = "v1.3.1"
hash = "sha256-XQpkj/k1oyxdCfzCc5r+8/wRf8Gk6J9N4gah2taedZA="
[mod."github.com/beorn7/perks"]
version = "v1.0.1"
hash = "sha256-h75GUqfwJKngCJQVE5Ao5wnO3cfKD9lSIteoLp/3xJ4="
Expand Down Expand Up @@ -65,8 +65,8 @@ schema = 3
version = "v1.0.0"
hash = "sha256-9uZ0wNf44ilzLsvXqOsmFUpNOBFAVadj6+ZH8+QMDMk="
[mod."github.com/labstack/echo/v4"]
version = "v4.11.2"
hash = "sha256-OECk2lBNKKBpzJ58XMhpp8KI/tqE0TnyddWyhI+nHPs="
version = "v4.11.3"
hash = "sha256-rdqH4HQB/vZyEsoymrEsQ8izjf0m7jhrIxbF6r5ZmBo="
[mod."github.com/labstack/gommon"]
version = "v0.4.0"
hash = "sha256-xISAIJEu2xh0hoWsORbgjnz3rDK3ft3hrvmxt0wfHVw="
Expand Down Expand Up @@ -98,8 +98,8 @@ schema = 3
version = "v0.11.1"
hash = "sha256-yphZ7NZtYC/tb0HVag2T58SuN64Ial9sBo/TdCEQx6Q="
[mod."github.com/spf13/cobra"]
version = "v1.7.0"
hash = "sha256-bom9Zpnz8XPwx9IVF+GAodd3NVQ1dM1Uwxn8sy4Gmzs="
version = "v1.8.0"
hash = "sha256-oAE+fEaRfZPE541IPWE0GMeBBYgH2DMhtZNxzp7DFlY="
[mod."github.com/spf13/pflag"]
version = "v1.0.5"
hash = "sha256-w9LLYzxxP74WHT4ouBspH/iQZXjuAh2WQCHsuvyEjAw="
Expand Down Expand Up @@ -128,23 +128,23 @@ schema = 3
version = "v1.11.0"
hash = "sha256-Lb6rHHfR62Ozg2j2JZy3MKOMKdsfzd1IYTR57r3Mhp0="
[mod."golang.org/x/crypto"]
version = "v0.14.0"
hash = "sha256-UUSt3X/i34r1K0mU+Y5IzljX5HYy07JcHh39Pm1MU+o="
version = "v0.16.0"
hash = "sha256-DgSVOnXRK8GF01p5rLtq4qPBcglwEoOk8qhW2EGfJfA="
[mod."golang.org/x/net"]
version = "v0.17.0"
hash = "sha256-qRawHWLSsJ06QNbLhUWPXGVSO1eaioeC9xZlUEWN8J8="
version = "v0.19.0"
hash = "sha256-3M5rKEvJx4cO/q+06cGjR5sxF5JpnUWY0+fQttrWdT4="
[mod."golang.org/x/oauth2"]
version = "v0.13.0"
hash = "sha256-mEmRQrh6FMsenT7x406HbZCynBJCHJ4e9u0M3hpG3m4="
version = "v0.15.0"
hash = "sha256-exA/abu6WOR7Cwqa41LpnTD2xQNRZMYU5CnBKvXHx8Y="
[mod."golang.org/x/sync"]
version = "v0.4.0"
hash = "sha256-VCl5IerUva6XZqGXHa0J/r/ewsbOIIP7EBqyh1JGsXY="
version = "v0.5.0"
hash = "sha256-EAKeODSsct5HhXPmpWJfulKSCkuUu6kkDttnjyZMNcI="
[mod."golang.org/x/sys"]
version = "v0.13.0"
hash = "sha256-/+RDZ0a0oEfJ0k304VqpJpdrl2ZXa3yFlOxy4mjW7w0="
version = "v0.15.0"
hash = "sha256-n7TlABF6179RzGq3gctPDKDPRtDfnwPdjNCMm8ps2KY="
[mod."golang.org/x/text"]
version = "v0.13.0"
hash = "sha256-J34dbc8UNVIdRJUZP7jPt11oxuwG8VvrOOylxE7V3oA="
version = "v0.14.0"
hash = "sha256-yh3B0tom1RfzQBf1RNmfdNWF1PtiqxV41jW1GVS6JAg="
[mod."golang.org/x/time"]
version = "v0.3.0"
hash = "sha256-/hmc9skIswMYbivxNS7R8A6vCTUF9k2/7tr/ACkcEaM="
Expand Down
2 changes: 1 addition & 1 deletion pkg/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"name": "Apache 2.0",
"url": "https://github.com/tfadeyi/auth0-simple-exporter/blob/main/LICENSE"
},
"version": "0.2.1"
"version": "0.2.6"
},
"host": "localhost:8080",
"basePath": "/",
Expand Down
2 changes: 1 addition & 1 deletion pkg/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ info:
name: Apache 2.0
url: https://github.com/tfadeyi/auth0-simple-exporter/blob/main/LICENSE
title: Auth0 simple exporter
version: 0.2.1
version: 0.2.6
paths:
/metrics:
get:
Expand Down
39 changes: 20 additions & 19 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type (
namespace string
subsystem string
// checkpoint from where to start fetching logs
startTime time.Time
startTime time.Time
userMetricDisabled bool

// webserver TLS
tlsDisabled bool
Expand Down Expand Up @@ -170,24 +171,24 @@ func (e *exporter) collect(ctx context.Context, m *metrics.Metrics) error {
}

// Process users
list, err = e.client.User.List(ctx)
switch {
case errors.Is(err, context.Canceled):
eventUsers := list.([]*management.User)
e.logger.V(0).Error(err, "Request was terminated by the client,"+
"the exporter could not finish polling the Auth0 user client to fetch the tenant users."+
"Please increase the client timeout", "users_found", len(eventUsers))
case err != nil:
return errors.Annotate(err, "error fetching the users from Auth0")
}

tenantUsers, ok := list.([]*management.User)
if !ok {
return errors.New("auth0 client users fetch didn't return the expected list of User type")
}

if err := m.ProcessUsers(tenantUsers); err != nil {
e.logger.V(0).Error(err, err.Error())
if !e.userMetricDisabled {
list, err = e.client.User.List(ctx)
switch {
case errors.Is(err, context.Canceled):
eventUsers := list.([]*management.User)
e.logger.V(0).Error(err, "Request was terminated by the client,"+
"the exporter could not finish polling the Auth0 user client to fetch the tenant users."+
"Please increase the client timeout", "users_found", len(eventUsers))
case err != nil:
return errors.Annotate(err, "error fetching the users from Auth0")
}
tenantUsers, ok := list.([]*management.User)
if !ok {
return errors.New("auth0 client users fetch didn't return the expected list of User type")
}
if err := m.ProcessUsers(tenantUsers); err != nil {
e.logger.V(0).Error(err, err.Error())
}
}

return nil
Expand Down
6 changes: 6 additions & 0 deletions pkg/exporter/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,9 @@ func Logger(l logging.Logger) Option {
e.logger = l
}
}

func DisableUserMetrics(flag bool) Option {
return func(e *exporter) {
e.userMetricDisabled = flag
}
}
2 changes: 1 addition & 1 deletion pkg/exporter/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// @title Auth0 simple exporter
// @version 0.2.1
// @version 0.2.6
// @description A simple Prometheus exporter for Auth0 log [events](https://auth0.com/docs/api/management/v2#!/Logs/get_logs),
// @description which allows you to collect metrics from Auth0 and expose them in a format that can be consumed by Prometheus.

Expand Down

0 comments on commit 2aac16a

Please sign in to comment.