Skip to content

Commit 6160592

Browse files
[samples] remove unneeded file_storage and fix a bug (#10856)
* fix: add flush_interval * couple of enhancements * test samples * lint * use observer and t.Setenv * lint * fix profiling * fix unit test race * more time * comment * enable profiling for linux * Add comment * use DryRun to validate the config --------- Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]>
1 parent 926e5f9 commit 6160592

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

internal/pkg/otel/samples/windows/logs_metrics_traces.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ receivers:
3636
grpc:
3737
http:
3838

39-
extensions:
40-
file_storage:
41-
directory: ${env:STORAGE_DIR}
42-
4339
connectors:
4440
elasticapm:
4541

@@ -85,7 +81,6 @@ exporters:
8581
mode: otel
8682

8783
service:
88-
extensions: [file_storage]
8984
pipelines:
9085
traces/fromsdk:
9186
receivers: [otlp/fromsdk]

internal/pkg/otel/samples/windows/managed_otlp/logs_metrics_traces.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ receivers:
3535
grpc:
3636
http:
3737

38-
extensions:
39-
file_storage:
40-
directory: ${env:STORAGE_DIR}
41-
4238
processors:
4339
resourcedetection:
4440
detectors: ["system"]
@@ -101,7 +97,6 @@ exporters:
10197
max_size: 4_000_000 # 4MB uncompressed
10298

10399
service:
104-
extensions: [file_storage]
105100
pipelines:
106101
traces/fromsdk:
107102
receivers: [otlp/fromsdk]

internal/pkg/otel/samples_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
package otel
6+
7+
import (
8+
"os"
9+
"path/filepath"
10+
"runtime"
11+
"testing"
12+
13+
"github.com/stretchr/testify/assert"
14+
"go.opentelemetry.io/collector/featuregate"
15+
"go.opentelemetry.io/collector/otelcol"
16+
"go.uber.org/zap"
17+
"go.uber.org/zap/zapcore"
18+
)
19+
20+
func TestSamples(t *testing.T) {
21+
// Set environment variables required by the sample configurations.
22+
// These are just sample values to allow the collector to start.
23+
t.Setenv("STORAGE_DIR", t.TempDir())
24+
t.Setenv("ELASTIC_ENDPOINT", "http://localhost:9200")
25+
t.Setenv("ELASTIC_API_KEY", "test_api_key")
26+
t.Setenv("ELASTIC_OTLP_ENDPOINT", "http://localhost:4318")
27+
t.Setenv("AUTOOPS_ES_URL", "http://localhost:9200")
28+
t.Setenv("AUTOOPS_TOKEN", "token")
29+
t.Setenv("AUTOOPS_TEMP_RESOURCE_ID", "temp")
30+
t.Setenv("AUTOOPS_OTEL_URL", "http://localhost:4318")
31+
32+
// Enable service.profilesSupport featuregate to test the profiling samples.
33+
assert.NoError(t, featuregate.GlobalRegistry().Set("service.profilesSupport", true))
34+
defer func() {
35+
assert.NoError(t, featuregate.GlobalRegistry().Set("service.profilesSupport", false))
36+
}()
37+
38+
err := filepath.WalkDir(filepath.Join(".", "samples", runtime.GOOS), func(path string, d os.DirEntry, err error) error {
39+
if err != nil {
40+
return err
41+
}
42+
if !d.IsDir() && (filepath.Ext(d.Name()) == ".yaml" || filepath.Ext(d.Name()) == ".yml") {
43+
t.Run(d.Name(), func(t *testing.T) {
44+
testSample(t, filepath.Join(".", "samples", runtime.GOOS, d.Name()))
45+
})
46+
}
47+
return nil
48+
})
49+
assert.NoError(t, err)
50+
}
51+
52+
func testSample(t *testing.T, configFile string) {
53+
settings := NewSettings("test", []string{configFile})
54+
settings.LoggingOptions = []zap.Option{zap.WrapCore(func(zapcore.Core) zapcore.Core {
55+
// TODO: Replace with observer core. Right now, it results in a race condition.
56+
return zapcore.NewNopCore()
57+
})}
58+
collector, err := otelcol.NewCollector(*settings)
59+
assert.NoError(t, err)
60+
assert.NotNil(t, collector)
61+
assert.NoError(t, collector.DryRun(t.Context()))
62+
collector.Shutdown()
63+
}

0 commit comments

Comments
 (0)