forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeat_test.go
More file actions
84 lines (77 loc) · 2.76 KB
/
beat_test.go
File metadata and controls
84 lines (77 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package instance
import (
"maps"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.uber.org/zap/zapcore"
"github.com/elastic/beats/v7/filebeat/cmd"
"github.com/elastic/beats/v7/filebeat/input/log"
"github.com/elastic/beats/v7/libbeat/management"
"github.com/elastic/beats/v7/x-pack/libbeat/common/otelbeat/otelmanager"
conf "github.com/elastic/elastic-agent-libs/config"
)
func TestManager(t *testing.T) {
tmpDir := t.TempDir()
cfg := map[string]any{
"filebeat": map[string]any{
"inputs": []map[string]any{
{
"type": "benchmark",
"enabled": true,
"message": "test",
"count": 10,
},
},
},
"path.home": tmpDir,
}
t.Run("otel management disabled - key missing", func(t *testing.T) {
beat, err := NewBeatForReceiver(cmd.FilebeatSettings("filebeat"), cfg, consumertest.NewNop(), "testcomponent", zapcore.NewNopCore())
assert.NoError(t, err)
assert.NotNil(t, beat.Manager)
// it should fallback to FallbackManager if key is missing
assert.IsType(t, beat.Manager, &management.FallbackManager{})
assert.False(t, management.UnderAgent())
})
t.Run("otel management enabled", func(t *testing.T) {
tmpCfg := map[string]any{}
maps.Copy(tmpCfg, cfg)
tmpCfg["management.otel.enabled"] = true
defer func() {
management.SetUnderAgent(false) // reset to false
}()
beat, err := NewBeatForReceiver(cmd.FilebeatSettings("filebeat"), tmpCfg, consumertest.NewNop(), "testcomponent", zapcore.NewNopCore())
assert.NoError(t, err)
assert.NotNil(t, beat.Manager)
assert.IsType(t, beat.Manager, &otelmanager.OtelManager{})
assert.True(t, management.UnderAgent())
// test if log input is enabled
cfg, err := conf.NewConfigFrom(`
type: "log"`)
require.NoError(t, err)
assert.True(t, log.AllowDeprecatedUse(cfg))
})
t.Run("otel management disabled", func(t *testing.T) {
tmpCfg := map[string]any{}
maps.Copy(tmpCfg, cfg)
tmpCfg["management.otel.enabled"] = false
defer func() {
management.SetUnderAgent(false) // reset to false
}()
beat, err := NewBeatForReceiver(cmd.FilebeatSettings("filebeat"), tmpCfg, consumertest.NewNop(), "testcomponent", zapcore.NewNopCore())
assert.NoError(t, err)
assert.NotNil(t, beat.Manager)
assert.IsType(t, beat.Manager, &management.FallbackManager{})
assert.False(t, management.UnderAgent())
// test if log input is disabled
cfg, err := conf.NewConfigFrom(`
type: "log"`)
require.NoError(t, err)
assert.False(t, log.AllowDeprecatedUse(cfg))
})
}