Skip to content

Commit

Permalink
chore: Add v1alpha Agent and Direct end-to-end tests (#490)
Browse files Browse the repository at this point in the history
Adds v1alpha `Agent` and `Direct` tests.
  • Loading branch information
nieomylnieja authored Jul 11, 2024
1 parent 77ff3d4 commit 51352eb
Show file tree
Hide file tree
Showing 59 changed files with 500 additions and 174 deletions.
23 changes: 19 additions & 4 deletions internal/manifest/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"testing"

"github.com/goccy/go-yaml"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

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

func TestObjectExamples(t *testing.T) {
moduleRoot := pathutils.FindModuleRoot()
objects, err := sdk.ReadObjects(context.Background(), filepath.Join(moduleRoot, "manifest/**/example*.yaml"))
objects, err := sdk.ReadObjects(context.Background(),
filepath.Join(moduleRoot, "manifest/**/example*.yaml"),
filepath.Join(moduleRoot, "manifest/**/examples/*.yaml"),
)
require.NoError(t, err)
assert.Greater(t, len(objects), 0, "no object examples found")
errs := manifest.Validate(objects)
assert.Empty(t, errs)
assert.NotEmpty(t, objects, "no object examples found")
for i := range objects {
err = objects[i].Validate()
require.NoError(t, err)
// Make sure YAML and JSON are interoperable.
yamlData, err := yaml.Marshal(objects[i])
require.NoError(t, err)
jsonData, err := yaml.YAMLToJSON(yamlData)
assert.NoError(t, err)
object, err := sdk.DecodeObject[manifest.Object](jsonData)
assert.NoError(t, err)
err = object.Validate()
require.NoError(t, err)
}
}
21 changes: 19 additions & 2 deletions internal/manifest/v1alpha/examples/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alphaExamples

import (
"fmt"
"slices"

"github.com/nobl9/nobl9-go/manifest"
"github.com/nobl9/nobl9-go/manifest/v1alpha"
Expand All @@ -14,6 +15,10 @@ type agentExample struct {
typ v1alpha.DataSourceType
}

func (a agentExample) GetDataSourceType() v1alpha.DataSourceType {
return a.typ
}

func Agent() []Example {
types := v1alpha.DataSourceTypeValues()
examples := make([]Example, 0, len(types))
Expand All @@ -30,6 +35,14 @@ func Agent() []Example {
return examples
}

var betaChannelAgents = []v1alpha.DataSourceType{
v1alpha.AzureMonitor,
v1alpha.Honeycomb,
v1alpha.LogicMonitor,
v1alpha.AzurePrometheus,
v1alpha.GCM,
}

func (a agentExample) Generate() v1alphaAgent.Agent {
titleName := dataSourceTypePrettyName(a.typ)
agent := v1alphaAgent.New(
Expand All @@ -39,8 +52,7 @@ func (a agentExample) Generate() v1alphaAgent.Agent {
Project: sdk.DefaultProject,
},
v1alphaAgent.Spec{
Description: fmt.Sprintf("Example %s Agent", titleName),
ReleaseChannel: v1alpha.ReleaseChannelStable,
Description: fmt.Sprintf("Example %s Agent", titleName),
},
)
agent = a.generateVariant(agent)
Expand All @@ -61,6 +73,11 @@ func (a agentExample) Generate() v1alphaAgent.Agent {
Unit: defaultQueryDelay.Unit,
},
}
if slices.Contains(betaChannelAgents, typ) {
agent.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
} else {
agent.Spec.ReleaseChannel = v1alpha.ReleaseChannelStable
}
return agent
}

Expand Down
12 changes: 8 additions & 4 deletions internal/manifest/v1alpha/examples/alert_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ var customAlertMethodsSubVariants = map[v1alpha.AlertMethodType][]alertMethodSpe

type alertMethodExample struct {
standardExample
methodType v1alpha.AlertMethodType
typ v1alpha.AlertMethodType
}

func (a alertMethodExample) GetAlertMethodType() v1alpha.AlertMethodType {
return a.typ
}

func (a alertMethodExample) GetYAMLComments() []string {
Expand All @@ -54,7 +58,7 @@ func AlertMethod() []Example {
standardExample: standardExample{
Variant: typ.String(),
},
methodType: typ,
typ: typ,
})
}
for typ, subVariants := range customAlertMethodsSubVariants {
Expand All @@ -64,7 +68,7 @@ func AlertMethod() []Example {
Variant: typ.String(),
SubVariant: subVariant,
},
methodType: typ,
typ: typ,
})
}
}
Expand All @@ -89,7 +93,7 @@ func (a alertMethodExample) Generate() v1alphaAlertMethod.AlertMethod {
}

func (a alertMethodExample) generateVariant(am v1alphaAlertMethod.AlertMethod) v1alphaAlertMethod.AlertMethod {
switch a.methodType {
switch a.typ {
case v1alpha.AlertMethodTypeEmail:
am.Spec.Email = &v1alphaAlertMethod.EmailAlertMethod{
To: []string{"[email protected]"},
Expand Down
2 changes: 1 addition & 1 deletion internal/manifest/v1alpha/examples/alert_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestAlertMethod_SupportsAllAlertMethodTypes(t *testing.T) {
variants := AlertMethod()
for _, methodType := range v1alpha.AlertMethodTypeValues() {
if !slices.ContainsFunc(variants, func(e Example) bool {
return e.(alertMethodExample).methodType == methodType
return e.(alertMethodExample).typ == methodType
}) {
t.Errorf("%T '%s' is not listed in the examples", methodType, methodType)
}
Expand Down
25 changes: 21 additions & 4 deletions internal/manifest/v1alpha/examples/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alphaExamples

import (
"fmt"
"slices"

"github.com/nobl9/nobl9-go/manifest"
"github.com/nobl9/nobl9-go/manifest/v1alpha"
Expand All @@ -14,6 +15,10 @@ type directExample struct {
typ v1alpha.DataSourceType
}

func (d directExample) GetDataSourceType() v1alpha.DataSourceType {
return d.typ
}

func Direct() []Example {
types := v1alpha.DataSourceTypeValues()
examples := make([]Example, 0, len(types))
Expand All @@ -33,6 +38,13 @@ func Direct() []Example {
return examples
}

var betaChannelDirects = []v1alpha.DataSourceType{
v1alpha.AzureMonitor,
v1alpha.Honeycomb,
v1alpha.LogicMonitor,
v1alpha.GoogleCloudMonitoring,
}

func (d directExample) Generate() v1alphaDirect.Direct {
titleName := dataSourceTypePrettyName(d.typ)
direct := v1alphaDirect.New(
Expand Down Expand Up @@ -64,6 +76,11 @@ func (d directExample) Generate() v1alphaDirect.Direct {
Unit: defaultQueryDelay.Unit,
},
}
if slices.Contains(betaChannelDirects, typ) {
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
} else {
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelStable
}
return direct
}

Expand All @@ -77,6 +94,7 @@ func (d directExample) generateVariant(direct v1alphaDirect.Direct) v1alphaDirec
ClientSecret: "[secret]",
}
case v1alpha.AzureMonitor:
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
direct.Spec.AzureMonitor = &v1alphaDirect.AzureMonitorConfig{
TenantID: "5cdecca3-c2c5-4072-89dd-5555faf05202",
ClientID: "70747025-9367-41a5-98f1-59b18b5793c3",
Expand Down Expand Up @@ -106,6 +124,7 @@ func (d directExample) generateVariant(direct v1alphaDirect.Direct) v1alphaDirec
ServiceAccountKey: gcloudServiceAccountKey,
}
case v1alpha.Honeycomb:
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
direct.Spec.Honeycomb = &v1alphaDirect.HoneycombConfig{
APIKey: "[secret]",
}
Expand Down Expand Up @@ -144,10 +163,8 @@ func (d directExample) generateVariant(direct v1alphaDirect.Direct) v1alphaDirec
}
case v1alpha.Redshift:
direct.Spec.Redshift = &v1alphaDirect.RedshiftConfig{
AccessKeyID: "AKIA4NPYKXO34R341XUX",
SecretAccessKey: "[secret]",
SecretARN: "arn:aws:secretsmanager:eu-central-1:123456578901:secret:prod-redshift-db-user",
RoleARN: "arn:aws:iam::123456578901:role/awsCrossAccountProdRedshift-prod-app",
SecretARN: "arn:aws:secretsmanager:eu-central-1:123456578901:secret:prod-redshift-db-user",
RoleARN: "arn:aws:iam::123456578901:role/awsCrossAccountProdRedshift-prod-app",
}
case v1alpha.Splunk:
direct.Spec.Splunk = &v1alphaDirect.SplunkConfig{
Expand Down
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/amazon-prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 1
unit: Second
value: 1
unit: Second
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/app-dynamics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
7 changes: 3 additions & 4 deletions manifest/v1alpha/agent/examples/azure-monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
project: default
spec:
description: Example Azure Monitor Agent
releaseChannel: stable
releaseChannel: beta
azureMonitor:
tenantId: 5cdecca3-c2c5-4072-89dd-5555faf05202
historicalDataRetrieval:
Expand All @@ -17,6 +17,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 6
unit: Minute
value: 6
unit: Minute
7 changes: 3 additions & 4 deletions manifest/v1alpha/agent/examples/azure-prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
project: default
spec:
description: Example Azure Prometheus Agent
releaseChannel: stable
releaseChannel: beta
azurePrometheus:
url: https://defaultazuremonitorworkspace-westus2-szxw.westus2.prometheus.monitor.azure.com
tenantId: 41372654-f4b6-4bd1-a3fe-75629c024df1
Expand All @@ -18,6 +18,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 1
unit: Second
value: 1
unit: Second
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/big-query.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ spec:
releaseChannel: stable
bigQuery: {}
queryDelay:
duration:
value: 1
unit: Second
value: 1
unit: Second
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/cloud-watch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ spec:
value: 7
unit: Day
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/datadog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/dynatrace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ spec:
value: 14
unit: Day
queryDelay:
duration:
value: 3
unit: Minute
value: 3
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ spec:
elasticsearch:
url: http://elasticsearch-main.elasticsearch:9200
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/generic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ spec:
releaseChannel: stable
generic: {}
queryDelay:
duration:
value: 1
unit: Second
value: 1
unit: Second
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/google-cloud-monitoring.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 3
unit: Minute
value: 3
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/grafana-loki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ spec:
grafanaLoki:
url: http://grafana-loki.loki:3100
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/graphite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
7 changes: 3 additions & 4 deletions manifest/v1alpha/agent/examples/honeycomb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
project: default
spec:
description: Example Honeycomb Agent
releaseChannel: stable
releaseChannel: beta
honeycomb: {}
historicalDataRetrieval:
maxDuration:
Expand All @@ -16,6 +16,5 @@ spec:
value: 3
unit: Day
queryDelay:
duration:
value: 6
unit: Minute
value: 6
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/influx-d-b.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ spec:
influxdb:
url: https://us-west-2-2.aws.cloud2.influxdata.com
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/instana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ spec:
instana:
url: https://orange-my-org12.instana.io
queryDelay:
duration:
value: 2
unit: Minute
value: 2
unit: Minute
5 changes: 2 additions & 3 deletions manifest/v1alpha/agent/examples/lightstep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ spec:
value: 15
unit: Day
queryDelay:
duration:
value: 3
unit: Minute
value: 3
unit: Minute
Loading

0 comments on commit 51352eb

Please sign in to comment.