Skip to content

Commit 108113d

Browse files
authored
Merge pull request #11 from tailor-platform/fix-calc
fix: correct calculation of execution paths total
2 parents 498b65d + 87804b7 commit 108113d

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

tailor/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *Client) Metrics(resources *Resources) ([]Metric, error) {
3434
testsCount++
3535
}
3636
}
37-
executionPathsTotal += int(math.Pow(float64(len(r.Steps)), float64(testsCount)))
37+
executionPathsTotal += len(r.Steps) * int(math.Pow(2, float64(testsCount)))
3838
}
3939
}
4040
metrics = append(metrics, Metric{

tailor/metrics_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestClient_Metrics(t *testing.T) {
6666
"pipelines_total": 1,
6767
"pipeline_resolvers_total": 1,
6868
"pipeline_resolver_steps_total": 1,
69-
"pipeline_resolver_execution_paths_total": 1, // 1^0 = 1 (no tests)
69+
"pipeline_resolver_execution_paths_total": 1, // 1 * 2^0 = 1 (1 step, no tests)
7070
"tailordbs_total": 1,
7171
"tailordb_types_total": 1,
7272
"tailordb_type_fields_total": 2, // id and name fields
@@ -153,7 +153,7 @@ func TestClient_Metrics(t *testing.T) {
153153
"pipelines_total": 2, // ns1, ns2
154154
"pipeline_resolvers_total": 3, // resolver1, resolver2, resolver3
155155
"pipeline_resolver_steps_total": 6, // 2+3+1 steps
156-
"pipeline_resolver_execution_paths_total": 3, // 2^0 + 3^0 + 1^0 = 1+1+1 (no tests)
156+
"pipeline_resolver_execution_paths_total": 6, // 2*2^0 + 3*2^0 + 1*2^0 = 2+3+1 (no tests)
157157
"tailordbs_total": 2, // two TailorDB instances
158158
"tailordb_types_total": 3, // User, Post, Comment
159159
"tailordb_type_fields_total": 9, // 3+2+4 fields
@@ -368,8 +368,8 @@ func TestClient_Metrics_SpecificMetricValues(t *testing.T) {
368368
if metricMap["pipeline_resolver_steps_total"].Value != float64(5) {
369369
t.Errorf("Expected pipeline_resolver_steps_total to be 5, got %f", metricMap["pipeline_resolver_steps_total"].Value)
370370
}
371-
if metricMap["pipeline_resolver_execution_paths_total"].Value != float64(2) {
372-
t.Errorf("Expected pipeline_resolver_execution_paths_total to be 2, got %f", metricMap["pipeline_resolver_execution_paths_total"].Value)
371+
if metricMap["pipeline_resolver_execution_paths_total"].Value != float64(5) {
372+
t.Errorf("Expected pipeline_resolver_execution_paths_total to be 5, got %f", metricMap["pipeline_resolver_execution_paths_total"].Value)
373373
}
374374

375375
// Test TailorDB metrics
@@ -725,8 +725,8 @@ func TestClient_Metrics_LargeNumbers(t *testing.T) {
725725
if metricMap["pipeline_resolver_steps_total"] != float64(5000) {
726726
t.Errorf("Expected pipeline_resolver_steps_total to be 5000, got %f", metricMap["pipeline_resolver_steps_total"])
727727
}
728-
if metricMap["pipeline_resolver_execution_paths_total"] != float64(1000) {
729-
t.Errorf("Expected pipeline_resolver_execution_paths_total to be 1000, got %f", metricMap["pipeline_resolver_execution_paths_total"])
728+
if metricMap["pipeline_resolver_execution_paths_total"] != float64(5000) {
729+
t.Errorf("Expected pipeline_resolver_execution_paths_total to be 5000, got %f", metricMap["pipeline_resolver_execution_paths_total"])
730730
}
731731
}
732732

@@ -774,7 +774,7 @@ func TestClient_Metrics_ExecutionPaths(t *testing.T) {
774774
"pipelines_total": 1,
775775
"pipeline_resolvers_total": 1,
776776
"pipeline_resolver_steps_total": 3,
777-
"pipeline_resolver_execution_paths_total": 9, // 3^2 = 9 (3 steps, 2 tests)
777+
"pipeline_resolver_execution_paths_total": 12, // 3 * 2^2 = 12 (3 steps, 2 tests)
778778
},
779779
},
780780
{
@@ -842,8 +842,8 @@ func TestClient_Metrics_ExecutionPaths(t *testing.T) {
842842
expectedMetrics: map[string]float64{
843843
"pipelines_total": 1,
844844
"pipeline_resolvers_total": 3,
845-
"pipeline_resolver_steps_total": 6, // 2+3+1 steps
846-
"pipeline_resolver_execution_paths_total": 8, // 2^2 + 3^1 + 1^0 = 4+3+1 = 8
845+
"pipeline_resolver_steps_total": 6, // 2+3+1 steps
846+
"pipeline_resolver_execution_paths_total": 15, // 2*2^2 + 3*2^1 + 1*2^0 = 8+6+1 = 15
847847
},
848848
},
849849
{
@@ -878,7 +878,7 @@ func TestClient_Metrics_ExecutionPaths(t *testing.T) {
878878
"pipelines_total": 1,
879879
"pipeline_resolvers_total": 1,
880880
"pipeline_resolver_steps_total": 2,
881-
"pipeline_resolver_execution_paths_total": 1, // 2^0 = 1 (no tests)
881+
"pipeline_resolver_execution_paths_total": 2, // 2 * 2^0 = 2 (2 steps, no tests)
882882
},
883883
},
884884
{
@@ -900,7 +900,7 @@ func TestClient_Metrics_ExecutionPaths(t *testing.T) {
900900
"pipelines_total": 1,
901901
"pipeline_resolvers_total": 1,
902902
"pipeline_resolver_steps_total": 0,
903-
"pipeline_resolver_execution_paths_total": 1, // 0^0 = 1 (by math.Pow definition)
903+
"pipeline_resolver_execution_paths_total": 0, // 0 * 2^0 = 0 (no steps)
904904
},
905905
},
906906
{
@@ -947,7 +947,7 @@ func TestClient_Metrics_ExecutionPaths(t *testing.T) {
947947
"pipelines_total": 1,
948948
"pipeline_resolvers_total": 1,
949949
"pipeline_resolver_steps_total": 4,
950-
"pipeline_resolver_execution_paths_total": 256, // 4^4 = 256 (4 steps, 4 tests)
950+
"pipeline_resolver_execution_paths_total": 64, // 4 * 2^4 = 64 (4 steps, 4 tests)
951951
},
952952
},
953953
}
@@ -1038,7 +1038,7 @@ func TestClient_Metrics_ExecutionPaths_EdgeCases(t *testing.T) {
10381038
}
10391039

10401040
// Expected: 3 steps, 2 tests (one empty string doesn't count, whitespace does count)
1041-
expectedExecutionPaths := float64(9) // 3^2 = 9
1041+
expectedExecutionPaths := float64(12) // 3 * 2^2 = 12
10421042
if metricMap["pipeline_resolver_execution_paths_total"] != expectedExecutionPaths {
10431043
t.Errorf("Expected execution paths to be %.0f, got %.0f",
10441044
expectedExecutionPaths, metricMap["pipeline_resolver_execution_paths_total"])
@@ -1077,8 +1077,8 @@ func TestClient_Metrics_ExecutionPaths_EdgeCases(t *testing.T) {
10771077
metricMap[m.Name] = m.Value
10781078
}
10791079

1080-
// Expected: 1 step, 1 test -> 1^1 = 1
1081-
expectedExecutionPaths := float64(1)
1080+
// Expected: 1 step, 1 test -> 1 * 2^1 = 2
1081+
expectedExecutionPaths := float64(2)
10821082
if metricMap["pipeline_resolver_execution_paths_total"] != expectedExecutionPaths {
10831083
t.Errorf("Expected execution paths to be %.0f, got %.0f",
10841084
expectedExecutionPaths, metricMap["pipeline_resolver_execution_paths_total"])

0 commit comments

Comments
 (0)