diff --git a/app/vmauth/README.md b/app/vmauth/README.md index fdbe3e933b..45075adb91 100644 --- a/app/vmauth/README.md +++ b/app/vmauth/README.md @@ -147,6 +147,14 @@ It is recommended protecting `/-/reload` endpoint with `-reloadAuthKey` command- `vmauth` exports various metrics in Prometheus exposition format at `http://vmauth-host:8427/metrics` page. It is recommended setting up regular scraping of this page either via [vmagent](https://docs.victoriametrics.com/vmagent.html) or via Prometheus, so the exported metrics could be analyzed later. +`vmauth` exports `vmauth_user_requests_total` metric with `username` label. The `username` label value equals to `username` field value set in the `-auth.config` file. It is possible to override or hide the value in the label by specifying `name` field. For example, the following config will result in `vmauth_user_requests_total{username="foobar"}` instead of `vmauth_user_requests_total{username="secret_user"}`: + +```yml +users: +- username: "secret_user" + name: "foobar" + # other config options here +``` ## How to build from sources diff --git a/app/vmauth/auth_config.go b/app/vmauth/auth_config.go index 3deb8a67c1..f3b36278bd 100644 --- a/app/vmauth/auth_config.go +++ b/app/vmauth/auth_config.go @@ -32,6 +32,7 @@ type AuthConfig struct { // UserInfo is user information read from authConfigPath type UserInfo struct { + Name string `yaml:"name,omitempty"` BearerToken string `yaml:"bearer_token,omitempty"` Username string `yaml:"username,omitempty"` Password string `yaml:"password,omitempty"` @@ -299,14 +300,22 @@ func parseAuthConfig(data []byte) (map[string]*UserInfo, error) { return nil, fmt.Errorf("missing `url_prefix`") } if ui.BearerToken != "" { + name := "bearer_token" + if ui.Name != "" { + name = ui.Name + } if ui.Password != "" { return nil, fmt.Errorf("password shouldn't be set for bearer_token %q", ui.BearerToken) } - ui.requests = metrics.GetOrCreateCounter(`vmauth_user_requests_total{username="bearer_token"}`) + ui.requests = metrics.GetOrCreateCounter(fmt.Sprintf(`vmauth_user_requests_total{username=%q}`, name)) byBearerToken[ui.BearerToken] = true } if ui.Username != "" { - ui.requests = metrics.GetOrCreateCounter(fmt.Sprintf(`vmauth_user_requests_total{username=%q}`, ui.Username)) + name := ui.Username + if ui.Name != "" { + name = ui.Name + } + ui.requests = metrics.GetOrCreateCounter(fmt.Sprintf(`vmauth_user_requests_total{username=%q}`, name)) byUsername[ui.Username] = true } byAuthToken[authToken] = ui diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 00ea6351e0..f574d03d49 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,6 +6,8 @@ sort: 15 ## tip +* FEATURE: vmauth: allow using optional `name` field in configs. This field is then used as `username` label value for `vmauth_user_requests_total` metric. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1805). + * BUGFIX: vmstorage [enterprise](https://victoriametrics.com/enterprise.html): added missing `vm_tenant_used_tenant_bytes` metric, which shows the approximate per-tenant disk usage. See [these docs](https://docs.victoriametrics.com/PerTenantStatistic.html) and [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1605). * BUGFIX: vmauth: properly take into account the value passed to `-maxIdleConnsPerBackend` command-line flag. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1300). * BUGFIX: vmagent: fix [reading data from Kafka](https://docs.victoriametrics.com/vmagent.html#reading-metrics-from-kafka). diff --git a/docs/vmauth.md b/docs/vmauth.md index 1698942bbe..827e678e90 100644 --- a/docs/vmauth.md +++ b/docs/vmauth.md @@ -151,6 +151,14 @@ It is recommended protecting `/-/reload` endpoint with `-reloadAuthKey` command- `vmauth` exports various metrics in Prometheus exposition format at `http://vmauth-host:8427/metrics` page. It is recommended setting up regular scraping of this page either via [vmagent](https://docs.victoriametrics.com/vmagent.html) or via Prometheus, so the exported metrics could be analyzed later. +`vmauth` exports `vmauth_user_requests_total` metric with `username` label. The `username` label value equals to `username` field value set in the `-auth.config` file. It is possible to override or hide the value in the label by specifying `name` field. For example, the following config will result in `vmauth_user_requests_total{username="foobar"}` instead of `vmauth_user_requests_total{username="secret_user"}`: + +```yml +users: +- username: "secret_user" + name: "foobar" + # other config options here +``` ## How to build from sources