diff --git a/.github/workflows/chart-testing.yaml b/.github/workflows/chart-testing.yaml index 512e016..0ad7fd3 100644 --- a/.github/workflows/chart-testing.yaml +++ b/.github/workflows/chart-testing.yaml @@ -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" @@ -62,4 +62,8 @@ 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.disabled=true --set=auth0.domain="${{ secrets.TEST_AUTH0_DOMAIN }}" --set=auth0.clientId="$CLIENT_ID" --set=auth0.clientSecret="$CLIENT_SECRET"' + env: + CLIENT_ID: ${{ secrets.TEST_AUTH0_CLIENT_ID }} + CLIENT_SECRET: ${{ secrets.TEST_AUTH0_CLIENT_SECRET }} + DOMAIN: ${{ secrets.TEST_AUTH0_DOMAIN }} diff --git a/.github/workflows/setup_environment/action.yaml b/.github/workflows/setup_environment/action.yaml index adbdb0b..cc32532 100644 --- a/.github/workflows/setup_environment/action.yaml +++ b/.github/workflows/setup_environment/action.yaml @@ -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 diff --git a/cmd/exporter.go b/cmd/exporter.go index ae596e8..d3d6f66 100644 --- a/cmd/exporter.go +++ b/cmd/exporter.go @@ -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() }, diff --git a/cmd/options/exporter/options.go b/cmd/options/exporter/options.go index 23005eb..8f62e54 100644 --- a/cmd/options/exporter/options.go +++ b/cmd/options/exporter/options.go @@ -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 @@ -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.", + ) } diff --git a/default.nix b/default.nix index 22be318..3fab8f3 100644 --- a/default.nix +++ b/default.nix @@ -13,7 +13,7 @@ pkgs.buildGoApplication { pname = "auth0-simple-exporter"; - version = "v0.2.2"; + version = "v0.2.6"; pwd = ./.; src = ./.; modules = ./gomod2nix.toml; diff --git a/deploy/charts/auth0-exporter/Chart.yaml b/deploy/charts/auth0-exporter/Chart.yaml index 3405c75..109b649 100644 --- a/deploy/charts/auth0-exporter/Chart.yaml +++ b/deploy/charts/auth0-exporter/Chart.yaml @@ -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: diff --git a/deploy/charts/auth0-exporter/README.md b/deploy/charts/auth0-exporter/README.md index 4ce58a1..cee7eca 100644 --- a/deploy/charts/auth0-exporter/README.md +++ b/deploy/charts/auth0-exporter/README.md @@ -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 | `".eu.auth0.com"` | Auth0 tenant's domain. (i.e: .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/) | diff --git a/deploy/charts/auth0-exporter/templates/deployment.yaml b/deploy/charts/auth0-exporter/templates/deployment.yaml index 98115fa..999c974 100644 --- a/deploy/charts/auth0-exporter/templates/deployment.yaml +++ b/deploy/charts/auth0-exporter/templates/deployment.yaml @@ -76,17 +76,20 @@ 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 }} - "--tls.auto" - "--tls.hosts" - "{{- .Values.exporter.tls.hosts}}" - {{- else if (not .Values.exporter.tls.auto) }} + {{- else if (not .Values.exporter.tls.disabled) }} - "--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 (default .Values.exporter.tls.disabled false) (default .Values.exporter.tls.auto false) }} volumeMounts: - name: tls-certs mountPath: "/etc/tls-certs/" @@ -106,9 +109,9 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} - {{- if and (not .Values.exporter.tls.disabled) (not .Values.exporter.tls.auto) }} + {{- if and (default .Values.exporter.tls.disabled false) (default .Values.exporter.tls.auto false) }} volumes: - name: tls-certs secret: - secretName: {{ include "auth0-exporter.fullname" . }} + secretName: {{ .Values.exporter.tls.secretName }} {{- end }} diff --git a/deploy/charts/auth0-exporter/values.yaml b/deploy/charts/auth0-exporter/values.yaml index 5085463..b2210af 100644 --- a/deploy/charts/auth0-exporter/values.yaml +++ b/deploy/charts/auth0-exporter/values.yaml @@ -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: [] @@ -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. @@ -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: {} diff --git a/dev/devshell.toml b/dev/devshell.toml index dea9550..04aa672 100644 --- a/dev/devshell.toml +++ b/dev/devshell.toml @@ -32,7 +32,8 @@ packages = [ "prometheus", "moq", "goreleaser", "golangci-lint", "tmux", "helm-docs", - "go-swag", "ko", "gnumake" + "go-swag", "ko", "gnumake", + "kubernetes-helm" ] [[commands]] diff --git a/gomod2nix.toml b/gomod2nix.toml index f33e909..2990c77 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -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=" @@ -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=" @@ -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=" @@ -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=" diff --git a/pkg/docs/docs.go b/pkg/docs/docs.go index 5e4fe1b..9fab627 100644 --- a/pkg/docs/docs.go +++ b/pkg/docs/docs.go @@ -49,7 +49,7 @@ const docTemplate = `{ // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "0.2.1", + Version: "0.2.6", Host: "localhost:8080", BasePath: "/", Schemes: []string{}, diff --git a/pkg/docs/swagger.json b/pkg/docs/swagger.json index 3049f48..13cd910 100644 --- a/pkg/docs/swagger.json +++ b/pkg/docs/swagger.json @@ -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": "/", diff --git a/pkg/docs/swagger.yaml b/pkg/docs/swagger.yaml index 1c09428..707dc0a 100644 --- a/pkg/docs/swagger.yaml +++ b/pkg/docs/swagger.yaml @@ -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: diff --git a/pkg/exporter/exporter.go b/pkg/exporter/exporter.go index 2122aaf..538d10f 100644 --- a/pkg/exporter/exporter.go +++ b/pkg/exporter/exporter.go @@ -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 @@ -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 diff --git a/pkg/exporter/options.go b/pkg/exporter/options.go index 22b0818..51f912d 100644 --- a/pkg/exporter/options.go +++ b/pkg/exporter/options.go @@ -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 + } +} diff --git a/pkg/exporter/server.go b/pkg/exporter/server.go index 94055c4..b145dd9 100644 --- a/pkg/exporter/server.go +++ b/pkg/exporter/server.go @@ -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.