Skip to content

Commit

Permalink
[exporter/loki] Add Config QueueSettings validation (#16855)
Browse files Browse the repository at this point in the history
Description: Added QueueStettings validation into Config Validate method
Link to tracking Issue: #7841
  • Loading branch information
mar4uk authored Jan 17, 2023
1 parent b214a4e commit 3f56ff9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .chloggen/lokiexporter-add-queue-settings-validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: lokiexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added QueueSettings validation into Config Validate method

# One or more tracking issues related to the change
issues: [7841]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
4 changes: 4 additions & 0 deletions exporter/lokiexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type Config struct {
}

func (c *Config) Validate() error {
if err := c.QueueSettings.Validate(); err != nil {
return fmt.Errorf("queue settings has invalid configuration: %w", err)
}

if _, err := url.Parse(c.Endpoint); c.Endpoint == "" || err != nil {
return fmt.Errorf("\"endpoint\" must be a valid URL")
}
Expand Down
41 changes: 41 additions & 0 deletions exporter/lokiexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package lokiexporter

import (
"fmt"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -164,3 +165,43 @@ func TestIsLegacy(t *testing.T) {
func stringp(str string) *string {
return &str
}

func TestConfigValidate(t *testing.T) {
testCases := []struct {
desc string
cfg *Config
err error
}{
{
desc: "QueueSettings are invalid",
cfg: &Config{QueueSettings: exporterhelper.QueueSettings{QueueSize: -1, Enabled: true}},
err: fmt.Errorf("queue settings has invalid configuration"),
},
{
desc: "Endpoint is invalid",
cfg: &Config{},
err: fmt.Errorf("\"endpoint\" must be a valid URL"),
},
{
desc: "Config is valid",
cfg: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "https://loki.example.com",
},
},
err: nil,
},
}

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
err := tc.cfg.Validate()
if tc.err != nil {
require.Error(t, err)
assert.Contains(t, err.Error(), tc.err.Error())
} else {
require.NoError(t, err)
}
})
}
}

0 comments on commit 3f56ff9

Please sign in to comment.