-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feature(enterprise): configurable app name #18554
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
Changes from 11 commits
99c53bb
a105d7d
9625858
39b9c7b
94decfe
2f2f4e7
aad4c20
20c1b08
0a69f0e
2cc23ac
fad4306
798fcca
b9b5543
698f525
790a97a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -984,6 +984,7 @@ skywalking | |
| slashin | ||
| slf | ||
| slideover | ||
| slugified | ||
| smallvec | ||
| smartphone | ||
| Smol | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,6 +124,35 @@ pub use source_sender::SourceSender; | |
| pub use vector_common::{shutdown, Error, Result}; | ||
| pub use vector_core::{event, metrics, schema, tcp, tls}; | ||
|
|
||
| /// The name used to identify this Vector application. | ||
| /// | ||
| /// This can be set at compile-time through the VECTOR_APP_NAME env variable. | ||
| /// Defaults to "Vector". | ||
| pub fn get_app_name(#[cfg(feature = "enterprise")] enterprise_enabled: bool) -> &'static str { | ||
| #[cfg(not(feature = "enterprise"))] | ||
| let default_app_name = "Vector"; | ||
| #[cfg(feature = "enterprise")] | ||
| let default_app_name = if enterprise_enabled { | ||
| "Vector Enterprise" | ||
| } else { | ||
| "Vector" | ||
| }; | ||
|
|
||
| option_env!("VECTOR_APP_NAME").unwrap_or(default_app_name) | ||
| } | ||
|
|
||
| /// Returns a slugified version of the name used to identify this Vector application. | ||
| /// | ||
| /// Defaults to "vector". | ||
| pub fn get_slugified_app_name(#[cfg(feature = "enterprise")] enterprise_enabled: bool) -> String { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this something we are going to fetch repeatedly? If so, and it can't ever change after the first lookup, a once cell might be warranted here. |
||
| get_app_name( | ||
| #[cfg(feature = "enterprise")] | ||
| enterprise_enabled, | ||
| ) | ||
| .to_lowercase() | ||
| .replace(' ', "-") | ||
| } | ||
|
|
||
| /// The current version of Vector in simplified format. | ||
| /// `<version-number>-nightly`. | ||
| pub fn vector_version() -> impl std::fmt::Display { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,20 +95,33 @@ pub struct LogApiService { | |
| client: HttpClient, | ||
| uri: Uri, | ||
| user_provided_headers: IndexMap<HeaderName, HeaderValue>, | ||
| default_headers: IndexMap<HeaderName, HeaderValue>, | ||
| } | ||
|
|
||
| impl LogApiService { | ||
| pub fn new( | ||
| client: HttpClient, | ||
| uri: Uri, | ||
| headers: IndexMap<String, String>, | ||
| dd_evp_origin: String, | ||
| ) -> crate::Result<Self> { | ||
| let headers = validate_headers(&headers)?; | ||
| let user_provided_headers = validate_headers(&headers)?; | ||
|
|
||
| // Note that these headers cannot be overriden by the user. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this documented?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. I'm not sure if we'd want to document this. The user should never want to modify these values unless for some nefarious reasons. |
||
| let default_headers = &[ | ||
| (CONTENT_TYPE.to_string(), "application/json".to_string()), | ||
| ("DD-EVP-ORIGIN".to_string(), dd_evp_origin), | ||
| ("DD-EVP-ORIGIN-VERSION".to_string(), crate::get_version()), | ||
| ] | ||
| .into_iter() | ||
| .collect(); | ||
| let default_headers = validate_headers(default_headers)?; | ||
|
|
||
| Ok(Self { | ||
| client, | ||
| uri, | ||
| user_provided_headers: headers, | ||
| user_provided_headers, | ||
| default_headers, | ||
| }) | ||
| } | ||
| } | ||
|
|
@@ -126,11 +139,8 @@ impl Service<LogApiRequest> for LogApiService { | |
| // Emission of Error internal event is handled upstream by the caller | ||
| fn call(&mut self, mut request: LogApiRequest) -> Self::Future { | ||
| let mut client = self.client.clone(); | ||
| let http_request = Request::post(&self.uri) | ||
| .header(CONTENT_TYPE, "application/json") | ||
| .header("DD-EVP-ORIGIN", "vector") | ||
| .header("DD-EVP-ORIGIN-VERSION", crate::get_version()) | ||
| .header("DD-API-KEY", request.api_key.to_string()); | ||
| let http_request = | ||
| Request::post(&self.uri).header("DD-API-KEY", request.api_key.to_string()); | ||
|
|
||
| let http_request = if let Some(ce) = request.compression.content_encoding() { | ||
| http_request.header(CONTENT_ENCODING, ce) | ||
|
|
@@ -149,6 +159,9 @@ impl Service<LogApiRequest> for LogApiService { | |
| // Replace rather than append to any existing header values | ||
| headers.insert(name, value.clone()); | ||
| } | ||
| for (name, value) in &self.default_headers { | ||
| headers.insert(name, value.clone()); | ||
| } | ||
| } | ||
|
|
||
| let http_request = http_request | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.