Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ observability:
otlp:
enabled: false
endpoint: "http://127.0.0.1:4317"
# Optional User-Agent -> client_type mapping rules for the
# aisix_llm_tokens_by_client_total metric. Tried in order (first match
# wins) BEFORE the built-in client allowlist, so you can classify
# in-house tools or re-bucket a built-in match. `pattern` is a regex
# (max 512 bytes), matched case-insensitively and unanchored against
# the raw User-Agent; `client` is the fixed label value emitted on
# match ([a-z0-9][a-z0-9._-]*, max 64 chars; max 64 rules). Validated at
# boot; changes require a restart. The metric label set stays bounded:
# only these fixed values (plus built-ins / "other" / "unknown") are
# ever emitted — never the raw User-Agent.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
# client_type_rules:
# - pattern: "^py-billing-batcher/"
# client: billing-batcher
# - pattern: "internal-eval-harness"
# client: eval-harness
tracing:
otlp:
enabled: false
Expand Down
7 changes: 7 additions & 0 deletions config.managed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ observability:
addr: "0.0.0.0:9090"
otlp:
enabled: false
# Optional User-Agent -> client_type mapping rules for the
# aisix_llm_tokens_by_client_total metric (first match wins, tried
# before the built-in allowlist; regex, case-insensitive). See
# config.example.yaml for the full annotation.
# client_type_rules:
# - pattern: "^py-billing-batcher/"
# client: billing-batcher
tracing:
otlp:
enabled: false
Expand Down
20 changes: 20 additions & 0 deletions crates/aisix-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,26 @@ impl ObservabilityConfig {
pub struct MetricsConfig {
pub prometheus: PrometheusConfig,
pub otlp: OtlpConfig,
/// Operator-defined User-Agent → `client_type` mapping rules
/// (AISIX-Cloud#1045), consulted BEFORE the built-in allowlist so a
/// deployment can classify in-house tools (or re-bucket a built-in
/// match). Deployment-scoped on purpose: the labels these rules mint
/// go to this DP's own Prometheus scrape surface, so the operator who
/// owns the scrape owns the label set. Order matters (first match
/// wins); compiled + validated at boot (fail-fast), never hot-reloaded.
pub client_type_rules: Vec<ClientTypeRule>,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

/// One `client_type_rules` entry: a regex tried against the raw inbound
/// `User-Agent` (case-insensitive, unanchored — anchor with `^` yourself),
/// and the bounded label value emitted on match. The label — not the UA —
/// becomes the Prometheus `client_type` value, so cardinality stays capped
/// by the rule count.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ClientTypeRule {
pub pattern: String,
pub client: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
6 changes: 3 additions & 3 deletions crates/aisix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pub mod version;
pub mod wildcard;

pub use config::{
AdminConfig, CacheBackend, CacheConfig, Config, EtcdConfig, EtcdTlsConfig, ManagedConfig,
ObservabilityConfig, ProxyConfig, RateLimitBackend, RateLimitConfig, RealIpConfig,
RedisConnConfig, RedisMode, TlsConfig,
AdminConfig, CacheBackend, CacheConfig, ClientTypeRule, Config, EtcdConfig, EtcdTlsConfig,
ManagedConfig, ObservabilityConfig, ProxyConfig, RateLimitBackend, RateLimitConfig,
RealIpConfig, RedisConnConfig, RedisMode, TlsConfig,
};
pub use config_status::{
hash_bytes, hash_entries, AppliedSnapshot, ConfigMetricsView, ConfigState, ConfigStatus,
Expand Down
1 change: 1 addition & 0 deletions crates/aisix-obs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tracing.workspace = true
tracing-subscriber.workspace = true
metrics.workspace = true
metrics-exporter-prometheus.workspace = true
regex.workspace = true
thiserror.workspace = true
async-trait.workspace = true
serde.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/aisix-obs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};

pub use access_log::AccessLog;
pub use metrics::{
client_type_from_user_agent, BudgetGauges, BudgetLabels, DeploymentLabels, DeploymentState,
LatencyLabels, LlmUsage, Metrics, RequestLabels, RequestOutcome, UsageLabels,
client_type_from_user_agent, BudgetGauges, BudgetLabels, ClientTypeClassifier,
DeploymentLabels, DeploymentState, LatencyLabels, LlmUsage, Metrics, RequestLabels,
RequestOutcome, UsageLabels,
};
pub use otlp::{install_otlp_tracer, shutdown_otlp, OtlpError, OtlpHandle};
pub use otlp_http_sink::{content_capture_cap, OtlpHttpFanOut, OtlpSink};
Expand Down
Loading
Loading