#2 Update to hyper 0.12
Merged 5 years ago by ignatenkobrain. Opened 5 years ago by rfairley.
rpms/ rfairley/rust-prometheus rfairley-update-hyper  into  master

@@ -1,7 +0,0 @@ 

- Rename `examples/example_hyper.rs` -> `examples/example_hyper.rs.bak`

- so the file does not get picked up by the build.

- 

- diff --git a/examples/example_hyper.rs b/examples/example_hyper.rs.bak

- similarity index 100%

- rename from examples/example_hyper.rs

- rename to examples/example_hyper.rs.bak

@@ -0,0 +1,62 @@ 

+ diff --git a/examples/example_hyper.rs b/examples/example_hyper.rs

+ index c9d02bc..a6eda1b 100644

+ --- a/examples/example_hyper.rs

+ +++ b/examples/example_hyper.rs

+ @@ -16,9 +16,7 @@ extern crate lazy_static;

+  #[macro_use]

+  extern crate prometheus;

+  

+ -use hyper::header::ContentType;

+ -use hyper::mime::Mime;

+ -use hyper::server::{Request, Response, Server};

+ +use hyper::{header::CONTENT_TYPE, rt::Future, service::service_fn_ok, Body, Response, Server};

+  

+  use prometheus::{Counter, Encoder, Gauge, HistogramVec, TextEncoder};

+  

+ @@ -44,24 +42,35 @@ lazy_static! {

+  }

+  

+  fn main() {

+ -    let encoder = TextEncoder::new();

+ -    let addr = "127.0.0.1:9898";

+ -    println!("listening addr {:?}", addr);

+ -    Server::http(addr)

+ -        .unwrap()

+ -        .handle(move |_: Request<'_, '_>, mut res: Response<'_>| {

+ +    let addr = ([127, 0, 0, 1], 9898).into();

+ +    println!("Listening address: {:?}", addr);

+ +

+ +    let new_service = || {

+ +        let encoder = TextEncoder::new();

+ +        service_fn_ok(move |_request| {

+              HTTP_COUNTER.inc();

+              let timer = HTTP_REQ_HISTOGRAM.with_label_values(&["all"]).start_timer();

+  

+              let metric_families = prometheus::gather();

+              let mut buffer = vec![];

+              encoder.encode(&metric_families, &mut buffer).unwrap();

+ -            res.headers_mut()

+ -                .set(ContentType(encoder.format_type().parse::<Mime>().unwrap()));

+ -            res.send(&buffer).unwrap();

+ +            HTTP_BODY_GAUGE.set(buffer.len() as f64);

+ +

+ +            let response = Response::builder()

+ +                .status(200)

+ +                .header(CONTENT_TYPE, encoder.format_type())

+ +                .body(Body::from(buffer))

+ +                .unwrap();

+  

+              timer.observe_duration();

+ -            HTTP_BODY_GAUGE.set(buffer.len() as f64);

+ +

+ +            response

+          })

+ -        .unwrap();

+ +    };

+ +

+ +    let server = Server::bind(&addr)

+ +        .serve(new_service)

+ +        .map_err(|e| eprintln!("Server error: {}", e));

+ +

+ +    hyper::rt::run(server);

+  }

file modified
+4 -15
@@ -1,25 +1,14 @@ 

  diff --git a/Cargo.toml b/Cargo.toml

- index 44f5796..4997818 100644

+ index 44f5796..d77f9eb 100644

  --- a/Cargo.toml

  +++ b/Cargo.toml

- @@ -15,6 +15,7 @@ edition = "2018"

-  name = "prometheus"

-  version = "0.6.1"

-  authors = ["overvenus@gmail.com", "siddontang@gmail.com", "vistaswx@gmail.com"]

- +exclude = ["examples/example_hyper.rs"]

-  description = "Prometheus instrumentation library for Rust applications."

-  homepage = "https://github.com/pingcap/rust-prometheus"

-  documentation = "https://docs.rs/prometheus"

- @@ -53,9 +54,9 @@ version = "0.5"

-  [dev-dependencies.getopts]

+ @@ -54,8 +54,7 @@ version = "0.5"

   version = "0.2"

   

- -[dev-dependencies.hyper]

+  [dev-dependencies.hyper]

  -version = "0.9"

  -default-features = false

- +#[dev-dependencies.hyper]

- +#version = "0.9"

- +#default-features = false

+ +version = "0.12"

   [build-dependencies.protobuf-codegen-pure]

   version = "2.0"

   optional = true

file modified
+8 -7
@@ -6,17 +6,17 @@ 

  

  Name:           rust-%{crate}

  Version:        0.6.1

- Release:        1%{?dist}

+ Release:        2%{?dist}

  Summary:        Prometheus instrumentation library for Rust applications

  

  # Upstream license specification: Apache-2.0

  License:        ASL 2.0

  URL:            https://crates.io/crates/prometheus

  Source:         %{crates_source}

- # examples/example_hyper.rs is excluded to remove dependency on hyper,

- # and hyper is removed from package metadata

+ # Fix manifest to update to hyper 0.12

  Patch0:         prometheus-fix-manifest.diff

- Patch0001:      0001-rename-example-hyper.diff

+ # See: https://github.com/pingcap/rust-prometheus/pull/249

+ Patch0001:      0001-update-example-hyper.diff

  # See: https://github.com/pingcap/rust-prometheus/pull/246

  Patch0002:      0002-fix-should-panic-tests.diff

  
@@ -35,9 +35,7 @@ 

  BuildRequires:  (crate(spin/default) >= 0.5.0 with crate(spin/default) < 0.6.0)

  %if %{with check}

  BuildRequires:  (crate(getopts/default) >= 0.2.0 with crate(getopts/default) < 0.3.0)

- # Temporarily remove dependency on hyper, until https://github.com/pingcap/rust-prometheus/pull/219

- # lands upstream.

- # BuildRequires:  (crate(hyper) >= 0.9.0 with crate(hyper) < 0.10.0)

+ BuildRequires:  (crate(hyper) >= 0.12.0 with crate(hyper) < 0.13.0)

  %endif

  %endif

  
@@ -196,5 +194,8 @@ 

  %endif

  

  %changelog

+ * Mon Jun 17 10:50:00 UTC 2019 Robert Fairley <rfairley@redhat.com> - 0.6.1-2

+ - Update to hyper 0.12 (https://github.com/pingcap/rust-prometheus/pull/249)

+ 

  * Mon Jun 10 19:00:25 UTC 2019 Robert Fairley <rfairley@redhat.com> - 0.6.1-1

  - Initial package (#1717614)