-
Notifications
You must be signed in to change notification settings - Fork 1
feat: summary metric #47
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
8d84128
refactor: split metrics in modules
Karrq 07e6a68
chore: add justfile
Karrq 7387ffa
feat: summary metric
Karrq f1ba237
refactor: export 2 more items
Karrq a1b584c
feat(derive): Summary metric support
Karrq b6a51de
refactor(derive): quote fully qualified imports
Karrq e17c6ca
refactor(README): move examples under examples/
Karrq 270c28f
fix(derive): enforce metric help string
Karrq 8d5d4e0
chore: fmt
Karrq c3ab4af
fix(derive): error with invalid partitions config
Karrq db9d262
refactor(summary): split into more modules
Karrq 9e0dd73
feat(summary): batching summary
Karrq 6255729
Merge remote-tracking branch 'origin/main' into feat/summary
Karrq 7e7ea94
feat(derive): expand metrics with user path
Karrq 7c59f9b
chore: fmt
Karrq 9f9ceef
fix: clippy
Karrq da0d4d8
feat: `ArcCell`
Karrq c618c40
fix: BatchOpts, unnecessary const-hack
Karrq 4a1fbcb
fix: use appropriate parse_quote macro
Karrq 745fb80
docs(macro): ensure generated docs link to items
Karrq 103ae8b
fix(README): reintroduce basic (smaller) example
Karrq 1a4927b
test(batch): concurrent_observe
Karrq 85d4946
fix(arccell): account for outstanding loads
Karrq da57d6e
fix(batching): commit deadlock
Karrq 20ffb66
docs: clarify comment
Karrq 5b6d889
test(arccell): avoid concurrency noise
Karrq d570a62
refactor: use existing `arc-cell`
Karrq 890c27d
Update prometric/src/summary/batching.rs
Karrq 02ec8a3
test: remove tokio
Karrq 0869556
test: generic summary smoke tests
Karrq 622e2eb
feat: GenericSummaryMetric (cheap clone)
Karrq 765a260
chore: fmt
Karrq d91be06
fix: clippy
Karrq 3c03576
fix: pr review
Karrq aeb342d
docs: more comments in prometric-derive
Karrq 5837ce5
chore: fmt
Karrq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| default: check doc fmt clippy | ||
|
|
||
| check: | ||
| cargo check --workspace --all-features --all-targets | ||
|
|
||
| doc: | ||
| cargo doc --workspace --all-features --no-deps --document-private-items | ||
|
|
||
| clippy: | ||
| cargo +nightly clippy --all --all-features -- -D warnings | ||
|
|
||
| fmt: | ||
| cargo +nightly fmt --all -- --check | ||
|
|
||
| test: | ||
| cargo nextest run --workspace --all-features --retries 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| use prometric::{Counter, Gauge, Histogram, Summary}; | ||
| use prometric_derive::metrics; | ||
|
|
||
| // The `scope` attribute is used to set the prefix for the metric names in this struct. | ||
| #[metrics(scope = "app")] | ||
| struct AppMetrics { | ||
| /// The total number of HTTP requests. | ||
| #[metric(rename = "http_requests_total", labels = ["method", "path"])] | ||
| http_requests: Counter, | ||
|
|
||
| // For histograms, the `buckets` attribute is optional. It will default to | ||
| // [prometheus::DEFAULT_BUCKETS] if not provided. `buckets` can also be an expression that | ||
| // evaluates into a `Vec<f64>`. | ||
| /// The duration of HTTP requests. | ||
| #[metric(labels = ["method", "path"], buckets = [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0])] | ||
| http_requests_duration: Histogram, | ||
|
|
||
| /// The size fo HTTP requests. | ||
| #[metric(labels = ["method", "path"], quantiles = [0.0, 0.5, 0.9, 0.95, 0.99, 0.999, 1.0])] | ||
| http_request_sizes: Summary, | ||
|
|
||
| /// This doc comment will be overwritten by the `help` attribute. | ||
| #[metric(rename = "current_active_users", labels = ["service"], help = "The current number of active users.")] | ||
| current_users: Gauge, | ||
|
|
||
| /// The balance of the account, in dollars. Uses a floating point number. | ||
| #[metric(rename = "account_balance", labels = ["account_id"])] | ||
| account_balance: Gauge<f64>, | ||
|
|
||
| /// The total number of errors. | ||
| #[metric] | ||
| errors: Counter, | ||
| } | ||
|
|
||
| #[tokio::main(flavor = "current_thread")] | ||
| async fn main() { | ||
| // Build the metrics struct with static labels, which will initialize and register the metrics | ||
| // with the default registry. A custom registry can be used by passing it to the builder | ||
| // using `with_registry`. | ||
| let metrics = | ||
| AppMetrics::builder().with_label("host", "localhost").with_label("port", "8080").build(); | ||
|
|
||
| // Metric fields each get an accessor method generated, which can be used to interact with the | ||
| // metric. The arguments to the accessor method are the labels for the metric. | ||
| metrics.http_requests("GET", "/").inc(); | ||
| metrics.http_requests_duration("GET", "/").observe(1.0); | ||
| metrics.http_request_sizes("GET", "/").observe(12345); | ||
| metrics.current_users("service-1").set(10); | ||
| metrics.account_balance("1234567890").set(-12.2); | ||
| metrics.errors().inc(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use prometric::{Counter, Gauge}; | ||
| use prometric_derive::metrics; | ||
|
|
||
| #[metrics(scope = "app", static)] | ||
| struct AppMetrics { | ||
| /// The total number of requests. | ||
| #[metric(labels = ["method"])] | ||
| requests: Counter, | ||
|
|
||
| /// The current number of active connections. | ||
| #[metric] | ||
| active_connections: Gauge, | ||
| } | ||
|
|
||
| #[tokio::main(flavor = "current_thread")] | ||
| async fn main() { | ||
| // Use the static directly (the name is APP_METRICS in SCREAMING_SNAKE_CASE) | ||
| APP_METRICS.requests("GET").inc(); | ||
| APP_METRICS.active_connections().set(10); | ||
|
|
||
| // The following would not compile: | ||
| // let metrics = AppMetrics::builder(); // Error: builder() is private | ||
| // let metrics = AppMetrics::default(); // Error: Default is not implemented | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.