Skip to content

Commit

Permalink
feat(cli): show required gates results (#2947)
Browse files Browse the repository at this point in the history
  • Loading branch information
schoren committed Jul 14, 2023
1 parent 20b9567 commit 837a6b5
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 11 deletions.
21 changes: 20 additions & 1 deletion cli/formatters/test_run.go
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/kubeshop/tracetest/cli/openapi"
"github.com/pterm/pterm"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -94,7 +95,7 @@ func (f testRun) pretty(output TestRunOutput) string {
return f.formatSuccessfulTest(output.Test, output.Run)
}

if !output.Run.Result.GetAllPassed() {
if !output.Run.Result.GetAllPassed() || !output.Run.RequiredGatesResult.GetPassed() {
return f.formatFailedTest(output.Test, output.Run)
}

Expand Down Expand Up @@ -210,6 +211,24 @@ func (f testRun) formatFailedTest(test openapi.Test, run openapi.TestRun) string
}
}

if len(run.GetRequiredGatesResult().Required) > 0 {
buffer.WriteString("\n")
gatesPassed := run.RequiredGatesResult.GetPassed()
icon := f.getStateIcon(gatesPassed)
message = f.getColoredText(
gatesPassed,
f.formatMessage("\t%s %s\n", icon, "Required gates"),
)
buffer.WriteString(message)
for _, gateResult := range run.GetRequiredGatesResult().Required {
passed := slices.Index(run.RequiredGatesResult.Failed, gateResult) == -1
icon := f.getStateIcon(passed)
message := f.formatMessage("\t\t%s %s\n", icon, gateResult)
message = f.getColoredText(passed, message)
buffer.WriteString(message)
}
}

return buffer.String()
}

Expand Down
2 changes: 1 addition & 1 deletion cli/runner/test_runner.go
Expand Up @@ -110,7 +110,7 @@ func (r testRunner) UpdateResult(ctx context.Context, result RunResult) (RunResu
return RunResult{}, err
}

passed := !isStateFailed(updated.GetState()) && updated.Result.GetAllPassed()
passed := !isStateFailed(updated.GetState()) && updated.Result.GetAllPassed() && updated.RequiredGatesResult.GetPassed()

return RunResult{
Resource: test,
Expand Down
2 changes: 1 addition & 1 deletion cli/runner/transaction_runner.go
Expand Up @@ -118,7 +118,7 @@ func (r transactionRunner) UpdateResult(ctx context.Context, result RunResult) (
}
}

passed := !isStateFailed(updated.GetState()) && allPassed
passed := !isStateFailed(updated.GetState()) && allPassed && updated.GetAllStepsRequiredGatesPassed()

return RunResult{
Resource: transaction,
Expand Down
8 changes: 8 additions & 0 deletions examples/collector/tracetest-provision.yaml
Expand Up @@ -14,3 +14,11 @@ spec:
name: OpenTelemetry Collector
type: otlp
default: true
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs
8 changes: 8 additions & 0 deletions examples/tracetest-jaeger/tracetest-provision.yaml
Expand Up @@ -17,3 +17,11 @@ spec:
endpoint: jaeger:16685
tls:
insecure: true
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs
8 changes: 8 additions & 0 deletions examples/tracetest-opensearch/tracetest-provision.yaml
Expand Up @@ -17,3 +17,11 @@ spec:
addresses:
- http://opensearch:9200
index: traces
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs
2 changes: 1 addition & 1 deletion examples/tracetest-provisioning-env/docker-compose.yml
Expand Up @@ -25,7 +25,7 @@ services:
environment:
TRACETEST_DEV: ${TRACETEST_DEV}
# contents of `tracetest-provision.yaml` encoded as base64
TRACETEST_PROVISIONING: "LS0tCnR5cGU6IFBvbGxpbmdQcm9maWxlCnNwZWM6CiAgbmFtZTogRGVmYXVsdAogIHN0cmF0ZWd5OiBwZXJpb2RpYwogIGRlZmF1bHQ6IHRydWUKICBwZXJpb2RpYzoKICAgIHJldHJ5RGVsYXk6IDVzCiAgICB0aW1lb3V0OiAxMG0KCi0tLQp0eXBlOiBEYXRhU3RvcmUKc3BlYzoKICBuYW1lOiBKYWVnZXIKICB0eXBlOiBqYWVnZXIKICBkZWZhdWx0OiB0cnVlCiAgamFlZ2VyOgogICAgZW5kcG9pbnQ6IGphZWdlcjoxNjY4NQogICAgdGxzOgogICAgICBpbnNlY3VyZTogdHJ1ZQo="
TRACETEST_PROVISIONING: "LS0tCnR5cGU6IFBvbGxpbmdQcm9maWxlCnNwZWM6CiAgbmFtZTogRGVmYXVsdAogIHN0cmF0ZWd5OiBwZXJpb2RpYwogIGRlZmF1bHQ6IHRydWUKICBwZXJpb2RpYzoKICAgIHJldHJ5RGVsYXk6IDVzCiAgICB0aW1lb3V0OiAxMG0KCi0tLQp0eXBlOiBEYXRhU3RvcmUKc3BlYzoKICBuYW1lOiBKYWVnZXIKICB0eXBlOiBqYWVnZXIKICBkZWZhdWx0OiB0cnVlCiAgamFlZ2VyOgogICAgZW5kcG9pbnQ6IGphZWdlcjoxNjY4NQogICAgdGxzOgogICAgICBpbnNlY3VyZTogdHJ1ZQotLS0KdHlwZTogVGVzdFJ1bm5lcgpzcGVjOgogIGlkOiBjdXJyZW50CiAgbmFtZTogZGVmYXVsdAogIHJlcXVpcmVkR2F0ZXM6CiAgICAtIGFuYWx5emVyLXNjb3JlCiAgICAtIHRlc3Qtc3BlY3MK"

postgres:
image: postgres:14
Expand Down
8 changes: 8 additions & 0 deletions examples/tracetest-provisioning-env/tracetest-provision.yaml
Expand Up @@ -18,3 +18,11 @@ spec:
endpoint: jaeger:16685
tls:
insecure: true
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs
8 changes: 8 additions & 0 deletions examples/tracetest-signoz/tracetest/tracetest-provision.yaml
Expand Up @@ -13,3 +13,11 @@ type: DataStore
spec:
name: Signoz
type: signoz
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs
8 changes: 8 additions & 0 deletions examples/tracetest-tempo/tracetest-provision.yaml
Expand Up @@ -19,3 +19,11 @@ spec:
endpoint: tempo:9095
tls:
insecure: true
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs
8 changes: 8 additions & 0 deletions local-config/tracetest.provision.yaml
Expand Up @@ -21,3 +21,11 @@ spec:
periodic:
timeout: 30s
retryDelay: 1s
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs
14 changes: 7 additions & 7 deletions server/transaction/transaction_run_repository.go
Expand Up @@ -155,14 +155,14 @@ UPDATE transaction_runs SET
"last_error" = $4,
"pass" = $5,
"fail" = $6,
"all_steps_required_gates_passed" = $11,
"all_steps_required_gates_passed" = $7,
"metadata" = $7,
"metadata" = $8,
-- environment
"environment" = $8
"environment" = $9
WHERE id = $9 AND transaction_id = $10
WHERE id = $10 AND transaction_id = $11
`

func (td *RunRepository) UpdateRun(ctx context.Context, tr TransactionRun) error {
Expand Down Expand Up @@ -193,7 +193,7 @@ func (td *RunRepository) UpdateRun(ctx context.Context, tr TransactionRun) error
}

pass, fail := tr.ResultsCount()
AllStepsRequiredGatesPassed := tr.StepsGatesValidation()
allStepsRequiredGatesPassed := tr.StepsGatesValidation()

_, err = stmt.ExecContext(
ctx,
Expand All @@ -203,11 +203,11 @@ func (td *RunRepository) UpdateRun(ctx context.Context, tr TransactionRun) error
lastError,
pass,
fail,
allStepsRequiredGatesPassed,
jsonMetadata,
jsonEnvironment,
tr.ID,
tr.TransactionID,
AllStepsRequiredGatesPassed,
)

if err != nil {
Expand Down Expand Up @@ -424,7 +424,7 @@ func (td *RunRepository) readRunRow(row scanner) (TransactionRun, error) {

// checks if the flag exists, if it doesn't we use the fail field to determine if all steps passed
if allStepsRequiredGatesPassed == nil {
failed := fail.Valid && fail.Int32 == 0
failed := r.Fail == 0
allStepsRequiredGatesPassed = &failed
}

Expand Down
Expand Up @@ -7,3 +7,11 @@ spec:
periodic:
retryDelay: 500ms
timeout: 1m
---
type: TestRunner
spec:
id: current
name: default
requiredGates:
- analyzer-score
- test-specs

0 comments on commit 837a6b5

Please sign in to comment.