Skip to content

[API-142] Power api metrics from api_metrics_* tables - #572

Merged
raymondjacobson merged 8 commits into
mainfrom
rj-finalize-metrics
Nov 14, 2025
Merged

raymondjacobson merged 8 commits into
mainfrom
rj-finalize-metrics

Conversation

@raymondjacobson

Copy link
Copy Markdown
Member

Remove old queries + usage of old discovery node tables

Manually wrote migrations to bring over old data from existing aggregate_* tables

Tested via running protocol dashboard against local api server
image

image image

Comment thread api/v1_metrics_apps.go Outdated
Name: metric.Name,
Count: metric.Count,
result := []AppMetric{}
for rows.Next() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason you're preferring the manual iteration/scan here or is it just what the AI chose?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yaaa, ill use collectrows good call

{"year", "year", 100},
}

for _, tt := range tests {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ooooo generated test cases let's go

Comment thread api/v1_metrics_routes.go Outdated
}

type GetMetricsRoutesQueryParams struct {
BucketSize string `query:"bucket_size" default:"day"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oneof validation on this?

Comment thread api/v1_metrics_routes.go
// Exclude current incomplete week
dateRangeClause = dateRangeClause + " AND date_trunc('week', date) < date_trunc('week', CURRENT_DATE)"
case "month":
bucketClause = "date_trunc('month', date)::date::text AS bucket"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that double cast is fun

Comment thread api/v1_metrics_routes.go
}

type GetMetricsRoutesTrailingRouteParams struct {
TimeRange string `params:"time_range" default:"month"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

optional nit: validation/oneof

{"all_time_day", "all_time", "day"},
{"year_month", "year", "month"},
{"month_day", "month", "day"},
{"week_day", "week", "day"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need any tests for invalid combinations here? Are there invalid combinations?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yeah I guess "week_month" works, but makes almost no sense... however, i doesn't actually error. it just gives you what you want - a weeks' worth of data bucketed to the nearest month

@raymondjacobson
raymondjacobson merged commit d53ddb9 into main Nov 14, 2025
5 checks passed
@raymondjacobson
raymondjacobson deleted the rj-finalize-metrics branch November 14, 2025 18:27
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.

2 participants