Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cortex] Add support for histogram and distribution #237

Merged
merged 12 commits into from
Aug 18, 2020
Merged
60 changes: 37 additions & 23 deletions exporters/metric/cortex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Remote Write API.

## Setting up an Exporter

Users can setup the Exporter with the `InstallNewPipeline` function. It requires a
`Config` struct and returns a push Controller that will periodically collect and push
data.
Users can setup the Exporter with the `InstallNewPipeline` function. It requires a `Config` struct
and returns a push Controller that will periodically collect and push data.

Example:

```go
pusher, err := cortex.InstallNewPipeline(config)
if err != nil {
Expand All @@ -21,15 +21,15 @@ if err != nil {

## Configuration

The Exporter needs certain information, such as the endpoint URL and push interval
duration, to function properly. This information is stored in a `Config` struct, which is
passed into the Exporter during the setup pipeline.
The Exporter needs certain information, such as the endpoint URL and push interval duration, to
function properly. This information is stored in a `Config` struct, which is passed into the
Exporter during the setup pipeline.

### Creating the Config struct

Users can either create the struct manually or use a `utils` submodule in the package to
read settings from a YAML file into a new Config struct using `Viper`. Here are the
supported YAML properties as well as the Config struct that they map to.
Users can either create the struct manually or use a `utils` submodule in the package to read
settings from a YAML file into a new Config struct using [Viper](https://github.com/spf13/viper).
Here are the supported YAML properties as well as the Config struct that they map to.

```yaml
# The URL of the endpoint to send samples to.
Expand Down Expand Up @@ -61,35 +61,49 @@ basic_auth:
tls_config:
# CA certificate to validate API server certificate with.
[ ca_file: <filename>]

# Certificate and key files for client cert authentication to the server.
[ cert_file: <filename> ]
[ key_file: <filename> ]

# ServerName extension to indicate the name of the server.
# https://tools.ietf.org/html/rfc4366#section-3.1
[ server_name: <string> ]

# Disable validation of the server certificate.
[ insecure_skip_verify: <boolean> ]

# Optional proxy URL.
[ proxy_url: <string>]

# Quantiles for Distribution aggregations
[ quantiles: ]
- <string>
- <string>
- ...

# Histogram Buckets
[ histogram_buckets: ]
- <string>
- <string>
- ...
```

```go
type Config struct {
Endpoint string `mapstructure:"url"`
RemoteTimeout time.Duration `mapstructure:"remote_timeout"`
Name string `mapstructure:"name"`
BasicAuth map[string]string `mapstructure:"basic_auth"`
BearerToken string `mapstructure:"bearer_token"`
BearerTokenFile string `mapstructure:"bearer_token_file"`
TLSConfig map[string]string `mapstructure:"tls_config"`
ProxyURL string `mapstructure:"proxy_url"`
PushInterval time.Duration `mapstructure:"push_interval"`
Headers map[string]string `mapstructure:"headers"`
Client *http.Client
Endpoint string `mapstructure:"url"`
RemoteTimeout time.Duration `mapstructure:"remote_timeout"`
Name string `mapstructure:"name"`
BasicAuth map[string]string `mapstructure:"basic_auth"`
BearerToken string `mapstructure:"bearer_token"`
BearerTokenFile string `mapstructure:"bearer_token_file"`
TLSConfig map[string]string `mapstructure:"tls_config"`
ProxyURL string `mapstructure:"proxy_url"`
PushInterval time.Duration `mapstructure:"push_interval"`
Quantiles []float64 `mapstructure:"quantiles"`
HistogramBoundaries []float64 `mapstructure:"histogram_boundaries"`
Headers map[string]string `mapstructure:"headers"`
Client *http.Client
}
```

Expand Down
24 changes: 13 additions & 11 deletions exporters/metric/cortex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ var (

// Config contains properties the Exporter uses to export metrics data to Cortex.
type Config struct {
Endpoint string `mapstructure:"url"`
RemoteTimeout time.Duration `mapstructure:"remote_timeout"`
Name string `mapstructure:"name"`
BasicAuth map[string]string `mapstructure:"basic_auth"`
BearerToken string `mapstructure:"bearer_token"`
BearerTokenFile string `mapstructure:"bearer_token_file"`
TLSConfig map[string]string `mapstructure:"tls_config"`
ProxyURL string `mapstructure:"proxy_url"`
PushInterval time.Duration `mapstructure:"push_interval"`
Headers map[string]string `mapstructure:"headers"`
Client *http.Client
Endpoint string `mapstructure:"url"`
RemoteTimeout time.Duration `mapstructure:"remote_timeout"`
Name string `mapstructure:"name"`
BasicAuth map[string]string `mapstructure:"basic_auth"`
BearerToken string `mapstructure:"bearer_token"`
BearerTokenFile string `mapstructure:"bearer_token_file"`
TLSConfig map[string]string `mapstructure:"tls_config"`
ProxyURL string `mapstructure:"proxy_url"`
PushInterval time.Duration `mapstructure:"push_interval"`
Quantiles []float64 `mapstructure:"quantiles"`
HistogramBoundaries []float64 `mapstructure:"histogram_boundaries"`
Headers map[string]string `mapstructure:"headers"`
Client *http.Client
}

// Validate checks a Config struct for missing required properties and property conflicts.
Expand Down
Loading