Skip to content

Commit 674edbb

Browse files
authored
feat(metrics): add runs by day and update returned types (#584)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 47826db commit 674edbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2894
-893
lines changed

app/controlplane/api/controlplane/v1/org_metrics.pb.go

Lines changed: 588 additions & 219 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/org_metrics.pb.validate.go

Lines changed: 931 additions & 203 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -17,50 +17,87 @@ syntax = "proto3";
1717

1818
package controlplane.v1;
1919

20-
option go_package = "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1;v1";
21-
import "validate/validate.proto";
2220
import "controlplane/v1/response_messages.proto";
21+
import "validate/validate.proto";
22+
import "workflowcontract/v1/crafting_schema.proto";
23+
24+
option go_package = "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1;v1";
2325

2426
service OrgMetricsService {
25-
rpc Totals (OrgMetricsServiceTotalsRequest) returns (OrgMetricsServiceTotalsResponse);
26-
rpc TopWorkflowsByRunsCount (TopWorkflowsByRunsCountRequest) returns (TopWorkflowsByRunsCountResponse);
27+
rpc Totals(OrgMetricsServiceTotalsRequest) returns (OrgMetricsServiceTotalsResponse);
28+
rpc TopWorkflowsByRunsCount(TopWorkflowsByRunsCountRequest) returns (TopWorkflowsByRunsCountResponse);
29+
rpc DailyRunsCount(DailyRunsCountRequest) returns (DailyRunsCountResponse);
30+
}
31+
32+
// Get the dayly count of runs by status
33+
message DailyRunsCountRequest {
34+
optional string workflow_id = 1 [(validate.rules).string.uuid = true];
35+
36+
MetricsTimeWindow time_window = 2 [(validate.rules).enum = {
37+
not_in: [0]
38+
}];
39+
}
40+
41+
message DailyRunsCountResponse {
42+
repeated TotalByDay result = 1;
43+
44+
message TotalByDay {
45+
// string format: "YYYY-MM-DD"
46+
string date = 1;
47+
MetricsStatusCount metrics = 2;
48+
}
2749
}
2850

2951
message OrgMetricsServiceTotalsRequest {
30-
MetricsTimeWindow time_window = 1 [(validate.rules).enum = {not_in: [0]}];
52+
MetricsTimeWindow time_window = 1 [(validate.rules).enum = {
53+
not_in: [0]
54+
}];
55+
}
56+
57+
message OrgMetricsServiceTotalsResponse {
58+
Result result = 1;
59+
60+
message Result {
61+
int32 runs_total = 1;
62+
repeated MetricsStatusCount runs_total_by_status = 2;
63+
repeated MetricsRunnerCount runs_total_by_runner_type = 3;
64+
}
65+
}
66+
67+
message MetricsStatusCount {
68+
int32 count = 1;
69+
RunStatus status = 2;
70+
}
71+
72+
message MetricsRunnerCount {
73+
int32 count = 1;
74+
workflowcontract.v1.CraftingSchema.Runner.RunnerType runner_type = 2;
3175
}
3276

3377
message TopWorkflowsByRunsCountRequest {
3478
// top x number of runs to return
35-
int32 num_workflows = 1 [(validate.rules).int32 = {gte: 1, lte: 20}];;
36-
MetricsTimeWindow time_window = 2 [(validate.rules).enum = {not_in: [0]}];
79+
int32 num_workflows = 1 [(validate.rules).int32 = {
80+
gte: 1,
81+
lte: 20
82+
}];
83+
MetricsTimeWindow time_window = 2 [(validate.rules).enum = {
84+
not_in: [0]
85+
}];
3786
}
3887

3988
message TopWorkflowsByRunsCountResponse {
4089
repeated TotalByStatus result = 1;
4190

4291
message TotalByStatus {
4392
WorkflowItem workflow = 1;
44-
// Status -> [initialized, error, success]
45-
map<string,int32> runs_total_by_status = 2;
46-
}
47-
}
48-
49-
message OrgMetricsServiceTotalsResponse {
50-
Result result = 1;
51-
52-
message Result {
53-
int32 runs_total = 1;
54-
// Status -> [initialized, error, success]
55-
map<string,int32> runs_total_by_status = 2;
56-
// runner_type -> [generic, github_action, ...]
57-
map<string,int32> runs_total_by_runner_type = 3;
93+
repeated MetricsStatusCount runs_total_by_status = 2;
5894
}
5995
}
6096

6197
enum MetricsTimeWindow {
62-
METRICS_TIME_WINDOW_UNSPECIFIED = 0;
63-
METRICS_TIME_WINDOW_LAST_30_DAYS = 1;
64-
METRICS_TIME_WINDOW_LAST_7_DAYS = 2;
65-
METRICS_TIME_WINDOW_LAST_DAY = 3;
66-
}
98+
METRICS_TIME_WINDOW_UNSPECIFIED = 0;
99+
METRICS_TIME_WINDOW_LAST_DAY = 1;
100+
METRICS_TIME_WINDOW_LAST_7_DAYS = 2;
101+
METRICS_TIME_WINDOW_LAST_30_DAYS = 3;
102+
METRICS_TIME_WINDOW_LAST_90_DAYS = 4;
103+
}

app/controlplane/api/controlplane/v1/org_metrics_grpc.pb.go

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/orgmetrics.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -20,13 +20,22 @@ import "time"
2020
func (tw MetricsTimeWindow) ToDuration() *time.Duration {
2121
var d time.Duration
2222

23+
var (
24+
day = 24 * time.Hour
25+
week = 7 * day
26+
month = 30 * day
27+
quarter = 3 * month
28+
)
29+
2330
switch tw {
31+
case MetricsTimeWindow_METRICS_TIME_WINDOW_LAST_90_DAYS:
32+
d = quarter
2433
case MetricsTimeWindow_METRICS_TIME_WINDOW_LAST_30_DAYS:
25-
d = 30 * 24 * time.Hour
34+
d = month
2635
case MetricsTimeWindow_METRICS_TIME_WINDOW_LAST_7_DAYS:
27-
d = 7 * 24 * time.Hour
36+
d = week
2837
case MetricsTimeWindow_METRICS_TIME_WINDOW_LAST_DAY:
29-
d = 24 * time.Hour
38+
d = day
3039
}
3140

3241
return &d

0 commit comments

Comments
 (0)