Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/integrations/install/install_test.go
5304 views
1
package install
2
3
import (
4
"fmt"
5
"strings"
6
"testing"
7
8
v1 "github.com/grafana/agent/pkg/integrations"
9
v2 "github.com/grafana/agent/pkg/integrations/v2"
10
"github.com/stretchr/testify/require"
11
)
12
13
// TestV1_Shims ensures that every v1 integration has a v2 counterpart.
14
func TestV1_Shims(t *testing.T) {
15
var (
16
v2Integrations = make(map[string]v2.Config) // Native v2 integrations
17
shimmedIntegrations = make(map[string]v1.Config) // Shimmed v1 integrations
18
)
19
20
for _, v2Integration := range v2.Registered() {
21
uc, ok := v2Integration.(v2.UpgradedConfig)
22
if !ok {
23
v2Integrations[v2Integration.Name()] = v2Integration
24
continue
25
}
26
27
v1Integration, _ := uc.LegacyConfig()
28
shimmedIntegrations[v1Integration.Name()] = v1Integration
29
}
30
31
for _, v1Integration := range v1.RegisteredIntegrations() {
32
t.Run(v1Integration.Name(), func(t *testing.T) {
33
_, v2Native := v2Integrations[v1Integration.Name()]
34
_, shimmed := shimmedIntegrations[v1Integration.Name()]
35
require.True(t, shimmed || v2Native, "integration not shimmed to v2 or does not have a native counterpart")
36
})
37
}
38
}
39
40
// TestV2_NoExporterSuffix ensures that v2 integrations do not have a name
41
// ending in _exporter. The test may be updated to exclude specific
42
// integrations from this requirement.
43
func TestV2_NoExporterSuffix(t *testing.T) {
44
exceptions := map[string]struct{}{
45
"node_exporter": {}, // node_exporter is an exception because its name is well-understood
46
}
47
48
var invalidNames []string
49
50
for _, v2Integration := range v2.Registered() {
51
name := v2Integration.Name()
52
if _, excluded := exceptions[name]; excluded {
53
continue
54
}
55
56
if strings.HasSuffix(name, "_exporter") {
57
invalidNames = append(invalidNames, name)
58
}
59
}
60
61
if len(invalidNames) > 0 {
62
require.FailNow(
63
t,
64
"Found v2 integrations named with unexpected _exporter suffix",
65
fmt.Sprintf("The following integrations must not end in _exporter: %s. Either drop the suffix or add them as an exception in this test.", strings.Join(invalidNames, ", ")),
66
)
67
}
68
}
69
70