Skip to content

Commit 5704125

Browse files
authored
Merge pull request #33 from kpn-dsh/hotfix/add-missing-reexport
Hotfix/add missing reexport
2 parents b9d5cc6 + 09f72df commit 5704125

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [0.3.0] - unreleased
8+
9+
## [0.3.1] - 2024-03-25
10+
11+
### Fixed
12+
- Add missing prometheus export back to the SDK
13+
14+
## [0.3.0] - yanked - 2024-03-25
915

1016
### Changed
1117
- Metrics http server based on Hyper instead of Warp

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license = "Apache-2.0"
1212
name = "dsh_sdk"
1313
readme = "README.md"
1414
repository = "https://github.com/kpn-dsh/dsh-sdk-platform-rs"
15-
version = "0.3.0"
15+
version = "0.3.1"
1616

1717
[package.metadata.docs.rs]
1818
features = ["full"]

examples/custom_metrics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use dsh_sdk::metrics::*;
2-
use prometheus::{register_int_gauge_vec, IntGaugeVec};
32

43
lazy_static! {
54
pub static ref HIGH_FIVE_COUNTER: IntCounter =

src/metrics.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,13 @@ use hyper::{header, Method, Request, Response, StatusCode};
6060
use hyper_util::rt::TokioIo;
6161
pub use lazy_static::lazy_static;
6262
use log::{error, warn};
63-
pub use prometheus::register_int_counter;
64-
use prometheus::Encoder;
65-
pub use prometheus::IntCounter;
63+
pub use prometheus::*;
6664
use tokio::net::TcpListener;
6765
use tokio::task::JoinHandle;
6866

6967
use crate::error::DshError;
7068

71-
type Result<T> = std::result::Result<T, DshError>;
69+
type DshResult<T> = std::result::Result<T, DshError>;
7270
type BoxBody = http_body_util::combinators::BoxBody<Bytes, hyper::Error>;
7371

7472
static NOTFOUND: &[u8] = b"404: Not Found";
@@ -121,7 +119,7 @@ static NOTFOUND: &[u8] = b"404: Not Found";
121119
/// }
122120
/// }
123121
/// ```
124-
pub fn start_http_server(port: u16) -> JoinHandle<Result<()>> {
122+
pub fn start_http_server(port: u16) -> JoinHandle<DshResult<()>> {
125123
tokio::spawn(async move {
126124
let result = run_server(port).await;
127125
warn!("HTTP server stopped: {:?}", result);
@@ -130,15 +128,15 @@ pub fn start_http_server(port: u16) -> JoinHandle<Result<()>> {
130128
}
131129

132130
/// Encode metrics to a string (UTF8)
133-
pub fn metrics_to_string() -> Result<String> {
131+
pub fn metrics_to_string() -> DshResult<String> {
134132
let encoder = prometheus::TextEncoder::new();
135133

136134
let mut buffer = Vec::new();
137135
encoder.encode(&prometheus::gather(), &mut buffer)?;
138136
Ok(String::from_utf8(buffer)?)
139137
}
140138

141-
async fn run_server(port: u16) -> Result<()> {
139+
async fn run_server(port: u16) -> DshResult<()> {
142140
let addr = SocketAddr::from(([0, 0, 0, 0], port));
143141
let listener = TcpListener::bind(addr).await?;
144142

@@ -157,21 +155,21 @@ async fn handle_connection(stream: tokio::net::TcpStream) {
157155
}
158156
}
159157

160-
async fn routes(req: Request<Incoming>) -> Result<Response<BoxBody>> {
158+
async fn routes(req: Request<Incoming>) -> DshResult<Response<BoxBody>> {
161159
match (req.method(), req.uri().path()) {
162160
(&Method::GET, "/metrics") => get_metrics(),
163161
(_, _) => not_found(),
164162
}
165163
}
166164

167-
fn get_metrics() -> Result<Response<BoxBody>> {
165+
fn get_metrics() -> DshResult<Response<BoxBody>> {
168166
Ok(Response::builder()
169167
.status(StatusCode::OK)
170168
.header(header::CONTENT_TYPE, prometheus::TEXT_FORMAT)
171169
.body(full(metrics_to_string().unwrap_or_default()))?)
172170
}
173171

174-
fn not_found() -> Result<Response<BoxBody>> {
172+
fn not_found() -> DshResult<Response<BoxBody>> {
175173
Ok(Response::builder()
176174
.status(StatusCode::NOT_FOUND)
177175
.body(full(NOTFOUND))?)

0 commit comments

Comments
 (0)