Skip to content

Commit

Permalink
Merge branch 'master' into fix/post-promotion-scaling-events-cause-ir…
Browse files Browse the repository at this point in the history
…reconcilable-rollout
  • Loading branch information
benminter-treatwell authored Jul 22, 2024
2 parents 459d9ac + d962435 commit e1692ff
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/image-reuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:

- name: Build and push container image
id: image
uses: docker/build-push-action@1a162644f9a7e87d8f4b053101d1d9a712edc18c #v6.3.0
uses: docker/build-push-action@a254f8ca60a858f3136a2f1f23a60969f2c402dd #v6.4.0
with:
context: .
platforms: ${{ inputs.platforms }}
Expand Down
4 changes: 4 additions & 0 deletions metricproviders/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ func (p *Provider) createRequestV2(queries map[string]string, formula string, no
"formula": formula,
}}
}
// we cannot leave aggregator empty as it will be passed as such to datadog API and fail
if aggregator == "" {
aggregator = "last"
}

attribs := datadogQueryAttributes{
// Datadog requires milliseconds for v2 api
Expand Down
36 changes: 36 additions & 0 deletions metricproviders/datadog/datadogV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func newQueryProviderInterval10m() v1alpha1.MetricProvider {
}
}

func newQueryProviderSumAggregator() v1alpha1.MetricProvider {
return v1alpha1.MetricProvider{
Datadog: &v1alpha1.DatadogMetric{
Query: "avg:kubernetes.cpu.user.total{*}",
Interval: "5m",
Aggregator: "sum",
ApiVersion: "v2",
},
}
}
func TestRunSuiteV2(t *testing.T) {
const expectedApiKey = "0123456789abcdef0123456789abcdef"
const expectedAppKey = "0123456789abcdef0123456789abcdef01234567"
Expand All @@ -68,6 +78,7 @@ func TestRunSuiteV2(t *testing.T) {
expectedValue string
expectedPhase v1alpha1.AnalysisPhase
expectedErrorMessage string
expectedAggregator string
useEnvVarForKeys bool
}{
{
Expand Down Expand Up @@ -252,6 +263,21 @@ func TestRunSuiteV2(t *testing.T) {
expectedPhase: v1alpha1.AnalysisPhaseSuccessful,
useEnvVarForKeys: false,
},

{
webServerStatus: 200,
webServerResponse: `{"data": {"attributes": {"columns": [ {"values": [0.006121378742186943]}]}}}`,
metric: v1alpha1.Metric{
Name: "success with default and data",
SuccessCondition: "default(result, 0) < 0.05",
Provider: newQueryProviderSumAggregator(),
},
expectedIntervalSeconds: 300,
expectedValue: "0.006121378742186943",
expectedPhase: v1alpha1.AnalysisPhaseSuccessful,
expectedAggregator: "sum",
useEnvVarForKeys: false,
},
}

// Run
Expand Down Expand Up @@ -298,6 +324,16 @@ func TestRunSuiteV2(t *testing.T) {
t.Errorf("\nExpected formula but no Formulas in request: %+v", actualFormulas)
}
}
// Check query aggregation being set
expectedAggregator := test.expectedAggregator
if expectedAggregator == "" {
expectedAggregator = "last"
}
for _, query := range actualQueries {
if query["aggregator"] != expectedAggregator {
t.Errorf("\naggregator expected %s but got %s", expectedAggregator, query["aggregator"])
}
}

if actualFrom != (unixNow()-test.expectedIntervalSeconds)*1000 {
t.Errorf("\nfrom %d expected be equal to %d", actualFrom, (unixNow()-test.expectedIntervalSeconds)*1000)
Expand Down

0 comments on commit e1692ff

Please sign in to comment.