This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
add webhooks function (Http, SlackIncomingWebhook) #259
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use crate::config_path::find_file_in_wa; | ||
use serde::Deserialize; | ||
use std::fs::File; | ||
use std::{collections::HashMap, fs::File}; | ||
use tracing::{debug, error}; | ||
|
||
const CONFIG_FILE_NAME: &str = "wave-config.yaml"; | ||
|
@@ -18,6 +18,10 @@ const DEFAULT_WEB_UI: bool = true; | |
const DEFAULT_WEB_UI_HOST: &str = "0.0.0.0"; | ||
const DEFAULT_WEB_UI_PORT: u16 = 3025; | ||
const DEFAULT_RESET_DEFINITIONS_ON_STARTUP: bool = false; | ||
const DEFAULT_WEBHOOKS: Option<Vec<Webhooks>> = None; | ||
const DEFAULT_WEBHOOKS_URL: Option<String> = None; | ||
const DEFAULT_WEBHOOKS_HEADERS: Option<HashMap<String, String>> = None; | ||
const DEFAULT_WEBHOOKS_WEBHOOK_URL: Option<String> = None; | ||
|
||
fn default_debug() -> bool { | ||
DEFAULT_DEBUG | ||
|
@@ -58,6 +62,18 @@ fn default_web_ui_port() -> u16 { | |
fn default_reset_definitions_on_startup() -> bool { | ||
DEFAULT_RESET_DEFINITIONS_ON_STARTUP | ||
} | ||
fn default_webhooks() -> Option<Vec<Webhooks>> { | ||
DEFAULT_WEBHOOKS | ||
} | ||
fn default_webhooks_url() -> Option<String> { | ||
DEFAULT_WEBHOOKS_URL | ||
} | ||
fn default_webhooks_headers() -> Option<HashMap<String, String>> { | ||
DEFAULT_WEBHOOKS_HEADERS | ||
} | ||
fn default_webhooks_webhook_url() -> Option<String> { | ||
DEFAULT_WEBHOOKS_WEBHOOK_URL | ||
} | ||
|
||
#[derive(Debug, PartialEq, Deserialize, Default, Clone)] | ||
struct DownloadUrlDefinition { | ||
|
@@ -127,6 +143,31 @@ pub struct WaveConfig { | |
vector: DownloadUrlDefinition, | ||
#[serde(default)] | ||
telegraf: DownloadUrlDefinition, | ||
|
||
// | ||
// Web hooks | ||
// | ||
#[serde(default = "default_webhooks")] | ||
pub webhooks: Option<Vec<Webhooks>>, | ||
} | ||
|
||
#[derive(PartialEq, Clone, Deserialize, Debug)] | ||
pub struct Webhooks { | ||
pub id: String, | ||
pub webhook_type: WebhookType, | ||
#[serde(default = "default_webhooks_url")] | ||
pub url: Option<String>, | ||
#[serde(default = "default_webhooks_headers")] | ||
pub headers: Option<HashMap<String, String>>, | ||
#[serde(default = "default_webhooks_webhook_url")] | ||
pub webhook_url: Option<String>, | ||
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. merge webhook_url with url |
||
} | ||
|
||
#[derive(Debug, PartialEq, Deserialize, Clone)] | ||
pub enum WebhookType { | ||
Http, | ||
SlackIncomingWebhook, | ||
// SlackOauth, // TODO: To be developed. | ||
} | ||
|
||
impl Default for WaveConfig { | ||
|
@@ -147,6 +188,7 @@ impl Default for WaveConfig { | |
web_ui_port: DEFAULT_WEB_UI_PORT, | ||
vector: DownloadUrlDefinition::default(), | ||
telegraf: DownloadUrlDefinition::default(), | ||
webhooks: DEFAULT_WEBHOOKS, | ||
} | ||
} | ||
} | ||
|
@@ -227,5 +269,6 @@ mod tests { | |
assert_eq!(wave_config.web_ui, DEFAULT_WEB_UI); | ||
assert_eq!(wave_config.web_ui_host, DEFAULT_WEB_UI_HOST); | ||
assert_eq!(wave_config.web_ui_port, DEFAULT_WEB_UI_PORT); | ||
assert_eq!(wave_config.webhooks, DEFAULT_WEBHOOKS); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -21,7 +21,11 @@ pub struct App { | |
} | ||
|
||
impl App { | ||
pub async fn new(wave_config: WaveConfig, shared_data_layer: Arc<DataLayer>) -> Self { | ||
pub async fn new( | ||
wave_config: WaveConfig, | ||
shared_data_layer: Arc<DataLayer>, | ||
webhooks: Option<Vec<utils::wave_config::Webhooks>>, | ||
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. remove the webhooks and reuse the wave_config |
||
) -> Self { | ||
// Create MetricUpdater | ||
let shared_metric_updater = MetricUpdater::new_shared(shared_data_layer.clone(), 1000); | ||
|
||
|
@@ -33,6 +37,7 @@ impl App { | |
shared_data_layer.clone(), | ||
shared_metric_updater.clone(), | ||
shared_scaling_component_manager.clone(), | ||
webhooks, | ||
); | ||
|
||
// Create App | ||
|
This file contains 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 |
---|---|---|
|
@@ -86,7 +86,12 @@ async fn main() { | |
} | ||
|
||
// Run the main application(controller) | ||
let mut app = app::App::new(wave_config.clone(), shared_data_layer.clone()).await; | ||
let mut app = app::App::new( | ||
wave_config.clone(), | ||
shared_data_layer.clone(), | ||
wave_config.webhooks.clone(), | ||
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. remove the line |
||
) | ||
.await; | ||
|
||
// | ||
// Run some jobs (Autoscaling History Remover, Reset definitions on startup, Watch the definition file, and the main application(controller)) | ||
|
This file contains 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 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore the upper or the lower cases