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

[Prometheus Remote Write Exporter for Cortex] Add Enhancements and Fixes #326

Merged
merged 18 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions exporters/metric/cortex/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ var (
// ErrNoBasicAuthPassword occurs when no password or password file was provided for
// basic authentication.
ErrNoBasicAuthPassword = fmt.Errorf("no password or password file provided for basic authentication")

// ErrInvalidQuantiles occurs when the supplied quantiles are not between 0 and 1.
ErrInvalidQuantiles = fmt.Errorf("cannot have quantiles that are less than 0 or greater than 1")
)

// Config contains properties the Exporter uses to export metrics data to Cortex.
Expand Down Expand Up @@ -86,6 +89,15 @@ func (c *Config) Validate() error {
return ErrTwoBearerTokens
}

// Verify that provided quantiles are between 0 and 1.
if c.Quantiles != nil {
for _, quantile := range c.Quantiles {
if quantile < 0 || quantile > 1 {
return ErrInvalidQuantiles
}
}
}

// Add default values for missing properties.
if c.Endpoint == "" {
c.Endpoint = "/api/prom/push"
Expand All @@ -97,6 +109,9 @@ func (c *Config) Validate() error {
if c.PushInterval == 0 {
c.PushInterval = 10 * time.Second
}
if c.Quantiles == nil {
c.Quantiles = []float64{0.5, 0.9, 0.95, 0.99}
}

return nil
}
34 changes: 32 additions & 2 deletions exporters/metric/cortex/config_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var validatedStandardConfig = cortex.Config{
Name: "Config",
RemoteTimeout: 30 * time.Second,
PushInterval: 10 * time.Second,
Quantiles: []float64{0.5, 0.9, 0.95, 0.99},
}

// Config struct with default values other than the remote timeout. This is used to verify
Expand All @@ -35,6 +36,17 @@ var validatedCustomTimeoutConfig = cortex.Config{
Name: "Config",
RemoteTimeout: 10 * time.Second,
PushInterval: 10 * time.Second,
Quantiles: []float64{0.5, 0.9, 0.95, 0.99},
}

// Config struct with default values other than the quantiles. This is used to verify
// the output of Validate().
var validatedQuantilesConfig = cortex.Config{
Endpoint: "/api/prom/push",
Name: "Config",
RemoteTimeout: 30 * time.Second,
PushInterval: 10 * time.Second,
Quantiles: []float64{0, 0.5, 1},
}

// Example Config struct with a custom remote timeout.
Expand Down Expand Up @@ -110,7 +122,7 @@ var exampleTwoAuthConfig = cortex.Config{
BearerToken: "bearer_token",
}

// Example Config struct with no password for basic authentication
// Example Config struct with no password for basic authentication.
var exampleNoPasswordConfig = cortex.Config{
Endpoint: "/api/prom/push",
Name: "Config",
Expand All @@ -121,7 +133,7 @@ var exampleNoPasswordConfig = cortex.Config{
},
}

// Example Config struct with no password for basic authentication
// Example Config struct with no password for basic authentication.
var exampleNoUsernameConfig = cortex.Config{
Endpoint: "/api/prom/push",
Name: "Config",
Expand All @@ -131,3 +143,21 @@ var exampleNoUsernameConfig = cortex.Config{
"password": "password",
},
}

// Example Config struct with invalid quantiles.
var exampleInvalidQuantilesConfig = cortex.Config{
Endpoint: "/api/prom/push",
Name: "Config",
RemoteTimeout: 30 * time.Second,
PushInterval: 10 * time.Second,
Quantiles: []float64{0, 1, 2, 3},
}

// Example Config struct with valid quantiles.
var exampleValidQuantilesConfig = cortex.Config{
Endpoint: "/api/prom/push",
Name: "Config",
RemoteTimeout: 30 * time.Second,
PushInterval: 10 * time.Second,
Quantiles: []float64{0, 0.5, 1},
}
12 changes: 12 additions & 0 deletions exporters/metric/cortex/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ func TestValidate(t *testing.T) {
expectedConfig: nil,
expectedError: cortex.ErrConflictingAuthorization,
},
{
testName: "Config with Invalid Quantiles",
config: &exampleInvalidQuantilesConfig,
expectedConfig: nil,
expectedError: cortex.ErrInvalidQuantiles,
},
{
testName: "Config with Valid Quantiles",
config: &exampleValidQuantilesConfig,
expectedConfig: &validatedQuantilesConfig,
expectedError: nil,
},
}
for _, test := range tests {
t.Run(test.testName, func(t *testing.T) {
Expand Down
Loading