forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
includeconfigsource: add tests for watch file and template files (ope…
…n-telemetry#1972) * fix templating and add tests for watch file and template files * add integration test for templated configs * rename test file * Update tests/general/include_config_source_test.go Co-authored-by: Ryan Fitzpatrick <rmfitzpatrick@users.noreply.github.com> * call cancel in subprocess shutdown Co-authored-by: Ryan Fitzpatrick <rmfitzpatrick@users.noreply.github.com>
- Loading branch information
1 parent
8375ec0
commit 070dbe7
Showing
9 changed files
with
236 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
internal/configsource/includeconfigsource/testdata/param_template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
logs_path: {{ .glob_pattern }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"path" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/confmap" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zaptest/observer" | ||
"gopkg.in/yaml.v2" | ||
|
||
"github.com/signalfx/splunk-otel-collector/tests/testutils" | ||
) | ||
|
||
func TestCollectorProcessWithMultipleTemplateConfigs(t *testing.T) { | ||
logCore, logs := observer.New(zap.DebugLevel) | ||
logger := zap.New(logCore) | ||
collector, err := testutils.NewCollectorProcess(). | ||
WithArgs("--config", path.Join(".", "testdata", "templated.yaml")). | ||
WithLogger(logger). | ||
Build() | ||
|
||
require.NotNil(t, collector) | ||
require.NoError(t, err) | ||
|
||
err = collector.Start() | ||
require.NoError(t, err) | ||
|
||
require.Eventually(t, func() bool { | ||
for _, log := range logs.All() { | ||
if strings.Contains(log.Message, | ||
`Set config to [testdata/templated.yaml]`, | ||
) { | ||
return true | ||
} | ||
} | ||
return false | ||
}, 20*time.Second, time.Second) | ||
|
||
require.Eventually(t, func() bool { | ||
for _, log := range logs.All() { | ||
// Confirm collector starts and runs successfully | ||
if strings.Contains(log.Message, "Everything is ready. Begin running and processing data.") { | ||
return true | ||
} | ||
} | ||
return false | ||
}, 20*time.Second, time.Second) | ||
|
||
expectedConfig := map[string]any{ | ||
"receivers": map[string]any{ | ||
"hostmetrics": map[string]any{ | ||
"collection_interval": "10s", | ||
"scrapers": map[string]any{ | ||
"cpu": nil, | ||
"disk": nil, | ||
"filesystem": nil, | ||
"memory": nil, | ||
"network": nil, | ||
}, | ||
}, | ||
}, | ||
"processors": map[string]any{ | ||
"resourcedetection": map[string]any{ | ||
"detectors": []any{"system"}, | ||
}, | ||
}, | ||
"exporters": map[string]any{ | ||
"otlp": map[string]any{ | ||
"endpoint": "localhost:23456", | ||
"tls": map[string]any{ | ||
"insecure": true, | ||
}, | ||
}, | ||
}, | ||
"service": map[string]any{ | ||
"pipelines": map[string]any{ | ||
"metrics": map[string]any{ | ||
"processors": []any{"resourcedetection"}, | ||
"receivers": []any{"hostmetrics"}, | ||
"exporters": []any{"otlp"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tc := range []struct { | ||
expected map[string]any | ||
endpoint string | ||
}{ | ||
{expected: expectedConfig, endpoint: "effective"}, | ||
} { | ||
resp, err := http.Get(fmt.Sprintf("http://localhost:55554/debug/configz/%s", tc.endpoint)) | ||
require.NoError(t, err) | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
|
||
actual := map[string]any{} | ||
require.NoError(t, yaml.Unmarshal(body, &actual)) | ||
|
||
require.Equal(t, tc.expected, confmap.NewFromStringMap(actual).ToStringMap()) | ||
} | ||
|
||
require.NoError(t, collector.Shutdown()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
10s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
endpoint: localhost:23456 | ||
tls: | ||
insecure: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pipelines: | ||
metrics: | ||
receivers: {{ .my_receivers }} | ||
processors: {{ .my_processors }} | ||
exporters: {{ .my_exporters }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
config_sources: | ||
include: | ||
|
||
receivers: | ||
hostmetrics: | ||
scrapers: | ||
filesystem: | ||
memory: | ||
network: | ||
cpu: | ||
disk: | ||
collection_interval: ${include:./testdata/collection_interval_scalar} | ||
processors: | ||
resourcedetection: | ||
detectors: [ system ] | ||
exporters: | ||
otlp: ${include:./testdata/exporter_component} | ||
service: | | ||
$include: ./testdata/service_template_component | ||
my_receivers: [ hostmetrics ] | ||
my_processors: [ resourcedetection ] | ||
my_exporters: [ otlp ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters