mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-05-02 17:13:08 +00:00
Log outgoing Backend Interfaces requests.
This commit is contained in:
parent
2020732459
commit
4d2f9828bb
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -767,6 +767,7 @@ version = "4.6.0-test.1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"aes-kw",
|
"aes-kw",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"chirpstack_api",
|
||||||
"chrono",
|
"chrono",
|
||||||
"hex",
|
"hex",
|
||||||
"httpmock",
|
"httpmock",
|
||||||
|
@ -3,7 +3,7 @@ use std::sync::{Arc, RwLock};
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::config;
|
use crate::{config, stream};
|
||||||
use backend::{Client, ClientConfig};
|
use backend::{Client, ClientConfig};
|
||||||
use lrwn::{EUI64Prefix, EUI64};
|
use lrwn::{EUI64Prefix, EUI64};
|
||||||
|
|
||||||
@ -28,6 +28,9 @@ pub fn setup() -> Result<()> {
|
|||||||
tls_cert: js.tls_cert.clone(),
|
tls_cert: js.tls_cert.clone(),
|
||||||
tls_key: js.tls_key.clone(),
|
tls_key: js.tls_key.clone(),
|
||||||
async_timeout: js.async_timeout,
|
async_timeout: js.async_timeout,
|
||||||
|
request_log_fn: Some(Box::new(move |log| {
|
||||||
|
Box::pin(async move { stream::backend_interfaces::log_request(log).await })
|
||||||
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -8,8 +8,8 @@ use chrono::{Duration, DurationRound};
|
|||||||
use prost::Message;
|
use prost::Message;
|
||||||
use tracing::{debug, info, span, Level};
|
use tracing::{debug, info, span, Level};
|
||||||
|
|
||||||
use crate::config;
|
|
||||||
use crate::gpstime::ToGpsTime;
|
use crate::gpstime::ToGpsTime;
|
||||||
|
use crate::{config, stream};
|
||||||
use backend::{Client, ClientConfig, GWInfoElement, ULMetaData};
|
use backend::{Client, ClientConfig, GWInfoElement, ULMetaData};
|
||||||
use chirpstack_api::{common, gw};
|
use chirpstack_api::{common, gw};
|
||||||
use lrwn::{region, DevAddr, NetID, EUI64};
|
use lrwn::{region, DevAddr, NetID, EUI64};
|
||||||
@ -56,6 +56,9 @@ pub fn setup() -> Result<()> {
|
|||||||
Some(s.authorization_header.clone())
|
Some(s.authorization_header.clone())
|
||||||
},
|
},
|
||||||
async_timeout: s.async_timeout,
|
async_timeout: s.async_timeout,
|
||||||
|
request_log_fn: Some(Box::new(move |log| {
|
||||||
|
Box::pin(async move { stream::backend_interfaces::log_request(log).await })
|
||||||
|
})),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
set(&s.net_id, c);
|
set(&s.net_id, c);
|
||||||
@ -103,6 +106,9 @@ pub fn get(net_id: &NetID) -> Result<Arc<Client>> {
|
|||||||
Some(conf.roaming.default.authorization_header.clone())
|
Some(conf.roaming.default.authorization_header.clone())
|
||||||
},
|
},
|
||||||
async_timeout: conf.roaming.default.async_timeout,
|
async_timeout: conf.roaming.default.async_timeout,
|
||||||
|
request_log_fn: Some(Box::new(move |log| {
|
||||||
|
Box::pin(async move { stream::backend_interfaces::log_request(log).await })
|
||||||
|
})),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
return Ok(Arc::new(c));
|
return Ok(Arc::new(c));
|
||||||
|
@ -273,7 +273,12 @@ pub fn run() {
|
|||||||
#
|
#
|
||||||
# If not set, this endpoint will be disabled.
|
# If not set, this endpoint will be disabled.
|
||||||
bind="{{ monitoring.bind }}"
|
bind="{{ monitoring.bind }}"
|
||||||
|
|
||||||
|
# Backend Interfaces log max history.
|
||||||
|
#
|
||||||
|
# This defines the max number of Backend Interface request records that will be persisted
|
||||||
|
# in Redis Streams. Setting this value to 0 disables this features.
|
||||||
|
backend_interfaces_log_max_history={{ monitoring.backend_interfaces_log_max_history }}
|
||||||
|
|
||||||
# Meta-log max history.
|
# Meta-log max history.
|
||||||
#
|
#
|
||||||
|
@ -195,6 +195,7 @@ impl Default for Scheduler {
|
|||||||
pub struct Monitoring {
|
pub struct Monitoring {
|
||||||
pub bind: String,
|
pub bind: String,
|
||||||
pub api_request_log_max_history: usize,
|
pub api_request_log_max_history: usize,
|
||||||
|
pub backend_interfaces_log_max_history: usize,
|
||||||
pub meta_log_max_history: usize,
|
pub meta_log_max_history: usize,
|
||||||
pub gateway_frame_log_max_history: usize,
|
pub gateway_frame_log_max_history: usize,
|
||||||
pub device_frame_log_max_history: usize,
|
pub device_frame_log_max_history: usize,
|
||||||
@ -215,6 +216,7 @@ impl Default for Monitoring {
|
|||||||
Monitoring {
|
Monitoring {
|
||||||
bind: "".to_string(),
|
bind: "".to_string(),
|
||||||
api_request_log_max_history: 10,
|
api_request_log_max_history: 10,
|
||||||
|
backend_interfaces_log_max_history: 10,
|
||||||
meta_log_max_history: 10,
|
meta_log_max_history: 10,
|
||||||
gateway_frame_log_max_history: 10,
|
gateway_frame_log_max_history: 10,
|
||||||
device_frame_log_max_history: 10,
|
device_frame_log_max_history: 10,
|
||||||
|
34
chirpstack/src/stream/backend_interfaces.rs
Normal file
34
chirpstack/src/stream/backend_interfaces.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use prost::Message;
|
||||||
|
use tokio::task;
|
||||||
|
|
||||||
|
use crate::config;
|
||||||
|
use crate::storage::{get_redis_conn, redis_key};
|
||||||
|
use chirpstack_api::stream;
|
||||||
|
|
||||||
|
pub async fn log_request(pl: stream::BackendInterfacesRequest) -> Result<()> {
|
||||||
|
task::spawn_blocking({
|
||||||
|
move || -> Result<()> {
|
||||||
|
let conf = config::get();
|
||||||
|
let mut c = get_redis_conn()?;
|
||||||
|
|
||||||
|
if conf.monitoring.backend_interfaces_log_max_history == 0 {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = redis_key("backend_interfaces::stream::request".to_string());
|
||||||
|
let b = pl.encode_to_vec();
|
||||||
|
redis::cmd("XADD")
|
||||||
|
.arg(&key)
|
||||||
|
.arg("MAXLEN")
|
||||||
|
.arg(conf.monitoring.backend_interfaces_log_max_history)
|
||||||
|
.arg("*")
|
||||||
|
.arg("request")
|
||||||
|
.arg(&b)
|
||||||
|
.query(&mut *c)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await?
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
pub mod api_request;
|
pub mod api_request;
|
||||||
|
pub mod backend_interfaces;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod frame;
|
pub mod frame;
|
||||||
pub mod meta;
|
pub mod meta;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user