#72 Add request_duration_seconds metric

Merged
mrngm merged 3 commits from metrics into master 1 month ago
Owner

This PR adds a new request_duration_seconds metrics, which records a histogram of the request latency, partitioned by status code and HTTP method.

This PR also refactors other parts of the metrics.go file.

This PR adds a new `request_duration_seconds` metrics, which records a histogram of the request latency, partitioned by status code and HTTP method. This PR also refactors other parts of the `metrics.go` file.
dsprenkels added 1 commit 2 months ago
dsprenkels force-pushed metrics from 46f26664a4 to ea8c22c37c 2 months ago
dsprenkels force-pushed metrics from ea8c22c37c to 0321bb72dc 2 months ago
mrngm approved these changes 1 month ago
metrics.go
// partitioned by type and state.
//
// Its values are computed on the fly by updateMetrics().
var metricURLsTotalGauge = prometheus.NewGaugeVec(
mrngm commented 1 month ago

(technically, the PR is for request_duration_seconds, so anything other than that should be omitted... or change the PR title and description)

(technically, the PR is for `request_duration_seconds`, so anything other than that should be omitted... or change the PR title and description)
mrngm marked this conversation as resolved
metrics.go
for state := db.PasteStateUndef; state <= db.PasteStateDeleted; state++ {
for ty := db.PasteTypeUndef; ty <= db.PasteTypeFileUpload; ty++ {
var count int64
query := mh.db.Unscoped().Model(&db.Paste{}).Where("type = ? AND state = ?", ty, state).Count(&count)
mrngm commented 1 month ago

Is it possible to query the database once, yielding all counts for all types and states?

Is it possible to query the database once, yielding all counts for all types and states?
dsprenkels commented 1 month ago

I tried to find this, but thought it was not not possible. I have retried searching for this and found this: https://stackoverflow.com/a/19046871/5207081
That would fix this.

I tried to find this, but thought it was not not possible. I have retried searching for this and found this: https://stackoverflow.com/a/19046871/5207081 That would fix this.
mrngm commented 1 month ago

Ran this query on the test migration database:

sqlite> SELECT type, state, COUNT(*) FROM pastes GROUP BY type, state;
0|2|136  // type: undef      state: deleted
2|1|118  // type: redirect   state: present
3|1|1376 // type: fileupload state: present

Would that roughly be what you expect to get here?

Ran this query on the test migration database: ``` sqlite> SELECT type, state, COUNT(*) FROM pastes GROUP BY type, state; 0|2|136 // type: undef state: deleted 2|1|118 // type: redirect state: present 3|1|1376 // type: fileupload state: present ``` Would that roughly be what you expect to get here?
dsprenkels marked this conversation as resolved
mrngm requested changes 1 month ago
mrngm left a comment

See the other review comments.

dsprenkels force-pushed metrics from 0321bb72dc to c4ff0ab1b7 1 month ago
dsprenkels added 1 commit 1 month ago
dsprenkels force-pushed metrics from ccd9d2f110 to 306705cb28 1 month ago
mrngm approved these changes 1 month ago
mrngm merged commit 29ee3dc6fd into master 1 month ago
mrngm commented 1 month ago
Collaborator

Live.

Live.
dsprenkels deleted branch metrics 1 month ago

Reviewers

mrngm approved these changes 1 month ago
The pull request has been merged as 29ee3dc6fd.
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.