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

External Logging #500

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

External Logging #500

wants to merge 12 commits into from

Conversation

lollerfirst
Copy link
Contributor

@lollerfirst lollerfirst commented Dec 12, 2024

Description

Defines a ElasticsearchLayer which implements Layer and can subscribe to tracing events and transmit them to ElasticSearch (specifically, another service might require another apposite Layer)

ElastiSearccLayer creates a multi producer single consumer channel and spawns a task that continuously attempts to receive log messages. In the Layer trait implementation on_event is called everytime a thread logs message and it write that message to the channel.

let api_key_header = api_key.map(|key| format!("ApiKey {}", key));

// Spawn an async task to process logs and send them to Elasticsearch.
tokio::spawn(async move {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be great to have the JoinHandle in the struct and to kill it on drop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea sorry for the delay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to move the handle in the ElasticsearchLayer object without wrapping it in a Option because there is always a task in this case. Wdyt?

@lollerfirst
Copy link
Contributor Author

lollerfirst commented Dec 15, 2024

Not quite sure how to test the API key in the "Authentication" header, since ElasticSearch won't mint one for me. It says some bullshit about the current license...

Currently only tested with http authentication embedded in the URL (e.g. http://elastic:password@localhost:9200) which is a bad auth.

@lollerfirst
Copy link
Contributor Author

Ok scrap that. Managed to get one.

@lollerfirst
Copy link
Contributor Author

Should we gate this under a feature?

@lollerfirst lollerfirst marked this pull request as ready for review December 16, 2024 09:54
Copy link
Collaborator

@thesimplekid thesimplekid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I have a mild preference for putting this behind a feature, but since its in mintd and not cdk and only adds deps we mostly already have from cdk not a strong one.

Should we add elasticsearch search to the docker-compose file with a few lines of docs of how to run it? Or what is the recommended way to run with elasticsearch?

Comment on lines +40 to +42
chrono = "0.4.39"
serde_json = "1.0.133"
reqwest = "0.12.9"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
chrono = "0.4.39"
serde_json = "1.0.133"
reqwest = "0.12.9"
chrono = "0.4.39"
serde_json = "1"
reqwest = "0.12"

Since for MSRV we need 24.3 of reqwest we should not set the patch version, cargo will use the lastest one we can.

This change plus rebasing onto main should fix the MSRV CI errors

Comment on lines +1 to +10
use chrono::Utc;
use reqwest::Client;
use serde::Serialize;
use std::fmt::Write;
use tokio::sync::mpsc::{self, Sender};
use tokio::task::JoinHandle;
use tracing::field::{Field, Visit};
use tracing::Event;
use tracing_subscriber::layer::{Context, Layer};
use tracing_subscriber::registry::LookupSpan;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use chrono::Utc;
use reqwest::Client;
use serde::Serialize;
use std::fmt::Write;
use tokio::sync::mpsc::{self, Sender};
use tokio::task::JoinHandle;
use tracing::field::{Field, Visit};
use tracing::Event;
use tracing_subscriber::layer::{Context, Layer};
use tracing_subscriber::registry::LookupSpan;
use std::fmt::Write;
use chrono::Utc;
use reqwest::Client;
use serde::Serialize;
use tokio::sync::mpsc::{self, Sender};
use tokio::task::JoinHandle;
use tracing::field::{Field, Visit};
use tracing::Event;
use tracing_subscriber::layer::{Context, Layer};
use tracing_subscriber::registry::LookupSpan;

Std imports should be first, this will fix formatting ci

@@ -58,6 +58,7 @@ uuid = { version = "1", features = ["v4", "serde"] }
# -Z minimal-versions
sync_wrapper = "0.1.2"
bech32 = "0.9.1"
chrono = "0.4.39"
Copy link
Collaborator

@thesimplekid thesimplekid Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports under the -Z minimal-versions are for the case where a dep of ours does not properly define their minimum deps I don't think that is the case here.

Do we need the dep in cdk I don't see where it is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I forgot to remove it because previously was working on cdk crate not cdk-mintd so that's left over from that..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants