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 Nov 18, 2023
1 parent a5a8ca6 commit ad06fdf
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .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
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.",
)
}
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
3 changes: 3 additions & 0 deletions deploy/charts/auth0-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ spec:
- "--web.listen-address"
- "{{- .Values.exporter.port }}"
{{- end }}
{{- if .Values.exporter.metrics.users.disabled }}
- "--metrics.users.disabled"
{{- end }}
{{- if .Values.exporter.tls.disabled }}
- "--tls.disabled"
{{- else if .Values.exporter.tls.auto }}
Expand Down
7 changes: 7 additions & 0 deletions deploy/charts/auth0-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ 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.
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.0"
hash = "sha256-mnH3wj9nClSIN7vhSiwNqsdHdN2ngA13f8LGNoVwZEc="
[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.15.0"
hash = "sha256-ABytl19ORbe9xcY4Ao76AcAkqqPduUCd8OrD4Sl5jyU="
[mod."golang.org/x/net"]
version = "v0.17.0"
hash = "sha256-qRawHWLSsJ06QNbLhUWPXGVSO1eaioeC9xZlUEWN8J8="
version = "v0.18.0"
hash = "sha256-7c3GBByVmRjd7CXf4STGTAnnUWtHVH4S0HjSYUHCcCA="
[mod."golang.org/x/oauth2"]
version = "v0.13.0"
hash = "sha256-mEmRQrh6FMsenT7x406HbZCynBJCHJ4e9u0M3hpG3m4="
version = "v0.14.0"
hash = "sha256-1wCXYvhtiGksL75rrOTDc6P82WuKBeaReqy1l7CahAE="
[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.14.0"
hash = "sha256-ReIRQmONicRW9idzGVPCBx5TTcKacmQTF1vPC3L4SxY="
[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
37 changes: 20 additions & 17 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 @@ -165,22 +166,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
}
}

0 comments on commit ad06fdf

Please sign in to comment.