Skip to content

Commit

Permalink
chore: fix junit test
Browse files Browse the repository at this point in the history
chore: test fixes
  • Loading branch information
moshloop committed Oct 5, 2023
1 parent 768a9d3 commit 5a4ec50
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 51 deletions.
31 changes: 14 additions & 17 deletions checks/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,21 @@ func getOrAddPrometheusMetric(name, metricType string, labelNames []string) (pro
}

func getWithEnvironment(ctx *context.Context, r *pkg.CheckResult) *context.Context {
templateInput := map[string]any{
"result": r.Data,
"canary": map[string]any{
"name": r.Canary.GetName(),
"namespace": r.Canary.GetNamespace(),
"labels": r.Canary.GetLabels(),
"id": r.Canary.GetPersistedID(),
},
"check": map[string]any{
"name": r.Check.GetName(),
"id": r.Canary.GetCheckID(r.Check.GetName()),
"description": r.Check.GetDescription(),
"labels": r.Check.GetLabels(),
"endpoint": r.Check.GetEndpoint(),
"duration": time.Millisecond * time.Duration(r.GetDuration()),
},
r.Data["canary"] = map[string]any{
"name": r.Canary.GetName(),
"namespace": r.Canary.GetNamespace(),
"labels": r.Canary.GetLabels(),
"id": r.Canary.GetPersistedID(),
}
return ctx.New(templateInput)
r.Data["check"] = map[string]any{
"name": r.Check.GetName(),
"id": r.Canary.GetCheckID(r.Check.GetName()),
"description": r.Check.GetDescription(),
"labels": r.Check.GetLabels(),
"endpoint": r.Check.GetEndpoint(),
"duration": time.Millisecond * time.Duration(r.GetDuration()),
}
return ctx.New(r.Data)
}

func getLabels(ctx *context.Context, metric external.Metrics) (map[string]string, []string, error) {
Expand Down
38 changes: 14 additions & 24 deletions fixtures/k8s/junit_pass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
name: junit-pass
labels:
part-of: canary-tools
spec:
interval: 120
owner: DBAdmin
severity: high
junit:
- testResults: "/tmp/junit-results/"
name: junit-pass
test:
expr: results.failed == 0 && results.passed > 0
display:
template: |
✅ {{.results.passed}} ❌ {{.results.failed}} in 🕑 {{.results.duration}}
{{ range $r := .results.suites}}
{{- if gt (conv.ToInt $r.failed) 0 }}
{{$r.name}} ✅ {{$r.passed}} ❌ {{$r.failed}} in 🕑 {{$r.duration}}
{{- end }}
{{- end }}
expr: "string(results.failed) + ' of ' + string(results.passed)"
spec:
containers:
- name: jes
Expand All @@ -25,26 +22,19 @@ spec:
metrics:
- name: junit_check_pass_count
type: gauge
value: "result.results.passed"
value: results.passed
labels:
- name: name
value: junit_check_pass_count
- name: check_name
valueExpr: check.name
- name: suite_name
valueExpr: results.suites[0].name
- name: junit_check_failed_count
type: gauge
value: "result.results.failed"
value: results.failed
labels:
- name: name
value: junit_check_fail_count
- name: check_name
valueExpr: check.name
- name: part_of
valueExpr: canary.labels['part-of']
- name: junit_check_duration_ms
type: histogram
value: "check.duration"
value: results.duration * 1000.0
labels:
- name: name
value: junit_check_duration_ms
- name: check_name
valueExpr: check.name

- name: suite_name
valueExpr: results.suites[0].name
6 changes: 4 additions & 2 deletions fixtures/minimal/http_auth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ metadata:
name: http-basic-auth
spec:
http:
- endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
- name: access-denied
endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [401]
- endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
- name: ok
endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world
responseCodes: [200]
username:
value: hello
Expand Down
4 changes: 2 additions & 2 deletions fixtures/minimal/http_pass_single.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ spec:
metrics:
- name: httpbin_2xx_count
type: counter
value: "result.code == 200 ? 1 : 0"
value: "code == 200 ? 1 : 0"
labels:
- name: name
value: httpbin_2xx_count
- name: check_name
valueExpr: check.name
- name: status_class
valueExpr: string(result.code).charAt(0)
valueExpr: string(code).charAt(0)
- name: http-param-tests
url: https://httpbin.demo.aws.flanksource.com/status/200
responseCodes: [201, 200, 301]
Expand Down
8 changes: 4 additions & 4 deletions fixtures/minimal/metrics-multiple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
metrics:
- name: exchange_rate
type: gauge
value: result.json.rates.GBP
value: json.rates.GBP
labels:
- name: "from"
value: "USD"
Expand All @@ -21,7 +21,7 @@ spec:

- name: exchange_rate
type: gauge
value: result.json.rates.EUR
value: json.rates.EUR
labels:
- name: "from"
value: "USD"
Expand All @@ -30,12 +30,12 @@ spec:

- name: exchange_rate
type: gauge
value: result.json.rates.ILS
value: json.rates.ILS
labels:
- name: "from"
value: "USD"
- name: to
value: ILS
- name: exchange_rate_api
type: histogram
value: result.elapsed.getMilliseconds()
value: elapsed.getMilliseconds()
4 changes: 2 additions & 2 deletions fixtures/minimal/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ spec:
- name: check_name
valueExpr: check.name
- name: code
valueExpr: result.code
valueExpr: code
- name: httpbin_2xx_duration
type: counter
value: result.elapsed.getMilliseconds()
value: elapsed.getMilliseconds()
labels:
- name: check_name
valueExpr: check.name
File renamed without changes.

0 comments on commit 5a4ec50

Please sign in to comment.