-
Notifications
You must be signed in to change notification settings - Fork 273
feat: project telemetry config models #1972
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b76bb94
feat: project telemetry config models
jonaro00 ccb4f5e
next steps
jonaro00 ce4c553
db type
jonaro00 3273ea3
use consistent snake case
jonaro00 8dedbb9
update models, bump typeshare
jonaro00 abddd15
simpler model names
jonaro00 ebfe9e4
add discriminant db type
jonaro00 0c64db5
chore(admin): add back beta access cmds
jonaro00 82f1004
nit: remove half-unused type alias
jonaro00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pub mod log; | |
pub mod project; | ||
pub mod resource; | ||
pub mod team; | ||
pub mod telemetry; | ||
pub mod user; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Status of a telemetry export configuration for an external sink | ||
#[derive(Eq, Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
#[typeshare::typeshare] | ||
pub struct TelemetrySinkStatus { | ||
/// Indicates that the associated project is configured to export telemetry data to this sink | ||
enabled: bool, | ||
} | ||
|
||
/// A safe-for-display representation of the current telemetry export configuration for a given project | ||
#[derive(Eq, Clone, Debug, Default, PartialEq, Serialize, Deserialize)] | ||
#[typeshare::typeshare] | ||
pub struct ProjectTelemetryConfigResponse { | ||
betterstack: Option<TelemetrySinkStatus>, | ||
datadog: Option<TelemetrySinkStatus>, | ||
grafana_cloud: Option<TelemetrySinkStatus>, | ||
} | ||
|
||
impl From<Vec<ProjectTelemetrySinkConfig>> for ProjectTelemetryConfigResponse { | ||
fn from(value: Vec<ProjectTelemetrySinkConfig>) -> Self { | ||
let mut instance = Self::default(); | ||
|
||
for sink in value { | ||
match sink { | ||
ProjectTelemetrySinkConfig::Betterstack(_) => { | ||
instance.betterstack = Some(TelemetrySinkStatus { enabled: true }) | ||
} | ||
ProjectTelemetrySinkConfig::Datadog(_) => { | ||
instance.datadog = Some(TelemetrySinkStatus { enabled: true }) | ||
} | ||
ProjectTelemetrySinkConfig::GrafanaCloud(_) => { | ||
instance.grafana_cloud = Some(TelemetrySinkStatus { enabled: true }) | ||
} | ||
} | ||
} | ||
|
||
instance | ||
} | ||
} | ||
jonaro00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// The user-supplied config required to export telemetry to a given external sink | ||
#[derive( | ||
Eq, Clone, PartialEq, Serialize, Deserialize, strum::AsRefStr, strum::EnumDiscriminants, | ||
)] | ||
#[serde(tag = "type", content = "content", rename_all = "snake_case")] | ||
#[strum(serialize_all = "snake_case")] | ||
#[typeshare::typeshare] | ||
#[strum_discriminants(derive(Serialize, Deserialize, strum::AsRefStr))] | ||
#[strum_discriminants(serde(rename_all = "snake_case"))] | ||
#[strum_discriminants(strum(serialize_all = "snake_case"))] | ||
pub enum ProjectTelemetrySinkConfig { | ||
/// [Betterstack](https://betterstack.com/docs/logs/open-telemetry/) | ||
Betterstack(BetterstackConfig), | ||
/// [Datadog](https://docs.datadoghq.com/opentelemetry/collector_exporter/otel_collector_datadog_exporter) | ||
Datadog(DatadogConfig), | ||
/// [Grafana Cloud](https://grafana.com/docs/grafana-cloud/send-data/otlp/) | ||
GrafanaCloud(GrafanaCloudConfig), | ||
} | ||
|
||
impl ProjectTelemetrySinkConfig { | ||
pub fn as_db_type(&self) -> String { | ||
format!("project::telemetry::{}::config", self.as_ref()) | ||
} | ||
jonaro00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#[derive(Eq, Clone, PartialEq, Serialize, Deserialize)] | ||
#[typeshare::typeshare] | ||
pub struct BetterstackConfig { | ||
pub source_token: String, | ||
} | ||
jonaro00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[derive(Eq, Clone, PartialEq, Serialize, Deserialize)] | ||
#[typeshare::typeshare] | ||
pub struct DatadogConfig { | ||
pub api_key: String, | ||
} | ||
#[derive(Eq, Clone, PartialEq, Serialize, Deserialize)] | ||
#[typeshare::typeshare] | ||
pub struct GrafanaCloudConfig { | ||
pub token: String, | ||
pub endpoint: String, | ||
pub instance_id: String, | ||
jonaro00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn sink_config_enum() { | ||
assert_eq!( | ||
"betterstack", | ||
ProjectTelemetrySinkConfig::Betterstack(BetterstackConfig { | ||
source_token: "".into() | ||
}) | ||
.as_ref() | ||
); | ||
assert_eq!( | ||
"project::telemetry::betterstack::config", | ||
ProjectTelemetrySinkConfig::Betterstack(BetterstackConfig { | ||
source_token: "".into() | ||
}) | ||
.as_db_type() | ||
); | ||
|
||
assert_eq!( | ||
"betterstack", | ||
ProjectTelemetrySinkConfigDiscriminants::Betterstack.as_ref() | ||
); | ||
assert_eq!( | ||
"grafana_cloud", | ||
ProjectTelemetrySinkConfigDiscriminants::GrafanaCloud.as_ref() | ||
); | ||
assert_eq!( | ||
"\"betterstack\"", | ||
serde_json::to_string(&ProjectTelemetrySinkConfigDiscriminants::Betterstack).unwrap() | ||
); | ||
assert_eq!( | ||
"\"grafana_cloud\"", | ||
serde_json::to_string(&ProjectTelemetrySinkConfigDiscriminants::GrafanaCloud).unwrap() | ||
); | ||
} | ||
jonaro00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.