Skip to content

Commit

Permalink
Setup prost
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd committed Jan 26, 2021
1 parent e1b197b commit fb2837d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Expand Up @@ -19,9 +19,10 @@ features = ["nightly"]

[features]
default = ["protobuf"]
gen = ["protobuf-codegen-pure"]
gen = ["prost-build"]
nightly = ["libc"]
process = ["libc", "procfs"]
protobuf = ["prost", "prost-types"]
push = ["reqwest", "libc", "protobuf"]

[dependencies]
Expand All @@ -30,7 +31,8 @@ fnv = "^1.0"
lazy_static = "^1.4"
libc = { version = "^0.2", optional = true }
parking_lot = "^0.11"
protobuf = { version = "^2.0", optional = true }
prost = { version = "^0.7", optional = true }
prost-types = { version = "^0.7", optional = true }
regex = "^1.3"
reqwest = { version = "^0.11", features = ["blocking"], optional = true }
thiserror = "^1.0"
Expand All @@ -45,6 +47,7 @@ hyper = { version = "^0.14", features = ["server", "http1", "tcp"] }
tokio = { version = "^1.0", features = ["macros", "rt-multi-thread"] }

[build-dependencies]
prost-build = { versopm = "^0.7", optional = true }
protobuf-codegen-pure = { version = "^2.0", optional = true }

[workspace]
Expand Down
13 changes: 6 additions & 7 deletions build.rs
Expand Up @@ -2,13 +2,12 @@

#[cfg(feature = "gen")]
fn generate_protobuf_binding_file() {
protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
out_dir: "proto",
input: &["proto/proto_model.proto"],
includes: &["proto"],
..Default::default()
})
.unwrap();
use prost_build::Config;
use std::path::Path;

let mut cfg = Config::new();
cfg.out_dir(Path::new("proto"));
cfg.compile_protos(&["proto/proto_model.proto"], &["proto"]).unwrap();
}

#[cfg(not(feature = "gen"))]
Expand Down
94 changes: 94 additions & 0 deletions proto/io.prometheus.client.rs
@@ -0,0 +1,94 @@
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LabelPair {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, optional, tag="2")]
pub value: ::core::option::Option<::prost::alloc::string::String>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Gauge {
#[prost(double, optional, tag="1")]
pub value: ::core::option::Option<f64>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Counter {
#[prost(double, optional, tag="1")]
pub value: ::core::option::Option<f64>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Quantile {
#[prost(double, optional, tag="1")]
pub quantile: ::core::option::Option<f64>,
#[prost(double, optional, tag="2")]
pub value: ::core::option::Option<f64>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Summary {
#[prost(uint64, optional, tag="1")]
pub sample_count: ::core::option::Option<u64>,
#[prost(double, optional, tag="2")]
pub sample_sum: ::core::option::Option<f64>,
#[prost(message, repeated, tag="3")]
pub quantile: ::prost::alloc::vec::Vec<Quantile>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Untyped {
#[prost(double, optional, tag="1")]
pub value: ::core::option::Option<f64>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Histogram {
#[prost(uint64, optional, tag="1")]
pub sample_count: ::core::option::Option<u64>,
#[prost(double, optional, tag="2")]
pub sample_sum: ::core::option::Option<f64>,
/// Ordered in increasing order of upper_bound, +Inf bucket is optional.
#[prost(message, repeated, tag="3")]
pub bucket: ::prost::alloc::vec::Vec<Bucket>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Bucket {
/// Cumulative in increasing order.
#[prost(uint64, optional, tag="1")]
pub cumulative_count: ::core::option::Option<u64>,
/// Inclusive.
#[prost(double, optional, tag="2")]
pub upper_bound: ::core::option::Option<f64>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Metric {
#[prost(message, repeated, tag="1")]
pub label: ::prost::alloc::vec::Vec<LabelPair>,
#[prost(message, optional, tag="2")]
pub gauge: ::core::option::Option<Gauge>,
#[prost(message, optional, tag="3")]
pub counter: ::core::option::Option<Counter>,
#[prost(message, optional, tag="4")]
pub summary: ::core::option::Option<Summary>,
#[prost(message, optional, tag="5")]
pub untyped: ::core::option::Option<Untyped>,
#[prost(message, optional, tag="7")]
pub histogram: ::core::option::Option<Histogram>,
#[prost(int64, optional, tag="6")]
pub timestamp_ms: ::core::option::Option<i64>,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct MetricFamily {
#[prost(string, optional, tag="1")]
pub name: ::core::option::Option<::prost::alloc::string::String>,
#[prost(string, optional, tag="2")]
pub help: ::core::option::Option<::prost::alloc::string::String>,
#[prost(enumeration="MetricType", optional, tag="3")]
pub r#type: ::core::option::Option<i32>,
#[prost(message, repeated, tag="4")]
pub metric: ::prost::alloc::vec::Vec<Metric>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum MetricType {
Counter = 0,
Gauge = 1,
Summary = 2,
Untyped = 3,
Histogram = 4,
}

0 comments on commit fb2837d

Please sign in to comment.