Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate Splunk Observability release channel #552

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/manifest/v1alpha/examples/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func Direct() []Example {
return examples
}

var alphaChannelDirects = []v1alpha.DataSourceType{
v1alpha.SplunkObservability,
}

var betaChannelDirects = []v1alpha.DataSourceType{
v1alpha.AzureMonitor,
v1alpha.Honeycomb,
Expand Down Expand Up @@ -77,7 +81,9 @@ func (d directExample) Generate() v1alphaDirect.Direct {
Unit: defaultQueryDelay.Unit,
},
}
if slices.Contains(betaChannelDirects, typ) {
if slices.Contains(alphaChannelDirects, typ) {
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelAlpha
} else if slices.Contains(betaChannelDirects, typ) {
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
} else {
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelStable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
project: default
spec:
description: Example Splunk Observability Direct
releaseChannel: stable
releaseChannel: alpha
splunkObservability:
realm: us1
accessToken: "[secret]"
Expand Down
27 changes: 26 additions & 1 deletion manifest/v1alpha/direct/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var specValidation = govy.New[Spec](
Rules(exactlyOneDataSourceTypeValidationRule).
Rules(
historicalDataRetrievalValidationRule,
queryDelayGreaterThanOrEqualToDefaultValidationRule),
queryDelayGreaterThanOrEqualToDefaultValidationRule,
releaseChannelValidationRule),
govy.For(func(s Spec) v1alpha.ReleaseChannel { return s.ReleaseChannel }).
WithName("releaseChannel").
OmitEmpty().
Expand Down Expand Up @@ -223,6 +224,7 @@ var (
const (
errCodeExactlyOneDataSourceType = "exactly_one_data_source_type"
errCodeQueryDelayGreaterThanOrEqualToDefault = "query_delay_greater_than_or_equal_to_default"
errUnsupportedReleaseChannel = "unsupported_release_channel"
mkaras-nobl9 marked this conversation as resolved.
Show resolved Hide resolved
)

var exactlyOneDataSourceTypeValidationRule = govy.NewRule(func(spec Spec) error {
Expand Down Expand Up @@ -383,6 +385,29 @@ var queryDelayGreaterThanOrEqualToDefaultValidationRule = govy.NewRule(func(spec
return nil
}).WithErrorCode(errCodeQueryDelayGreaterThanOrEqualToDefault)

const errorCodeUnsupportedReleaseChannel = "unsupported_release_channel"
mkaras-nobl9 marked this conversation as resolved.
Show resolved Hide resolved

var releaseChannelValidationRule = govy.NewRule(func(spec Spec) error {
typ, _ := spec.GetType()
if typ != v1alpha.SplunkObservability && spec.ReleaseChannel == v1alpha.ReleaseChannelAlpha {
nieomylnieja marked this conversation as resolved.
Show resolved Hide resolved
return govy.NewPropertyError(
"releaseChannel",
spec.ReleaseChannel,
errors.New("must be one of [stable, beta]"),
)
}

if typ == v1alpha.SplunkObservability && spec.ReleaseChannel != v1alpha.ReleaseChannelAlpha {
return govy.NewPropertyError(
"releaseChannel",
spec.ReleaseChannel,
errors.New("must be alpha for Splunk Observability"),
mkaras-nobl9 marked this conversation as resolved.
Show resolved Hide resolved
)
}

return nil
}).WithErrorCode(errorCodeUnsupportedReleaseChannel)

const errorCodeHTTPSSchemeRequired = "https_scheme_required"

func urlPropertyRules[S any](getter govy.PropertyGetter[string, S]) govy.PropertyRules[*url.URL, S] {
Expand Down
24 changes: 24 additions & 0 deletions manifest/v1alpha/direct/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,30 @@ func TestValidateSpec_ReleaseChannel(t *testing.T) {
Code: rules.ErrorCodeOneOf,
})
})
t.Run("data source type using supported release channel", func(t *testing.T) {
direct := validDirect(v1alpha.Datadog)
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelBeta
err := validate(direct)
testutils.AssertNoError(t, direct, err)
})
t.Run("data source type using unsupported release channel", func(t *testing.T) {
direct := validDirect(v1alpha.Datadog)
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelAlpha
err := validate(direct)
testutils.AssertContainsErrors(t, direct, err, 1, testutils.ExpectedError{
Prop: "spec.releaseChannel",
Code: errUnsupportedReleaseChannel,
})
})
t.Run("data source type using unsupported release channel", func(t *testing.T) {
direct := validDirect(v1alpha.SplunkObservability)
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelStable
err := validate(direct)
testutils.AssertContainsErrors(t, direct, err, 1, testutils.ExpectedError{
Prop: "spec.releaseChannel",
Code: errUnsupportedReleaseChannel,
})
})
}

func TestValidateSpec_QueryDelay(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion manifest/v1alpha/release_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ func (r *ReleaseChannel) UnmarshalText(text []byte) error {
}

func ReleaseChannelValidation() govy.Rule[ReleaseChannel] {
return rules.OneOf(ReleaseChannelStable, ReleaseChannelBeta)
return rules.OneOf(ReleaseChannelStable, ReleaseChannelBeta, ReleaseChannelAlpha)
}
Binary file modified sdk/config_activity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading