Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/PC-13696-timestamp-precision' in…
Browse files Browse the repository at this point in the history
…to PC-13696-timestamp-precision
  • Loading branch information
kubaceg committed Sep 24, 2024
2 parents 913967b + 0233f4a commit 4a18246
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
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
2 changes: 1 addition & 1 deletion manifest/v1alpha/direct/examples/splunk-observability.yaml
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
25 changes: 24 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"
errCodeUnsupportedReleaseChannel = "unsupported_release_channel"
)

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

var releaseChannelValidationRule = govy.NewRule(func(spec Spec) error {
typ, _ := spec.GetType()
if typ != v1alpha.SplunkObservability && spec.ReleaseChannel == v1alpha.ReleaseChannelAlpha {
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"),
)
}

return nil
}).WithErrorCode(errCodeUnsupportedReleaseChannel)

const errorCodeHTTPSSchemeRequired = "https_scheme_required"

func urlPropertyRules[S any](getter govy.PropertyGetter[string, S]) govy.PropertyRules[*url.URL, S] {
Expand Down
26 changes: 26 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: errCodeUnsupportedReleaseChannel,
})
})
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: errCodeUnsupportedReleaseChannel,
})
})
}

func TestValidateSpec_QueryDelay(t *testing.T) {
Expand Down Expand Up @@ -591,11 +615,13 @@ func TestValidateSpec_BigQuery(t *testing.T) {
func TestValidateSpec_SplunkObservability(t *testing.T) {
t.Run("passes", func(t *testing.T) {
direct := validDirect(v1alpha.SplunkObservability)
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelAlpha
err := validate(direct)
testutils.AssertNoError(t, direct, err)
})
t.Run("required realm", func(t *testing.T) {
direct := validDirect(v1alpha.SplunkObservability)
direct.Spec.ReleaseChannel = v1alpha.ReleaseChannelAlpha
direct.Spec.SplunkObservability.Realm = ""
err := validate(direct)
testutils.AssertContainsErrors(t, direct, err, 1, testutils.ExpectedError{
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.

0 comments on commit 4a18246

Please sign in to comment.