Bump static-metric to 0.4 (#338)
Signed-off-by: Breezewish <me@breeswish.org>
This commit is contained in:
parent
e809d3fd30
commit
acef86b8ab
4
Makefile
4
Makefile
|
|
@ -1,3 +1,5 @@
|
|||
.PHONY: all build test dev bench format clean examples gen_proto
|
||||
|
||||
ENABLE_FEATURES ?= default
|
||||
|
||||
all: format build test examples
|
||||
|
|
@ -29,5 +31,3 @@ gen_proto:
|
|||
@ which protoc >/dev/null || { echo "Please install protoc first"; exit 1; }
|
||||
@ which protoc-gen-rust >/dev/null || { echo "Please install protobuf rust plugin, cargo install protobuf"; exit 1; }
|
||||
protoc --rust_out proto proto/metrics.proto
|
||||
|
||||
.PHONY: all examples
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
# Changelog for prometheus-static-metric
|
||||
|
||||
## 0.4.0
|
||||
|
||||
- Misc: Update dependencies (https://github.com/tikv/rust-prometheus/pull/289, https://github.com/tikv/rust-prometheus/pull/311)
|
||||
- Add: Local metric trait (https://github.com/tikv/rust-prometheus/pull/297)
|
||||
- Add: Auto-flushable thread local metrics (https://github.com/tikv/rust-prometheus/pull/304)
|
||||
- Add: Derive `Eq` and `Hash` for label enums (https://github.com/tikv/rust-prometheus/pull/317)
|
||||
|
||||
## 0.3.0
|
||||
|
||||
- Misc: Update the dependent Syn version (https://github.com/tikv/rust-prometheus/pull/268)
|
||||
- Misc: Requires rust-prometheus v0.7+ (https://github.com/tikv/rust-prometheus/pull/252)
|
||||
|
||||
## 0.2.0
|
||||
|
||||
- Add: Local static metric (https://github.com/tikv/rust-prometheus/pull/245)
|
||||
|
||||
## 0.1.4
|
||||
|
||||
- Add: Static metric enums support `get_str()` (https://github.com/tikv/rust-prometheus/pull/183)
|
||||
|
||||
## 0.1.3
|
||||
|
||||
- Change: Static metrics are now type safe (https://github.com/tikv/rust-prometheus/pull/182)
|
||||
|
||||
## 0.1.2
|
||||
|
||||
- Misc: Update the dependent Protobuf version (https://github.com/tikv/rust-prometheus/pull/181)
|
||||
|
||||
## 0.1.1
|
||||
|
||||
- Add: `register_static_xxx!` macros (https://github.com/tikv/rust-prometheus/pull/180)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "prometheus-static-metric"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
license = "Apache-2.0"
|
||||
authors = ["me@breeswish.org"]
|
||||
description = "Static metric helper utilities for rust-prometheus."
|
||||
|
|
@ -13,12 +13,17 @@ include = [
|
|||
"src/**/*.rs",
|
||||
]
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
static-metric-proc-macros = { path = "./proc-macros" }
|
||||
syn = { version = "1.0", features = ["full", "extra-traits"] }
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
lazy_static = "1.4"
|
||||
|
||||
[dev-dependencies]
|
||||
prometheus = { path = "../" }
|
||||
lazy_static = "1.4"
|
||||
prometheus = { version = "0.9", path = "../" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
.PHONY: all build test format bench clean examples
|
||||
|
||||
ENABLE_FEATURES ?= default
|
||||
|
||||
all: format build test examples
|
||||
|
|
@ -18,10 +20,11 @@ clean:
|
|||
cargo clean
|
||||
|
||||
examples:
|
||||
cargo build --example simple
|
||||
cargo build --example metric_enum
|
||||
cargo build --example with_lazy_static
|
||||
cargo build --example advanced
|
||||
cargo build --example local
|
||||
cargo build --example make_auto_flush_static_counter
|
||||
cargo build --example make_auto_flush_static_metric_histogram
|
||||
cargo build --example metric_enum
|
||||
cargo build --example register_integration
|
||||
|
||||
.PHONY: all
|
||||
cargo build --example simple
|
||||
cargo build --example with_lazy_static
|
||||
|
|
|
|||
|
|
@ -36,20 +36,18 @@ introducing a lot of templating code.
|
|||
|
||||
## Getting Started
|
||||
|
||||
+ Add to `Cargo.toml`:
|
||||
- Add to `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
prometheus-static-metric = "0.1"
|
||||
```
|
||||
```toml
|
||||
[dependencies]
|
||||
prometheus-static-metric = "0.4"
|
||||
```
|
||||
|
||||
+ Add to `lib.rs`:
|
||||
- Add to `lib.rs`:
|
||||
|
||||
```rust
|
||||
#![feature(proc_macro)]
|
||||
|
||||
extern crate prometheus_static_metric;
|
||||
```
|
||||
```rust
|
||||
extern crate prometheus_static_metric;
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
|
|
@ -162,6 +160,4 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
Please take a look at [examples](./examples) directory for more.
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
[package]
|
||||
name = "static-metric-proc-macros"
|
||||
version = "0.1.0"
|
||||
authors = ["Yilin Chen <sticnarf@gmail.com>"]
|
||||
edition = "2018"
|
||||
repository = "https://github.com/tikv/rust-prometheus"
|
||||
homepage = "https://github.com/tikv/rust-prometheus"
|
||||
license = "Apache-2.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
syn = { version = "1.0", features = ["full", "extra-traits"] }
|
||||
proc-macro2 = "1.0"
|
||||
quote = "1.0"
|
||||
lazy_static = "1.4"
|
||||
|
||||
[dev-dependencies]
|
||||
prometheus = { path = "../../" }
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
|
||||
|
||||
extern crate lazy_static;
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
extern crate syn;
|
||||
|
||||
mod auto_flush_builder;
|
||||
mod auto_flush_from;
|
||||
mod builder;
|
||||
mod parser;
|
||||
mod register_macro;
|
||||
mod util;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
use self::builder::TokensBuilder;
|
||||
use self::parser::StaticMetricMacroBody;
|
||||
use self::register_macro::RegisterMethodInvoking;
|
||||
use crate::auto_flush_from::AutoFlushFromDef;
|
||||
use auto_flush_builder::AutoFlushTokensBuilder;
|
||||
|
||||
/// Build static metrics.
|
||||
#[proc_macro]
|
||||
pub fn make_static_metric(input: TokenStream) -> TokenStream {
|
||||
let body: StaticMetricMacroBody = syn::parse(input).unwrap();
|
||||
TokensBuilder::build(body).into()
|
||||
}
|
||||
|
||||
/// Build auto flush able static metrics.
|
||||
/// refer to https://github.com/tikv/rust-prometheus/tree/master/static-metric for more info.
|
||||
#[proc_macro]
|
||||
pub fn make_auto_flush_static_metric(input: TokenStream) -> TokenStream {
|
||||
let body: StaticMetricMacroBody = syn::parse(input).unwrap();
|
||||
AutoFlushTokensBuilder::build(body).into()
|
||||
}
|
||||
|
||||
/// Instantiate a auto flush able static metric struct from a HistogramVec or CounterVec.
|
||||
#[proc_macro]
|
||||
pub fn auto_flush_from(input: TokenStream) -> TokenStream {
|
||||
let def: AutoFlushFromDef = syn::parse(input).unwrap();
|
||||
def.auto_flush_from().into()
|
||||
}
|
||||
|
||||
/// Register a `CounterVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_counter_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("counter", input)
|
||||
}
|
||||
|
||||
/// Register a `IntCounterVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_int_counter_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("int_counter", input)
|
||||
}
|
||||
|
||||
/// Register a `GaugeVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_gauge_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("gauge", input)
|
||||
}
|
||||
|
||||
/// Register a `IntGaugeVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_int_gauge_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("int_gauge", input)
|
||||
}
|
||||
|
||||
/// Register a `HistogramVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_histogram_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("histogram", input)
|
||||
}
|
||||
|
||||
/// Procedural macro handler for `register_static_xxx_vec!`.
|
||||
fn register_static_vec(register_type: &str, input: TokenStream) -> TokenStream {
|
||||
let invoking: RegisterMethodInvoking = syn::parse(input).unwrap();
|
||||
invoking.into_tokens(register_type).into()
|
||||
}
|
||||
|
|
@ -22,11 +22,82 @@ assert_eq!(HIGH_FIVE_COUNTER.get(), 1);
|
|||
Is it reccomended that you consult the [`prometheus` documentation for more information.](https://docs.rs/prometheus/)
|
||||
*/
|
||||
|
||||
extern crate static_metric_proc_macros;
|
||||
extern crate lazy_static;
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
extern crate syn;
|
||||
|
||||
pub use static_metric_proc_macros::auto_flush_from;
|
||||
pub use static_metric_proc_macros::{make_auto_flush_static_metric, make_static_metric};
|
||||
pub use static_metric_proc_macros::{
|
||||
register_static_counter_vec, register_static_gauge_vec, register_static_histogram_vec,
|
||||
register_static_int_counter_vec, register_static_int_gauge_vec,
|
||||
};
|
||||
mod auto_flush_builder;
|
||||
mod auto_flush_from;
|
||||
mod builder;
|
||||
mod parser;
|
||||
mod register_macro;
|
||||
mod util;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
use self::builder::TokensBuilder;
|
||||
use self::parser::StaticMetricMacroBody;
|
||||
use self::register_macro::RegisterMethodInvoking;
|
||||
use crate::auto_flush_from::AutoFlushFromDef;
|
||||
use auto_flush_builder::AutoFlushTokensBuilder;
|
||||
|
||||
/// Build static metrics.
|
||||
#[proc_macro]
|
||||
pub fn make_static_metric(input: TokenStream) -> TokenStream {
|
||||
let body: StaticMetricMacroBody = syn::parse(input).unwrap();
|
||||
TokensBuilder::build(body).into()
|
||||
}
|
||||
|
||||
/// Build auto flush able static metrics.
|
||||
/// refer to https://github.com/tikv/rust-prometheus/tree/master/static-metric for more info.
|
||||
#[proc_macro]
|
||||
pub fn make_auto_flush_static_metric(input: TokenStream) -> TokenStream {
|
||||
let body: StaticMetricMacroBody = syn::parse(input).unwrap();
|
||||
AutoFlushTokensBuilder::build(body).into()
|
||||
}
|
||||
|
||||
/// Instantiate a auto flush able static metric struct from a HistogramVec or CounterVec.
|
||||
#[proc_macro]
|
||||
pub fn auto_flush_from(input: TokenStream) -> TokenStream {
|
||||
let def: AutoFlushFromDef = syn::parse(input).unwrap();
|
||||
def.auto_flush_from().into()
|
||||
}
|
||||
|
||||
/// Register a `CounterVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_counter_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("counter", input)
|
||||
}
|
||||
|
||||
/// Register a `IntCounterVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_int_counter_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("int_counter", input)
|
||||
}
|
||||
|
||||
/// Register a `GaugeVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_gauge_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("gauge", input)
|
||||
}
|
||||
|
||||
/// Register a `IntGaugeVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_int_gauge_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("int_gauge", input)
|
||||
}
|
||||
|
||||
/// Register a `HistogramVec` and create static metrics from it.
|
||||
#[proc_macro]
|
||||
pub fn register_static_histogram_vec(input: TokenStream) -> TokenStream {
|
||||
register_static_vec("histogram", input)
|
||||
}
|
||||
|
||||
/// Procedural macro handler for `register_static_xxx_vec!`.
|
||||
fn register_static_vec(register_type: &str, input: TokenStream) -> TokenStream {
|
||||
let invoking: RegisterMethodInvoking = syn::parse(input).unwrap();
|
||||
invoking.into_tokens(register_type).into()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue