Skip to content

feat(metrics): add runs by day and update returned types - #584

Merged
migmartri merged 2 commits into
chainloop-dev:mainfrom
migmartri:update-metrics
Mar 11, 2024
Merged

feat(metrics): add runs by day and update returned types#584
migmartri merged 2 commits into
chainloop-dev:mainfrom
migmartri:update-metrics

Conversation

@migmartri

@migmartri migmartri commented Mar 8, 2024

Copy link
Copy Markdown
Member

Note to reviewer: There are a lot of changes in the generated code in internal/data/ent. This is because I've enabled the modifier feature flag, to be able to group by Date(timestamp), and regenerated the bindings.

This patch implements two things

1 - Adds a metrics count by day and state endpoint

This endpoint by default returns the number of runs grouped by day and status for the provided time window

grpcurl --plaintext -H "authorization: Bearer $TOKEN" -d '{"time_window": "METRICS_TIME_WINDOW_LAST_30_DAYS"}' localhost:9000 controlplane.v1.OrgMetricsService.DailyRunsCount
{                  
  "result": [                                                                  
    {                                                                          
      "date": "2024-02-09",
      "metrics": {                                                             
        "count": 1,                                                            
        "status": "RUN_STATUS_SUCCEEDED"                                       
      }            
    },                                                                         
    {                                 
      "date": "2024-02-10",
      "metrics": {                                                             
        "count": 1,                                                            
        "status": "RUN_STATUS_SUCCEEDED"                                       
      }            
    },                                                                         
    {                                 
      "date": "2024-02-11",
      "metrics": {                                                             
        "count": 1,                                                            
        "status": "RUN_STATUS_SUCCEEDED"                                       
      }            
    },                                                                         
    {                                                                          
      "date": "2024-02-12",
      "metrics": {                                                             
        "count": 3,                                                            
        "status": "RUN_STATUS_SUCCEEDED"                                                                                                                            }                                                                        
    },
    {
      "date": "2024-02-13",
      "metrics": {
        "count": 2,
        "status": "RUN_STATUS_SUCCEEDED"
      }
    },
    {
      "date": "2024-02-14",
      "metrics": {
        "count": 3,
        "status": "RUN_STATUS_EXPIRED"
      }
...

Optionally it can be filtered by workflow_id

 grpcurl --plaintext -H "authorization: Bearer $TOKEN" -d '{"time_window": "METRICS_TIME_WINDOW_LAST_30_DAYS", "workflow_id": "0c497f60-de8d-402e-8caf-9975a61d4d14"}' localhost:9000 controlplane.v1.OrgMetricsService.DailyRunsCount

2 - Strong type existing metrics endpoints

Strongly type the runner and state aggregation fields used in the metrics endpoint.

controlplane.v1.OrgMetricsService.Totals

  "result": {
    "runsTotal": 97,
    "runsTotalByStatus": [
      {
        "count": 1,
        "status": "RUN_STATUS_FAILED"
      },
      {
        "count": 90,
        "status": "RUN_STATUS_SUCCEEDED"
      },
      {
        "count": 6,
        "status": "RUN_STATUS_EXPIRED"
      }
    ],
    "runsTotalByRunnerType": [
      {
        "count": 43,
        "runnerType": "DAGGER_PIPELINE"
      },
      {
        "count": 26,
        "runnerType": "GITLAB_PIPELINE"
      },
      {
        "count": 17,
        "runnerType": "GITHUB_ACTION"
      },
      {
        "count": 11
      }
    ]
  }
}

controlplane.v1.OrgMetricsService.TopWorkflowsByRunsCount

      "workflow": {                                                                                                                                                                           
        "id": "0c497f60-de8d-402e-8caf-9975a61d4d14",                                                                                                                                         
        "name": "build-and-test",                                                                                                                                                             
        "project": "chainloop-frontend",                                                                                                                                                      
        "team": "core",                                                                                                                                                                       
        "createdAt": "2022-11-27T17:04:06.071739Z",                                                                                                                                           
        "runsCount": 135                                                                                                                                                                      
      },                                                                                                                                                                                      
      "runsTotalByStatus": [                                                                                                                                                                  
        {                                                                                                                                                                                     
          "count": 6,                                                                                                                                                                         
          "status": "RUN_STATUS_EXPIRED"
        },
        {
          "count": 1,
          "status": "RUN_STATUS_FAILED"
        },
        {
          "count": 60,
          "status": "RUN_STATUS_SUCCEEDED"
        }
      ]
    },

cc/ @tknura
Closes #551

Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri
migmartri requested a review from danlishka March 8, 2024 21:50
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri migmartri changed the title chore(metrics): add types to metric responses feat(metrics): add runs by day and update returned types Mar 10, 2024

@danlishka danlishka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@migmartri
migmartri merged commit 674edbb into chainloop-dev:main Mar 11, 2024
@migmartri
migmartri deleted the update-metrics branch March 11, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(metrics): runs distributed in a time window

2 participants