Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate contract metrics when no contract or host filter is provided #802

Merged
merged 4 commits into from
Dec 8, 2023

Conversation

ChrisSchinnerl
Copy link
Member

When no filter for either contract id or host is provided, the contract metrics returned by the metrics endpoint will aggregate the spending within a period using the first metric for any given contract within the period.

@ChrisSchinnerl ChrisSchinnerl self-assigned this Dec 7, 2023
@ChrisSchinnerl ChrisSchinnerl marked this pull request as ready for review December 7, 2023 16:12
stores/metrics.go Show resolved Hide resolved
}
currentPeriod := int64(math.MinInt64)
err := tx.Raw(`
SELECT * FROM contracts
Copy link
Member

Choose a reason for hiding this comment

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

maybe reformat this raw query block to remove leading tabs/spaces and make the inner select more clear

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some indentation to make it look nicer but I'm not sure how to get rid of tabs while at the same time making it more clear by itself and with the surrounding code.

metrics = append(metrics, m.Metric)
currentPeriod = m.Period
} else {
metrics[len(metrics)-1] = metrics[len(metrics)-1].Aggregate(m.Metric)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not too sure but often with logic like this you have to perform this block outside of the loop to cover the last batch, is this one of those cases? e.g. do you need to call Aggregate on the last metric here after the loop on metricsWithPeriod?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is fine since every metric in the loop is either appended or aggregated. Looking at the test I also don't think there is anything missing at the end.

@ChrisSchinnerl ChrisSchinnerl merged commit 9994d3f into master Dec 8, 2023
6 checks passed
@ChrisSchinnerl ChrisSchinnerl deleted the chris/contract-metrics-no-filter branch December 8, 2023 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants