Skip to content

Commit

Permalink
Merge pull request #52 from iqlusioninc/configdd
Browse files Browse the repository at this point in the history
Add Datadog to config
  • Loading branch information
Shella authored Jan 11, 2024
2 parents 1fd9436 + 0675784 commit 27c1d79
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
5 changes: 4 additions & 1 deletion observatory.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ id = "stride-1"
validator_addr = "D542FA46ABFB3D29FE3E284D4380DE231A4791C8"
rpc_urls = [
"https://stride-rpc.polkachu.com/",
]
]

[datadog]
dd_api_key = "urdatadogapikeyhere"
14 changes: 13 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ pub struct ObservatoryConfig {
/// Chain configurations.
#[serde(rename = "chain")]
pub chains: Vec<ChainConfig>,

/// Datadog configuration
pub datadog: Option<DataDogConfig>,
}

/// Observatory Configuration
/// Chain Configuration
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct ChainConfig {
Expand All @@ -29,3 +32,12 @@ pub struct ChainConfig {
/// RPC URLs
pub rpc_urls: Vec<String>,
}


/// Datadog Configuration
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct DataDogConfig {
/// Datadog API Key
pub dd_api_key: Option<String>,
}
9 changes: 5 additions & 4 deletions src/datadog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
//!
//! **datadog.rs** is an API wrapper which provides support for sending HTTPS log
//! events and stream events to Datadog. Post Stream event enables Pagerduty integration.
//! Future work will include error report integration and datadog-agent support.
//! Currently very alpha, though iqlusion will test in prod.
//!
#![warn(missing_docs)]
use crate::{
prelude::*,
};
use hyper::{Body, Client, Method, Request};
use hyper_tls::HttpsConnector;
use serde::{ser, Serialize};
Expand Down Expand Up @@ -126,7 +127,7 @@ where
}
}

/// Send a log event to Datadog via HTTPS. Requires DD_API_KEY env variable set.
/// Send a log event to Datadog via HTTPS.
/// https://docs.datadoghq.com/api/v1/logs/#send-logs
pub async fn send_event(value: &Event, dd_api_key: String) -> Result<(), Error> {
let event = serde_json::to_string(&value).unwrap();
Expand All @@ -151,7 +152,7 @@ pub async fn send_event(value: &Event, dd_api_key: String) -> Result<(), Error>
}
}

/// Send a stream event to Datadog via HTTPS. Requires DD_API_KEY env variable set.
/// Send a stream event to Datadog via HTTPS.
/// https://docs.datadoghq.com/api/latest/events/#post-an-event
pub async fn send_stream_event(value: &StreamEvent, dd_api_key: String) -> Result<(), Error> {
let stream_event = serde_json::to_string(&value).unwrap();
Expand Down
10 changes: 7 additions & 3 deletions src/pager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::datadog::{send_stream_event, StreamEvent};
use crate::{
datadog::{send_stream_event, StreamEvent},
prelude::*,
};
use std::{
collections::BTreeMap as Map,
env,
fmt::{self, Debug},
future::Future,
pin::Pin,
Expand Down Expand Up @@ -48,7 +50,9 @@ async fn report_alarm(alarm: PagerAlarm) {
);

dbg!(&alarm);
let dd_api_key = env::var("DD_API_KEY").unwrap();
let config = APP.config();
let dd_config = config.datadog.as_ref().expect("no datadog config");
let dd_api_key = dd_config.dd_api_key.clone().expect("no datadog API key");
let hostname = hostname::get().unwrap();
let mut ddtags = Map::new();
ddtags.insert("env".to_owned(), "staging".to_owned());
Expand Down

0 comments on commit 27c1d79

Please sign in to comment.