Add a new HTTP management API to toggle pageserver logs

This commit is contained in:
Kirill Bulatov
2023-01-10 13:39:45 +02:00
parent fcb905f519
commit 65fe6b5f90
16 changed files with 1085 additions and 86 deletions

View File

@@ -10,6 +10,7 @@ use serde_with::{serde_as, DisplayFromStr};
use utils::{
history_buffer::HistoryBufferWithDropCounter,
id::{NodeId, TenantId, TimelineId},
logging::{Directive, Level},
lsn::Lsn,
};
@@ -17,6 +18,52 @@ use crate::reltag::RelTag;
use anyhow::bail;
use bytes::{BufMut, Bytes, BytesMut};
/// A way to change pageserver's log level in runtime.
#[serde_as]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ChangeLogLevelRequest {
/// Arbitrary [`Directive`] string, in format `target[span{field=value}]=level`.
/// E.g. `error`, `pageserver=debug`, `[{tenant=98d670ab7bee6f0051494306a1ab888f}]=warn`
///
/// Note that you cannot have `,` in a [`Directive`], so `error,pageserver=debug` is not a valid directive.
Custom {
#[serde_as(as = "DisplayFromStr")]
directive: Directive,
/// `true` value applies the log level, `false` value removes it (if applied before)
enabled: bool,
},
/// A few pageserver-specific log filters, able to expande into [`Directive`].
Predefined {
/// `Some` value applies the log level, `None` value removes it (if applied before)
#[serde_as(as = "Option<DisplayFromStr>")]
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
log_level: Option<Level>,
/// A scope of the log level to apply to.
scope: Scope,
},
}
/// A scope in the pageserver, having the same log level.
#[serde_as]
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(tag = "kind")]
pub enum Scope {
/// Try to filter all logs with certain tenant_id field value span fields.
Tenant {
#[serde_as(as = "DisplayFromStr")]
tenant_id: TenantId,
},
/// Try to filter all logs with certain timeline_id in their span fields.
Timeline {
#[serde_as(as = "DisplayFromStr")]
tenant_id: TenantId,
#[serde_as(as = "DisplayFromStr")]
timeline_id: TimelineId,
},
}
/// A state of a tenant in pageserver's memory.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum TenantState {