Skip to content

Commit

Permalink
fix(timeout): Don't timeout in requests to metrics endpoint (#118)
Browse files Browse the repository at this point in the history
Signed-off-by: oluwole fadeyi <[email protected]>
  • Loading branch information
tfadeyi authored Nov 1, 2023
1 parent 11d2627 commit db636e6
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deploy/charts/auth0-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ on the `/metrics` endpoint.
| tolerations | list | `[]` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
Autogenerated from chart metadata using [helm-docs v1.11.2](https://github.com/norwoodj/helm-docs/releases/v1.11.2)
8 changes: 4 additions & 4 deletions pkg/client/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ func (l *logClient) List(ctx context.Context, args ...interface{}) (interface{},
)
switch {
case errors.Is(err, errors.QuotaLimitExceeded):
return nil, ErrAPIRateLimitReached
return allLogs, ErrAPIRateLimitReached
case err != nil:
return nil, err
return allLogs, err
case len(logs) > 0:
checkpoint = logs[0]
}
Expand All @@ -92,9 +92,9 @@ func (l *logClient) List(ctx context.Context, args ...interface{}) (interface{},
logs, err := l.fetchLogs(ctx, checkpoint)
switch {
case errors.Is(err, errors.QuotaLimitExceeded):
return nil, ErrAPIRateLimitReached
return allLogs, ErrAPIRateLimitReached
case err != nil:
return nil, err
return allLogs, err
}
allLogs = append(allLogs, logs...)

Expand Down
4 changes: 2 additions & 2 deletions pkg/docs/docs.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"name": "Apache 2.0",
"url": "https://github.com/tfadeyi/auth0-simple-exporter/blob/main/LICENSE"
},
"version": "0.2.0"
"version": "0.2.1"
},
"host": "localhost:8080",
"basePath": "/",
"paths": {
"/metrics": {
"get": {
"description": "# Available Metrics\n\nExposes the Auth0 metrics collected by the exporter in a prometheus format.\n\n### Signup\n| Metric | Meaning | Labels |\n|------------------------------------------|-----------------------------------------------------|--------|\n| `tenant_sign_up_operations_total` | The total number of signup operations. | client |\n| `tenant_failed_sign_up_operations_total` | The number of failed signup operations. (codes: fs) | client |\n\n### Login\n| Metric | Meaning | Labels |\n|----------------------------------------|---------------------------------------------------------|--------|\n| `tenant_login_operations_total` | The total number of login operations. | client |\n| `tenant_failed_login_operations_total` | The number of failed login operations. (codes: f,fp,fu) | client |\n\n### Logout\n| Metric | Meaning | Labels |\n|-----------------------------------------|------------------------------------------------------|--------|\n| `tenant_logout_operations_total` | The total number of logout operations. | client |\n| `tenant_failed_logout_operations_total` | The number of failed logout operations. (codes: flo) | client |\n\n### Voice call operations\n| Metric | Meaning | Labels |\n|--------------------------------------------------|---------------------------------------------------------------------|--------|\n| `tenant_send_voice_call_operations_total` | The total number of voice_call operations. | client |\n| `tenant_failed_send_voice_call_operations_total` | The number of voice_call operations. (codes: gd_send_voice_failure) | client |\n\n### SMS operations\n| Metric | Meaning | Labels |\n|-------------------------------------------|------------------------------------------------------------------------|--------|\n| `tenant_send_sms_operations_total` | The total number of successful send_sms operations. | client |\n| `tenant_failed_send_sms_operations_total` | The number of failed send_sms operations. (codes: gd_send_sms_failure) | client |\n\n### Email operations\n| Metric | Meaning | Labels |\n|--------------------------------------|----------------------------------------------------------------------------------|--------|\n| `tenant_send_email_operations_total` | The number of successful send email operations. (codes: gd_send_email) | client |\n| `tenant_change_email_total` | The total number of change_user_email operations on the tenant. (codes: sce,fce) | client |\n| `tenant_failed_change_email_total` | The number of failed change user email operations on the tenant. (codes: fce) | client |\n\n### Push notification operations\n| Metric | Meaning | Labels |\n|-----------------------------------------|------------------------------------------------------------------------------------------|--------|\n| `tenant_push_notification_total` | The total number of push_notification operations. (codes: gd_send_pn,gd_send_pn_failure) | client |\n| `tenant_failed_push_notification_total` | The number of failed push_notification operations. (codes: gd_send_pn_failure) | client |\n\n### Password operations\n| Metric | Meaning | Labels |\n|-------------------------------------------------|-------------------------------------------------------------------------------------------------|--------|\n| `tenant_post_change_password_hook_total` | The total number of post change user password hook operations on the tenant. (codes: scph,fcph) | client |\n| `tenant_failed_post_change_password_hook_total` | The number of failed post change user password hook operations on the tenant. (codes: fcph) | client |\n| `tenant_change_password_request_total` | The total number of change_password_request operations. (codes: scpr,fcpr) | client |\n| `tenant_failed_change_password_request_total` | The number of failed change password request operations. (codes: fcpr) | client |\n| `tenant_change_password_total` | The total number of change_user_password operations on the tenant. (codes: scp,fcp) | client | |\n| `tenant_failed_change_password_total` | The number of failed change_user_password operations on the tenant. (codes: fcp) | client |\n\n### Passwordless Send code link\n| Metric | Meaning | Labels |\n|-------------------------------|----------------------------------------------------------|-------------|\n| `tenant_send_code_link_total` | The number of send_code_link operations. (codes: cls,cs) | type,client |\n\n### Delete user operations\n| Metric | Meaning | Labels |\n|-----------------------------------|---------------------------------------------------------------------------|--------|\n| `tenant_delete_user_total` | The total number of delete user operations on the tenant. (codes: du,fdu) | client |\n| `tenant_failed_delete_user_total` | The number of failed delete user operations on the tenant. (codes: fdu) | client |\n\n### Change phone number operations\n| Metric | Meaning | Labels |\n|-------------------------------------------|--------------------------------------------------------------------------------------|--------|\n| `tenant_change_phone_number_total` | The total number of change_phone_number operations on the tenant. (codes: scpn,fcpn) | client |\n| `tenant_failed_change_phone_number_total` | The number of failed change phone number operations on the tenant. (codes: fcpn) | client |\n\n### API operations\n| Metric | Meaning | Labels |\n|--------------------------------------|----------------------------------------------------------------------|--------|\n| `tenant_api_operations_total` | The total number of API operations on the tenant. (codes: sapi,fapi) | client |\n| `tenant_failed_api_operations_total` | The number of failed API operations on the tenant. (codes: fapi) | client |\n",
"description": "# Available Metrics\n\nExposes the Auth0 metrics collected by the exporter in a prometheus format.\n\n### Signup\n| Metric | Meaning | Labels |\n|------------------------------------------|-----------------------------------------------------|--------|\n| `tenant_sign_up_operations_total` | The total number of signup operations. | client |\n| `tenant_failed_sign_up_operations_total` | The number of failed signup operations. (codes: fs) | client |\n\n### Login\n| Metric | Meaning | Labels |\n|----------------------------------------|---------------------------------------------------------|--------|\n| `tenant_login_operations_total` | The total number of login operations. | client |\n| `tenant_failed_login_operations_total` | The number of failed login operations. (codes: f,fp,fu) | client |\n\n### Logout\n| Metric | Meaning | Labels |\n|-----------------------------------------|------------------------------------------------------|--------|\n| `tenant_logout_operations_total` | The total number of logout operations. | client |\n| `tenant_failed_logout_operations_total` | The number of failed logout operations. (codes: flo) | client |\n\n### Voice call operations\n| Metric | Meaning | Labels |\n|--------------------------------------------------|---------------------------------------------------------------------|--------|\n| `tenant_send_voice_call_operations_total` | The total number of voice_call operations. | client |\n| `tenant_failed_send_voice_call_operations_total` | The number of voice_call operations. (codes: gd_send_voice_failure) | client |\n\n### SMS operations\n| Metric | Meaning | Labels |\n|-------------------------------------------|------------------------------------------------------------------------|--------|\n| `tenant_send_sms_operations_total` | The total number of successful send_sms operations. | client |\n| `tenant_failed_send_sms_operations_total` | The number of failed send_sms operations. (codes: gd_send_sms_failure) | client |\n\n### Email operations\n| Metric | Meaning | Labels |\n|--------------------------------------|----------------------------------------------------------------------------------|--------|\n| `tenant_send_email_operations_total` | The number of successful send email operations. (codes: gd_send_email) | client |\n| `tenant_change_email_total` | The total number of change_user_email operations on the tenant. (codes: sce,fce) | client |\n| `tenant_failed_change_email_total` | The number of failed change user email operations on the tenant. (codes: fce) | client |\n\n### Push notification operations\n| Metric | Meaning | Labels |\n|-----------------------------------------|------------------------------------------------------------------------------------------|--------|\n| `tenant_push_notification_total` | The total number of push_notification operations. (codes: gd_send_pn,gd_send_pn_failure) | client |\n| `tenant_failed_push_notification_total` | The number of failed push_notification operations. (codes: gd_send_pn_failure) | client |\n\n### Password operations\n| Metric | Meaning | Labels |\n|-------------------------------------------------|-------------------------------------------------------------------------------------------------|--------|\n| `tenant_post_change_password_hook_total` | The total number of post change user password hook operations on the tenant. (codes: scph,fcph) | client |\n| `tenant_failed_post_change_password_hook_total` | The number of failed post change user password hook operations on the tenant. (codes: fcph) | client |\n| `tenant_change_password_request_total` | The total number of change_password_request operations. (codes: scpr,fcpr) | client |\n| `tenant_failed_change_password_request_total` | The number of failed change password request operations. (codes: fcpr) | client |\n| `tenant_change_password_total` | The total number of change_user_password operations on the tenant. (codes: scp,fcp) | client | |\n| `tenant_failed_change_password_total` | The number of failed change_user_password operations on the tenant. (codes: fcp) | client |\n\n### Passwordless Send code link\n| Metric | Meaning | Labels |\n|-------------------------------|----------------------------------------------------------|-------------|\n| `tenant_send_code_link_total` | The number of send_code_link operations. (codes: cls,cs) | type,client |\n\n### Delete user operations\n| Metric | Meaning | Labels |\n|-----------------------------------|---------------------------------------------------------------------------|--------|\n| `tenant_delete_user_total` | The total number of delete user operations on the tenant. (codes: du,fdu) | client |\n| `tenant_failed_delete_user_total` | The number of failed delete user operations on the tenant. (codes: fdu) | client |\n\n### Change phone number operations\n| Metric | Meaning | Labels |\n|-------------------------------------------|--------------------------------------------------------------------------------------|--------|\n| `tenant_change_phone_number_total` | The total number of change_phone_number operations on the tenant. (codes: scpn,fcpn) | client |\n| `tenant_failed_change_phone_number_total` | The number of failed change phone number operations on the tenant. (codes: fcpn) | client |\n\n### API operations\n| Metric | Meaning | Labels |\n|--------------------------------------|----------------------------------------------------------------------|--------|\n| `tenant_api_operations_total` | The total number of API operations on the tenant. (codes: sapi,fapi) | client |\n| `tenant_failed_api_operations_total` | The number of failed API operations on the tenant. (codes: fapi) | client |\n\n\n### User statistics\n| Metric | Meaning | Labels |\n|--------------------------------------|----------------------------------------------------------------------|--------|\n| `tenant_total_monthly_active_users` | The number of monthly active users. A user is active if he/she has logged in at least once in the last 30 days | tenant |",
"produces": [
"application/json",
"text/plain; charset=utf-8"
Expand Down
10 changes: 8 additions & 2 deletions pkg/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ info:
name: Apache 2.0
url: https://github.com/tfadeyi/auth0-simple-exporter/blob/main/LICENSE
title: Auth0 simple exporter
version: 0.2.0
version: 0.2.1
paths:
/metrics:
get:
description: |
description: |-
# Available Metrics
Exposes the Auth0 metrics collected by the exporter in a prometheus format.
Expand Down Expand Up @@ -94,6 +94,12 @@ paths:
|--------------------------------------|----------------------------------------------------------------------|--------|
| `tenant_api_operations_total` | The total number of API operations on the tenant. (codes: sapi,fapi) | client |
| `tenant_failed_api_operations_total` | The number of failed API operations on the tenant. (codes: fapi) | client |
### User statistics
| Metric | Meaning | Labels |
|--------------------------------------|----------------------------------------------------------------------|--------|
| `tenant_total_monthly_active_users` | The number of monthly active users. A user is active if he/she has logged in at least once in the last 30 days | tenant |
produces:
- application/json
- text/plain; charset=utf-8
Expand Down
5 changes: 4 additions & 1 deletion pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ func (e *exporter) probe() echo.HandlerFunc {
func (e *exporter) collect(ctx context.Context, m *metrics.Metrics) error {
// Process logs
list, err := e.client.Log.List(ctx, e.startTime)
if err != nil {
switch {
case errors.Is(err, context.Canceled):
e.logger.V(0).Error(err, "Could not finish fetching all the log events, too many might be present, from Auth0 in the given request context, try adding the --auth0.from")
case err != nil:
return errors.Annotate(err, "error fetching the log events from Auth0")
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ func TestExporter(t *testing.T) {
}
require.NoError(t, e.collect(ctx, nil))
})
t.Run("successful collect exporter metrics if auth0 client returns a context canceled error", func(t *testing.T) {
ctx := context.Background()
client := client.Client{
Log: &logs.ClientMock{ListFunc: func(ctx context.Context, args ...interface{}) (interface{}, error) {
return []*management.Log{}, context.Canceled
}},
User: &users.ClientMock{ListFunc: func(ctx context.Context, args ...interface{}) (interface{}, error) {
return []*management.User{}, nil
}},
App: nil,
}
current := time.Now()
e := exporter{
startTime: current,
ctx: ctx,
client: client,
}
require.NoError(t, e.collect(ctx, nil))
})
t.Run("fail exporter collect if auth0 client didn't return a list of logs", func(t *testing.T) {
ctx := context.Background()
client := client.Client{
Expand Down
3 changes: 2 additions & 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.0
// @version 0.2.1
// @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 Expand Up @@ -60,6 +60,7 @@ func (e *exporter) Export() error {
server.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return logging.Middleware(next, log)
})
server.Use(middleware.Timeout())
server.HideBanner = true
server.HidePort = true

Expand Down

0 comments on commit db636e6

Please sign in to comment.