Skip to content
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

fix(loki sink): Send auth header for healchecks #4604

Merged
merged 1 commit into from Oct 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/sinks/loki.rs
Expand Up @@ -196,7 +196,11 @@ impl HttpSink for LokiConfig {
async fn healthcheck(config: LokiConfig, mut client: HttpClient) -> crate::Result<()> {
let uri = format!("{}ready", config.endpoint);

let req = http::Request::get(uri).body(hyper::Body::empty()).unwrap();
let mut req = http::Request::get(uri).body(hyper::Body::empty()).unwrap();

if let Some(auth) = &config.auth {
auth.apply(&mut req);
}

let res = client.send(req).await?;

Expand All @@ -211,8 +215,10 @@ async fn healthcheck(config: LokiConfig, mut client: HttpClient) -> crate::Resul
mod tests {
use super::*;
use crate::sinks::util::http::HttpSink;
use crate::sinks::util::test::load_sink;
use crate::sinks::util::test::{build_test_server, load_sink};
use crate::test_util;
use crate::Event;
use futures::StreamExt;

#[test]
fn interpolate_labels() {
Expand Down Expand Up @@ -277,6 +283,46 @@ mod tests {

assert_eq!(record.labels[0], ("bar".to_string(), "bar".to_string()));
}

#[tokio::test]
async fn healthcheck_includes_auth() {
let (mut config, cx) = load_sink::<LokiConfig>(
r#"
endpoint = "http://localhost:3100"
labels = {test_name = "placeholder"}
auth.strategy = "basic"
auth.user = "username"
auth.password = "some_password"
"#,
)
.unwrap();

let addr = test_util::next_addr();
let endpoint = format!("http://{}", addr);
config.endpoint = endpoint
.clone()
.parse::<http::Uri>()
.expect("could not create URI")
.into();

let (rx, _trigger, server) = build_test_server(addr);
tokio::spawn(server);

let tls = TlsSettings::from_options(&config.tls).expect("could not create TLS settings");
let client = HttpClient::new(cx.resolver(), tls).expect("could not cerate HTTP client");

healthcheck(config.clone(), client)
.await
.expect("healthcheck failed");

let output = rx.take(1).collect::<Vec<_>>().await;
assert_eq!(
Some(&http::header::HeaderValue::from_static(
"Basic dXNlcm5hbWU6c29tZV9wYXNzd29yZA=="
)),
output[0].0.headers.get("authorization")
);
}
}

#[cfg(feature = "loki-integration-tests")]
Expand Down