-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea8bfe8
commit 68b109e
Showing
25 changed files
with
909 additions
and
3 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
load("@crate_index_dre//:defs.bzl", "aliases", "all_crate_deps") | ||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test", "rust_library") | ||
load("@//rs:oci_images.bzl", "rust_binary_oci_image_rules") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
DEPS = [] | ||
|
||
rust_library( | ||
name = "log-noise-filter-backend-lib", | ||
srcs = glob(["src/**/*.rs"]), | ||
aliases = aliases(), | ||
crate_name = "log_noise_filter_backend", | ||
proc_macro_deps = all_crate_deps( | ||
proc_macro = True, | ||
), | ||
deps = all_crate_deps( | ||
normal = True, | ||
) + DEPS, | ||
) | ||
|
||
BINARY_DEPS = [ | ||
":log-noise-filter-backend-lib", | ||
] | ||
|
||
rust_binary( | ||
name = "log-noise-filter-backend", | ||
srcs = glob(["src/**/*.rs"]), | ||
aliases = aliases(), | ||
proc_macro_deps = all_crate_deps( | ||
proc_macro = True, | ||
), | ||
stamp = 1, | ||
deps = all_crate_deps( | ||
normal = True, | ||
) + DEPS + BINARY_DEPS, | ||
) | ||
|
||
rust_test( | ||
name = "unit_test", | ||
aliases = aliases( | ||
normal_dev = True, | ||
proc_macro_dev = True, | ||
), | ||
crate = ":log-noise-filter-backend-lib", | ||
proc_macro_deps = all_crate_deps( | ||
proc_macro_dev = True, | ||
), | ||
deps = all_crate_deps( | ||
normal_dev = True, | ||
) + DEPS, | ||
) | ||
|
||
rust_binary_oci_image_rules( | ||
name = "oci_image", | ||
src = ":log-noise-filter-backend", | ||
base_image = "@debian-slim" | ||
) | ||
|
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "log-noise-filter-backend" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
description.workspace = true | ||
documentation.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { workspace = true } | ||
axum = { workspace = true } | ||
slog = { workspace = true } | ||
slog-async = { workspace = true } | ||
slog-term = { workspace = true } | ||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
tokio = { workspace = true } | ||
regex = { workspace = true } | ||
|
||
[[bin]] | ||
name = "log-noise-filter-backend" | ||
path = "src/main.rs" | ||
|
||
[lib] | ||
name = "log_noise_filter_backend" | ||
path = "src/lib.rs" |
22 changes: 22 additions & 0 deletions
22
rs/ic-observability/log-noise-filter-backend/src/handlers/criteria/delete_criteria.rs
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use axum::{extract::State, http::StatusCode, Json}; | ||
use slog::{info, warn}; | ||
|
||
use crate::handlers::Server; | ||
|
||
pub async fn delete_criteria( | ||
State(state): State<Server>, | ||
Json(criteria): Json<Vec<u32>>, | ||
) -> Result<Json<BTreeMap<u32, String>>, (StatusCode, String)> { | ||
match state.delete_criteria(criteria.clone()).await { | ||
Ok(()) => { | ||
info!(state.logger, "Deleted criteria"; "indexes" => ?criteria); | ||
Ok(Json(state.get_criteria_mapped().await)) | ||
} | ||
Err(missing) => { | ||
warn!(state.logger, "Failed to delete criteria"; "indexes" => ?missing); | ||
Err((StatusCode::NOT_FOUND, format!("Missing indexes: {:?}", missing))) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
rs/ic-observability/log-noise-filter-backend/src/handlers/criteria/get_criteria.rs
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use axum::http::StatusCode; | ||
use axum::{extract::State, Json}; | ||
|
||
use crate::handlers::Server; | ||
|
||
pub(crate) async fn get_criteria(State(state): State<Server>) -> Result<Json<BTreeMap<u32, String>>, (StatusCode, String)> { | ||
Ok(Json(state.get_criteria_mapped().await)) | ||
} |
3 changes: 3 additions & 0 deletions
3
rs/ic-observability/log-noise-filter-backend/src/handlers/criteria/mod.rs
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod delete_criteria; | ||
pub mod get_criteria; | ||
pub mod post_criteria; |
12 changes: 12 additions & 0 deletions
12
rs/ic-observability/log-noise-filter-backend/src/handlers/criteria/post_criteria.rs
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use axum::{extract::State, http::StatusCode, Json}; | ||
|
||
use crate::handlers::Server; | ||
|
||
pub async fn update(State(state): State<Server>, Json(criteria): Json<Vec<String>>) -> Result<Json<BTreeMap<u32, String>>, (StatusCode, String)> { | ||
match state.update_criteria(criteria).await { | ||
Ok(()) => Ok(Json(state.get_criteria_mapped().await)), | ||
Err(v) => Err((StatusCode::BAD_REQUEST, format!("Invalid instances of regex: {:?}", v))), | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
rs/ic-observability/log-noise-filter-backend/src/handlers/get_all.rs
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use axum::{extract::State, http::StatusCode, Json}; | ||
|
||
use super::{Server, WholeState}; | ||
|
||
pub async fn get_all(State(server): State<Server>) -> Result<Json<WholeState>, (StatusCode, String)> { | ||
let state = WholeState { | ||
criteria: server.get_criteria_mapped().await, | ||
rate: server.get_rate().await, | ||
}; | ||
|
||
Ok(Json(state)) | ||
} |
Oops, something went wrong.