From 4d7da34595185cb4b1f4d8f1bc1cd9760bf183ed Mon Sep 17 00:00:00 2001 From: Hergy Fongue <23282107+rjtch@users.noreply.github.com> Date: Wed, 1 May 2024 15:23:11 +0200 Subject: [PATCH 1/9] =?UTF-8?q?=E2=9C=A8=20(cdviz-collectopr)=20http=20sin?= =?UTF-8?q?k=20sends=20cloudevents=20#21=20(#57)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added cloud-event converter in the sink * reworked http request in sink for cloud-event --------- Signed-off-by: Hergy Fongue Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: David Bernard --- cdviz-collector/Cargo.toml | 1 + cdviz-collector/src/sinks/http.rs | 49 ++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/cdviz-collector/Cargo.toml b/cdviz-collector/Cargo.toml index 2a606f7..8acaf56 100644 --- a/cdviz-collector/Cargo.toml +++ b/cdviz-collector/Cargo.toml @@ -15,6 +15,7 @@ publish = false axum = { version = "0.7", optional = true } axum-tracing-opentelemetry = { version = "0.18", optional = true } cdevents-sdk = { git = "https://github.com/cdevents/sdk-rust" } +cloudevents-sdk = { version = "0.7"} # cloudevents-sdk = { version = "0.7", features = ["axum"] } // not compatible with axum 0.7 chrono = "0.4" clap = { version = "4", features = ["derive", "env"] } diff --git a/cdviz-collector/src/sinks/http.rs b/cdviz-collector/src/sinks/http.rs index 0c12c03..2e32e12 100644 --- a/cdviz-collector/src/sinks/http.rs +++ b/cdviz-collector/src/sinks/http.rs @@ -1,3 +1,6 @@ +use cdevents_sdk::cloudevents::BuilderExt; +use cloudevents::{EventBuilder, EventBuilderV10}; +use cloudevents::binding::reqwest::RequestBuilderExt; use reqwest::Url; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use serde::{Deserialize, Serialize}; @@ -44,20 +47,38 @@ impl HttpSink { impl Sink for HttpSink { //TODO use cloudevents async fn send(&self, msg: &Message) -> Result<()> { - let json = serde_json::to_value(&msg.cdevent)?; - let resp = self - .client - .post(self.dest.clone()) - .json(&json) - .send() - .await?; - if !resp.status().is_success() { - tracing::warn!( - cdevent = ?msg.cdevent, - http_status = ?resp.status(), - "failed to send event" - ) - } + let cd_event = msg.cdevent.clone(); + // convert CdEvent to cloudevents + let event_result = EventBuilderV10::new().with_cdevent(cd_event.clone()); + match event_result { + Ok(event_builder) => { + let event_result = event_builder.build(); + let value = event_result.map_err(|e| { + tracing::warn!(error = ?e, "Failed to build event") + })?; + reqwest::Client::new() + .post(self.dest.clone()) + .event(value) + .map_err(|e| { + tracing::warn!(error = ?e, "Failed to build request-builder") + })? + .header("Access-Control-Allow-Origin", "*") + .send() + .await + .map_err(|e| { + tracing::warn!(error = ?e, "Failed to get response") + })?; + } + Err(err) => { + tracing::warn!(error = ?err, "Failed to convert to cloudevents"); + // In error case, send the original event + self.client + .post(self.dest.clone()) + .json(&cd_event) + .send() + .await?; + } + }; Ok(()) } } From a3021fe89090507c158dc897fc0453716c58ddd2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 15:24:17 +0200 Subject: [PATCH 2/9] Update Rust crate serde_with to 3.8.1 (#66) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- cdviz-collector/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdviz-collector/Cargo.toml b/cdviz-collector/Cargo.toml index 8acaf56..9a1e482 100644 --- a/cdviz-collector/Cargo.toml +++ b/cdviz-collector/Cargo.toml @@ -40,7 +40,7 @@ reqwest-middleware = "0.2" reqwest-tracing = "0.4" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -serde_with = "3.7" +serde_with = "3.8.1" sqlx = { version = "0.7", features = [ "postgres", "runtime-tokio", From 85dfe76e778f023f286027bd3d93d7c6e4707e95 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 15:25:01 +0200 Subject: [PATCH 3/9] Update Helm release grafana to v7.3.9 (#65) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- charts/cdviz/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/cdviz/Chart.yaml b/charts/cdviz/Chart.yaml index 232e86b..9cc2be4 100644 --- a/charts/cdviz/Chart.yaml +++ b/charts/cdviz/Chart.yaml @@ -12,7 +12,7 @@ dependencies: repository: oci://registry-1.docker.io/bitnamicharts condition: postgresql.enabled - name: grafana - version: 7.3.7 # grafana 10.2.2 + version: 7.3.9 # grafana 10.2.2 repository: https://grafana.github.io/helm-charts condition: grafana.enabled - name: cdviz-collector From b07c484d189e020b8e5857b9bb26b217b379f449 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 15:26:27 +0200 Subject: [PATCH 4/9] Update docker.io/grafana/grafana-oss Docker tag to v10.4.2 (#64) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- demos/stack-compose/docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/stack-compose/docker-compose.yaml b/demos/stack-compose/docker-compose.yaml index 49a1d9d..12a80ea 100644 --- a/demos/stack-compose/docker-compose.yaml +++ b/demos/stack-compose/docker-compose.yaml @@ -49,7 +49,7 @@ services: ports: - 5499:8080 grafana: - image: docker.io/grafana/grafana-oss:10.4.1 + image: docker.io/grafana/grafana-oss:10.4.2 container_name: grafana restart: unless-stopped environment: From 82407eadc0c3b221b319e904b9fadf8c51d163f6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 15:26:43 +0200 Subject: [PATCH 5/9] Update postgresql Docker tag to v15.2.7 (#59) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- charts/cdviz/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/cdviz/Chart.yaml b/charts/cdviz/Chart.yaml index 9cc2be4..6ab7277 100644 --- a/charts/cdviz/Chart.yaml +++ b/charts/cdviz/Chart.yaml @@ -7,7 +7,7 @@ appVersion: 0.1.0 # TODO Change this to a version number on release dependencies: - name: postgresql - version: 15.2.2 + version: 15.2.7 # repository: https://charts.bitnami.com/bitnami repository: oci://registry-1.docker.io/bitnamicharts condition: postgresql.enabled From c13b990dc0c9099b39e1d7dced0725f1d4f1b6b4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 1 May 2024 15:27:02 +0200 Subject: [PATCH 6/9] Update Rust crate rstest to 0.19.0 (#61) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- cdviz-collector/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdviz-collector/Cargo.toml b/cdviz-collector/Cargo.toml index 9a1e482..4c838b7 100644 --- a/cdviz-collector/Cargo.toml +++ b/cdviz-collector/Cargo.toml @@ -61,7 +61,7 @@ cdevents-sdk = { git = "https://github.com/cdevents/sdk-rust", features = [ "testkit", ] } proptest = "1" -rstest = "0.18" +rstest = "0.19.0" rustainers = "0.12" tracing-subscriber = "0.3" From d277eba7a4567400c756f29af8801fb3eea224d1 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Wed, 1 May 2024 18:26:28 +0200 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=91=B7=20update=20config=20of=20renov?= =?UTF-8?q?ate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- renovate.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/renovate.json b/renovate.json index 5db72dd..1f47a75 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,4 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:recommended" - ] + "extends": ["config:recommended", ":semanticCommitType(chore)"] } From 64b0756de68db83ce39b304d436a74abcfba26ba Mon Sep 17 00:00:00 2001 From: David Bernard Date: Wed, 1 May 2024 20:09:50 +0200 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=9A=A7=20fix=20compilation=20issue=20?= =?UTF-8?q?on=20cdviz-collector?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cdviz-collector/Cargo.toml | 2 +- cdviz-collector/src/errors.rs | 6 ++++++ cdviz-collector/src/sinks/http.rs | 20 +++++++------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cdviz-collector/Cargo.toml b/cdviz-collector/Cargo.toml index 4c838b7..8a832b3 100644 --- a/cdviz-collector/Cargo.toml +++ b/cdviz-collector/Cargo.toml @@ -15,7 +15,7 @@ publish = false axum = { version = "0.7", optional = true } axum-tracing-opentelemetry = { version = "0.18", optional = true } cdevents-sdk = { git = "https://github.com/cdevents/sdk-rust" } -cloudevents-sdk = { version = "0.7"} +cloudevents-sdk = { version = "0.7", features = ["reqwest"] } # cloudevents-sdk = { version = "0.7", features = ["axum"] } // not compatible with axum 0.7 chrono = "0.4" clap = { version = "4", features = ["derive", "env"] } diff --git a/cdviz-collector/src/errors.rs b/cdviz-collector/src/errors.rs index b80ec99..59d50da 100644 --- a/cdviz-collector/src/errors.rs +++ b/cdviz-collector/src/errors.rs @@ -22,6 +22,8 @@ pub(crate) enum Error { #[error(transparent)] Http(#[from] reqwest_middleware::Error), #[error(transparent)] + HttpReqwest(#[from] reqwest::Error), + #[error(transparent)] Json(#[from] serde_json::Error), #[cfg(feature = "source_opendal")] #[error(transparent)] @@ -37,6 +39,10 @@ pub(crate) enum Error { Io(#[from] std::io::Error), #[error(transparent)] ConfigReader(#[from] figment::Error), + #[error(transparent)] + CloudEventBuilder(#[from] cloudevents::event::EventBuilderError), + #[error(transparent)] + CloudEventMessage(#[from] cloudevents::message::Error), // #[error(transparent)] // ConfigTomlError(#[from] toml::de::Error), #[error("{txt}")] diff --git a/cdviz-collector/src/sinks/http.rs b/cdviz-collector/src/sinks/http.rs index 2e32e12..6458834 100644 --- a/cdviz-collector/src/sinks/http.rs +++ b/cdviz-collector/src/sinks/http.rs @@ -1,6 +1,6 @@ use cdevents_sdk::cloudevents::BuilderExt; -use cloudevents::{EventBuilder, EventBuilderV10}; use cloudevents::binding::reqwest::RequestBuilderExt; +use cloudevents::{EventBuilder, EventBuilderV10}; use reqwest::Url; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use serde::{Deserialize, Serialize}; @@ -53,21 +53,15 @@ impl Sink for HttpSink { match event_result { Ok(event_builder) => { let event_result = event_builder.build(); - let value = event_result.map_err(|e| { - tracing::warn!(error = ?e, "Failed to build event") - })?; + let value = event_result?; + //TODO use self.client (with middleware) reqwest::Client::new() .post(self.dest.clone()) - .event(value) - .map_err(|e| { - tracing::warn!(error = ?e, "Failed to build request-builder") - })? - .header("Access-Control-Allow-Origin", "*") + .event(value)? + //.map_err(|e| tracing::warn!(error = ?e, "Failed to build request-builder")) + //.header("Access-Control-Allow-Origin", "*") .send() - .await - .map_err(|e| { - tracing::warn!(error = ?e, "Failed to get response") - })?; + .await?; } Err(err) => { tracing::warn!(error = ?err, "Failed to convert to cloudevents"); From d27e8490ac4e814efe4ef011b3853ed918096fc1 Mon Sep 17 00:00:00 2001 From: David Bernard Date: Wed, 1 May 2024 20:14:50 +0200 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=9A=A7=20fix=20compilation=20issue=20?= =?UTF-8?q?on=20cdviz-collector=20(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cdviz-collector/Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cdviz-collector/Cargo.toml b/cdviz-collector/Cargo.toml index 8a832b3..3991cdf 100644 --- a/cdviz-collector/Cargo.toml +++ b/cdviz-collector/Cargo.toml @@ -15,11 +15,10 @@ publish = false axum = { version = "0.7", optional = true } axum-tracing-opentelemetry = { version = "0.18", optional = true } cdevents-sdk = { git = "https://github.com/cdevents/sdk-rust" } -cloudevents-sdk = { version = "0.7", features = ["reqwest"] } -# cloudevents-sdk = { version = "0.7", features = ["axum"] } // not compatible with axum 0.7 chrono = "0.4" clap = { version = "4", features = ["derive", "env"] } clap-verbosity-flag = "2.2.0" +cloudevents-sdk = { version = "0.7", features = ["reqwest"] } enum_dispatch = "0.3" figment = { version = "0.10", features = ["toml", "env"] } futures = "0.3"