Skip to content

Commit 8b6735c

Browse files
committed
add agent and direct e2e tests
1 parent 8794a87 commit 8b6735c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+500
-174
lines changed

internal/manifest/objects_test.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"path/filepath"
66
"testing"
77

8+
"github.com/goccy/go-yaml"
89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
1011

@@ -21,9 +22,23 @@ func TestMain(m *testing.M) {
2122

2223
func TestObjectExamples(t *testing.T) {
2324
moduleRoot := pathutils.FindModuleRoot()
24-
objects, err := sdk.ReadObjects(context.Background(), filepath.Join(moduleRoot, "manifest/**/example*.yaml"))
25+
objects, err := sdk.ReadObjects(context.Background(),
26+
filepath.Join(moduleRoot, "manifest/**/example*.yaml"),
27+
filepath.Join(moduleRoot, "manifest/**/examples/*.yaml"),
28+
)
2529
require.NoError(t, err)
26-
assert.Greater(t, len(objects), 0, "no object examples found")
27-
errs := manifest.Validate(objects)
28-
assert.Empty(t, errs)
30+
assert.NotEmpty(t, objects, "no object examples found")
31+
for i := range objects {
32+
err = objects[i].Validate()
33+
require.NoError(t, err)
34+
// Make sure YAML and JSON are interoperable.
35+
yamlData, err := yaml.Marshal(objects[i])
36+
require.NoError(t, err)
37+
jsonData, err := yaml.YAMLToJSON(yamlData)
38+
assert.NoError(t, err)
39+
object, err := sdk.DecodeObject[manifest.Object](jsonData)
40+
assert.NoError(t, err)
41+
err = object.Validate()
42+
require.NoError(t, err)
43+
}
2944
}

internal/manifest/v1alpha/examples/agent.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1alphaExamples
22

33
import (
44
"fmt"
5+
"slices"
56

67
"github.com/nobl9/nobl9-go/manifest"
78
"github.com/nobl9/nobl9-go/manifest/v1alpha"
@@ -14,6 +15,10 @@ type agentExample struct {
1415
typ v1alpha.DataSourceType
1516
}
1617

18+
func (a agentExample) GetDataSourceType() v1alpha.DataSourceType {
19+
return a.typ
20+
}
21+
1722
func Agent() []Example {
1823
types := v1alpha.DataSourceTypeValues()
1924
examples := make([]Example, 0, len(types))
@@ -30,6 +35,14 @@ func Agent() []Example {
3035
return examples
3136
}
3237

38+
var betaChannelAgents = []v1alpha.DataSourceType{
39+
v1alpha.AzureMonitor,
40+
v1alpha.Honeycomb,
41+
v1alpha.LogicMonitor,
42+
v1alpha.AzurePrometheus,
43+
v1alpha.GCM,
44+
}
45+
3346
func (a agentExample) Generate() v1alphaAgent.Agent {
3447
titleName := dataSourceTypePrettyName(a.typ)
3548
agent := v1alphaAgent.New(
@@ -39,8 +52,7 @@ func (a agentExample) Generate() v1alphaAgent.Agent {
3952
Project: sdk.DefaultProject,
4053
},
4154
v1alphaAgent.Spec{
42-
Description: fmt.Sprintf("Example %s Agent", titleName),
43-
ReleaseChannel: v1alpha.ReleaseChannelStable,
55+
Description: fmt.Sprintf("Example %s Agent", titleName),
4456
},
4557
)
4658
agent = a.generateVariant(agent)
@@ -61,6 +73,11 @@ func (a agentExample) Generate() v1alphaAgent.Agent {
6173
Unit: defaultQueryDelay.Unit,
6274
},
6375
}
76+
if slices.Contains(betaChannelAgents, typ) {
77+
agent.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
78+
} else {
79+
agent.Spec.ReleaseChannel = v1alpha.ReleaseChannelStable
80+
}
6481
return agent
6582
}
6683

internal/manifest/v1alpha/examples/alert_method.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ var customAlertMethodsSubVariants = map[v1alpha.AlertMethodType][]alertMethodSpe
3636

3737
type alertMethodExample struct {
3838
standardExample
39-
methodType v1alpha.AlertMethodType
39+
typ v1alpha.AlertMethodType
40+
}
41+
42+
func (a alertMethodExample) GetAlertMethodType() v1alpha.AlertMethodType {
43+
return a.typ
4044
}
4145

4246
func (a alertMethodExample) GetYAMLComments() []string {
@@ -54,7 +58,7 @@ func AlertMethod() []Example {
5458
standardExample: standardExample{
5559
Variant: typ.String(),
5660
},
57-
methodType: typ,
61+
typ: typ,
5862
})
5963
}
6064
for typ, subVariants := range customAlertMethodsSubVariants {
@@ -64,7 +68,7 @@ func AlertMethod() []Example {
6468
Variant: typ.String(),
6569
SubVariant: subVariant,
6670
},
67-
methodType: typ,
71+
typ: typ,
6872
})
6973
}
7074
}
@@ -89,7 +93,7 @@ func (a alertMethodExample) Generate() v1alphaAlertMethod.AlertMethod {
8993
}
9094

9195
func (a alertMethodExample) generateVariant(am v1alphaAlertMethod.AlertMethod) v1alphaAlertMethod.AlertMethod {
92-
switch a.methodType {
96+
switch a.typ {
9397
case v1alpha.AlertMethodTypeEmail:
9498
am.Spec.Email = &v1alphaAlertMethod.EmailAlertMethod{
9599
To: []string{"[email protected]"},

internal/manifest/v1alpha/examples/alert_method_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestAlertMethod_SupportsAllAlertMethodTypes(t *testing.T) {
1111
variants := AlertMethod()
1212
for _, methodType := range v1alpha.AlertMethodTypeValues() {
1313
if !slices.ContainsFunc(variants, func(e Example) bool {
14-
return e.(alertMethodExample).methodType == methodType
14+
return e.(alertMethodExample).typ == methodType
1515
}) {
1616
t.Errorf("%T '%s' is not listed in the examples", methodType, methodType)
1717
}

internal/manifest/v1alpha/examples/direct.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1alphaExamples
22

33
import (
44
"fmt"
5+
"slices"
56

67
"github.com/nobl9/nobl9-go/manifest"
78
"github.com/nobl9/nobl9-go/manifest/v1alpha"
@@ -14,6 +15,10 @@ type directExample struct {
1415
typ v1alpha.DataSourceType
1516
}
1617

18+
func (d directExample) GetDataSourceType() v1alpha.DataSourceType {
19+
return d.typ
20+
}
21+
1722
func Direct() []Example {
1823
types := v1alpha.DataSourceTypeValues()
1924
examples := make([]Example, 0, len(types))
@@ -33,6 +38,13 @@ func Direct() []Example {
3338
return examples
3439
}
3540

41+
var betaChannelDirects = []v1alpha.DataSourceType{
42+
v1alpha.AzureMonitor,
43+
v1alpha.Honeycomb,
44+
v1alpha.LogicMonitor,
45+
v1alpha.GoogleCloudMonitoring,
46+
}
47+
3648
func (d directExample) Generate() v1alphaDirect.Direct {
3749
titleName := dataSourceTypePrettyName(d.typ)
3850
direct := v1alphaDirect.New(
@@ -64,6 +76,11 @@ func (d directExample) Generate() v1alphaDirect.Direct {
6476
Unit: defaultQueryDelay.Unit,
6577
},
6678
}
79+
if slices.Contains(betaChannelDirects, typ) {
80+
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
81+
} else {
82+
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelStable
83+
}
6784
return direct
6885
}
6986

@@ -77,6 +94,7 @@ func (d directExample) generateVariant(direct v1alphaDirect.Direct) v1alphaDirec
7794
ClientSecret: "[secret]",
7895
}
7996
case v1alpha.AzureMonitor:
97+
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
8098
direct.Spec.AzureMonitor = &v1alphaDirect.AzureMonitorConfig{
8199
TenantID: "5cdecca3-c2c5-4072-89dd-5555faf05202",
82100
ClientID: "70747025-9367-41a5-98f1-59b18b5793c3",
@@ -106,6 +124,7 @@ func (d directExample) generateVariant(direct v1alphaDirect.Direct) v1alphaDirec
106124
ServiceAccountKey: gcloudServiceAccountKey,
107125
}
108126
case v1alpha.Honeycomb:
127+
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
109128
direct.Spec.Honeycomb = &v1alphaDirect.HoneycombConfig{
110129
APIKey: "[secret]",
111130
}
@@ -144,10 +163,8 @@ func (d directExample) generateVariant(direct v1alphaDirect.Direct) v1alphaDirec
144163
}
145164
case v1alpha.Redshift:
146165
direct.Spec.Redshift = &v1alphaDirect.RedshiftConfig{
147-
AccessKeyID: "AKIA4NPYKXO34R341XUX",
148-
SecretAccessKey: "[secret]",
149-
SecretARN: "arn:aws:secretsmanager:eu-central-1:123456578901:secret:prod-redshift-db-user",
150-
RoleARN: "arn:aws:iam::123456578901:role/awsCrossAccountProdRedshift-prod-app",
166+
SecretARN: "arn:aws:secretsmanager:eu-central-1:123456578901:secret:prod-redshift-db-user",
167+
RoleARN: "arn:aws:iam::123456578901:role/awsCrossAccountProdRedshift-prod-app",
151168
}
152169
case v1alpha.Splunk:
153170
direct.Spec.Splunk = &v1alphaDirect.SplunkConfig{

manifest/v1alpha/agent/examples/amazon-prometheus.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ spec:
1818
value: 15
1919
unit: Day
2020
queryDelay:
21-
duration:
22-
value: 1
23-
unit: Second
21+
value: 1
22+
unit: Second

manifest/v1alpha/agent/examples/app-dynamics.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ spec:
1717
value: 15
1818
unit: Day
1919
queryDelay:
20-
duration:
21-
value: 2
22-
unit: Minute
20+
value: 2
21+
unit: Minute

manifest/v1alpha/agent/examples/azure-monitor.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
project: default
77
spec:
88
description: Example Azure Monitor Agent
9-
releaseChannel: stable
9+
releaseChannel: beta
1010
azureMonitor:
1111
tenantId: 5cdecca3-c2c5-4072-89dd-5555faf05202
1212
historicalDataRetrieval:
@@ -17,6 +17,5 @@ spec:
1717
value: 15
1818
unit: Day
1919
queryDelay:
20-
duration:
21-
value: 6
22-
unit: Minute
20+
value: 6
21+
unit: Minute

manifest/v1alpha/agent/examples/azure-prometheus.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
project: default
77
spec:
88
description: Example Azure Prometheus Agent
9-
releaseChannel: stable
9+
releaseChannel: beta
1010
azurePrometheus:
1111
url: https://defaultazuremonitorworkspace-westus2-szxw.westus2.prometheus.monitor.azure.com
1212
tenantId: 41372654-f4b6-4bd1-a3fe-75629c024df1
@@ -18,6 +18,5 @@ spec:
1818
value: 15
1919
unit: Day
2020
queryDelay:
21-
duration:
22-
value: 1
23-
unit: Second
21+
value: 1
22+
unit: Second

manifest/v1alpha/agent/examples/big-query.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ spec:
99
releaseChannel: stable
1010
bigQuery: {}
1111
queryDelay:
12-
duration:
13-
value: 1
14-
unit: Second
12+
value: 1
13+
unit: Second

manifest/v1alpha/agent/examples/cloud-watch.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ spec:
1616
value: 7
1717
unit: Day
1818
queryDelay:
19-
duration:
20-
value: 2
21-
unit: Minute
19+
value: 2
20+
unit: Minute

manifest/v1alpha/agent/examples/datadog.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ spec:
1717
value: 15
1818
unit: Day
1919
queryDelay:
20-
duration:
21-
value: 2
22-
unit: Minute
20+
value: 2
21+
unit: Minute

manifest/v1alpha/agent/examples/dynatrace.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ spec:
1717
value: 14
1818
unit: Day
1919
queryDelay:
20-
duration:
21-
value: 3
22-
unit: Minute
20+
value: 3
21+
unit: Minute

manifest/v1alpha/agent/examples/elasticsearch.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ spec:
1010
elasticsearch:
1111
url: http://elasticsearch-main.elasticsearch:9200
1212
queryDelay:
13-
duration:
14-
value: 2
15-
unit: Minute
13+
value: 2
14+
unit: Minute

manifest/v1alpha/agent/examples/generic.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ spec:
99
releaseChannel: stable
1010
generic: {}
1111
queryDelay:
12-
duration:
13-
value: 1
14-
unit: Second
12+
value: 1
13+
unit: Second

manifest/v1alpha/agent/examples/google-cloud-monitoring.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ spec:
1616
value: 15
1717
unit: Day
1818
queryDelay:
19-
duration:
20-
value: 3
21-
unit: Minute
19+
value: 3
20+
unit: Minute

manifest/v1alpha/agent/examples/grafana-loki.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ spec:
1010
grafanaLoki:
1111
url: http://grafana-loki.loki:3100
1212
queryDelay:
13-
duration:
14-
value: 2
15-
unit: Minute
13+
value: 2
14+
unit: Minute

manifest/v1alpha/agent/examples/graphite.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ spec:
1717
value: 15
1818
unit: Day
1919
queryDelay:
20-
duration:
21-
value: 2
22-
unit: Minute
20+
value: 2
21+
unit: Minute

manifest/v1alpha/agent/examples/honeycomb.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
project: default
77
spec:
88
description: Example Honeycomb Agent
9-
releaseChannel: stable
9+
releaseChannel: beta
1010
honeycomb: {}
1111
historicalDataRetrieval:
1212
maxDuration:
@@ -16,6 +16,5 @@ spec:
1616
value: 3
1717
unit: Day
1818
queryDelay:
19-
duration:
20-
value: 6
21-
unit: Minute
19+
value: 6
20+
unit: Minute

manifest/v1alpha/agent/examples/influx-d-b.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ spec:
1010
influxdb:
1111
url: https://us-west-2-2.aws.cloud2.influxdata.com
1212
queryDelay:
13-
duration:
14-
value: 2
15-
unit: Minute
13+
value: 2
14+
unit: Minute

manifest/v1alpha/agent/examples/instana.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ spec:
1010
instana:
1111
url: https://orange-my-org12.instana.io
1212
queryDelay:
13-
duration:
14-
value: 2
15-
unit: Minute
13+
value: 2
14+
unit: Minute

manifest/v1alpha/agent/examples/lightstep.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ spec:
1919
value: 15
2020
unit: Day
2121
queryDelay:
22-
duration:
23-
value: 3
24-
unit: Minute
22+
value: 3
23+
unit: Minute

0 commit comments

Comments
 (0)