294 lines
9.8 KiB
Rust
294 lines
9.8 KiB
Rust
//! Business-level metrics for platform operations.
|
|
//!
|
|
//! Provides `metrics::counter!` and `metrics::gauge!` calls for all
|
|
//! business events (projects, issues, PRs, rooms, repos, billing).
|
|
//! Counter names are registered in `install_recorder()` so they appear
|
|
//! in Prometheus exposition format.
|
|
//!
|
|
//! Service layer code should call `incr!()` after successful operations.
|
|
|
|
/// Increment a business counter by 1.
|
|
/// Calls `metrics::counter!` from within the observability crate so
|
|
/// calling crates don't need `metrics` as a direct dependency.
|
|
#[macro_export]
|
|
macro_rules! incr {
|
|
($name:expr) => {
|
|
$crate::increment_business_counter($name)
|
|
};
|
|
}
|
|
|
|
/// Function wrapper so the `metrics::counter!` macro is only invoked
|
|
/// inside the observability crate (which depends on `metrics`).
|
|
pub fn increment_business_counter(name: &'static str) {
|
|
metrics::counter!(name);
|
|
}
|
|
|
|
// ── Counter names (constants) ──────────────────────────────────────────────────
|
|
|
|
// Project
|
|
pub const PROJECTS_CREATED_TOTAL: &str = "projects_created_total";
|
|
pub const PROJECTS_DELETED_TOTAL: &str = "projects_deleted_total";
|
|
pub const PROJECT_MEMBERS_ADDED_TOTAL: &str = "project_members_added_total";
|
|
pub const PROJECT_MEMBERS_REMOVED_TOTAL: &str = "project_members_removed_total";
|
|
pub const PROJECT_MEMBERS_ROLE_CHANGED_TOTAL: &str = "project_members_role_changed_total";
|
|
pub const PROJECT_LIKES_TOTAL: &str = "project_likes_total";
|
|
pub const PROJECT_UNLIKES_TOTAL: &str = "project_unlikes_total";
|
|
pub const PROJECT_WATCHES_TOTAL: &str = "project_watches_total";
|
|
pub const PROJECT_UNWATCHES_TOTAL: &str = "project_unwatches_total";
|
|
|
|
// Issue
|
|
pub const ISSUES_OPENED_TOTAL: &str = "issues_opened_total";
|
|
pub const ISSUES_CLOSED_TOTAL: &str = "issues_closed_total";
|
|
pub const ISSUES_REOPENED_TOTAL: &str = "issues_reopened_total";
|
|
pub const ISSUES_DELETED_TOTAL: &str = "issues_deleted_total";
|
|
pub const ISSUES_UPDATED_TOTAL: &str = "issues_updated_total";
|
|
pub const ISSUE_COMMENTS_CREATED_TOTAL: &str = "issue_comments_created_total";
|
|
pub const ISSUE_COMMENTS_DELETED_TOTAL: &str = "issue_comments_deleted_total";
|
|
|
|
// Pull Request
|
|
pub const PRS_OPENED_TOTAL: &str = "prs_opened_total";
|
|
pub const PRS_MERGED_TOTAL: &str = "prs_merged_total";
|
|
pub const PRS_CLOSED_TOTAL: &str = "prs_closed_total";
|
|
pub const PRS_UPDATED_TOTAL: &str = "prs_updated_total";
|
|
pub const PR_REVIEWS_SUBMITTED_TOTAL: &str = "pr_reviews_submitted_total";
|
|
pub const PR_REVIEW_COMMENTS_TOTAL: &str = "pr_review_comments_total";
|
|
|
|
// Room
|
|
pub const ROOMS_CREATED_TOTAL: &str = "rooms_created_total";
|
|
pub const ROOMS_DELETED_TOTAL: &str = "rooms_deleted_total";
|
|
pub const ROOMS_UPDATED_TOTAL: &str = "rooms_updated_total";
|
|
pub const ROOM_MESSAGES_SENT_TOTAL: &str = "room_messages_sent_total";
|
|
pub const ROOM_MESSAGES_AI_TOTAL: &str = "room_messages_ai_total";
|
|
pub const ROOM_THREADS_CREATED_TOTAL: &str = "room_threads_created_total";
|
|
|
|
// Repo / Git
|
|
pub const REPOS_CREATED_TOTAL: &str = "repos_created_total";
|
|
pub const GIT_COMMITS_PUSHED_TOTAL: &str = "git_commits_pushed_total";
|
|
pub const GIT_BRANCHES_CREATED_TOTAL: &str = "git_branches_created_total";
|
|
pub const GIT_BRANCHES_DELETED_TOTAL: &str = "git_branches_deleted_total";
|
|
pub const GIT_TAGS_CREATED_TOTAL: &str = "git_tags_created_total";
|
|
pub const GIT_TAGS_DELETED_TOTAL: &str = "git_tags_deleted_total";
|
|
pub const GIT_CLONES_TOTAL: &str = "git_clones_total";
|
|
|
|
// Billing
|
|
pub const BILLING_CREDITS_USED_TOTAL: &str = "billing_credits_used_total";
|
|
pub const BILLING_ERRORS_TOTAL: &str = "billing_errors_total";
|
|
pub const BILLING_CREDITS_ADDED_TOTAL: &str = "billing_credits_added_total";
|
|
|
|
// AI (supplements existing ai_* counters)
|
|
pub const AI_ROOM_CALLS_TOTAL: &str = "ai_room_calls_total";
|
|
pub const AI_CHAT_CONVERSATIONS_CREATED: &str = "ai_chat_conversations_created_total";
|
|
pub const AI_CHAT_MESSAGES_SENT: &str = "ai_chat_messages_sent_total";
|
|
|
|
// ── Gauge names ─────────────────────────────────────────────────────────────────
|
|
|
|
pub const ACTIVE_CONNECTIONS: &str = "active_connections";
|
|
pub const ACTIVE_ROOM_PARTICIPANTS: &str = "active_room_participants";
|
|
|
|
/// Register all business metric descriptions.
|
|
/// Called from `install_recorder()` in `prometheus_exporter.rs`.
|
|
pub fn describe_business_metrics() {
|
|
// Project
|
|
metrics::describe_counter!(
|
|
PROJECTS_CREATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Projects created"
|
|
);
|
|
metrics::describe_counter!(
|
|
PROJECTS_DELETED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Projects deleted"
|
|
);
|
|
metrics::describe_counter!(
|
|
PROJECT_MEMBERS_ADDED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Project members added"
|
|
);
|
|
metrics::describe_counter!(
|
|
PROJECT_MEMBERS_REMOVED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Project members removed"
|
|
);
|
|
metrics::describe_counter!(
|
|
PROJECT_MEMBERS_ROLE_CHANGED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Project member role changes"
|
|
);
|
|
metrics::describe_counter!(PROJECT_LIKES_TOTAL, metrics::Unit::Count, "Project likes");
|
|
metrics::describe_counter!(
|
|
PROJECT_UNLIKES_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Project unlikes"
|
|
);
|
|
metrics::describe_counter!(
|
|
PROJECT_WATCHES_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Project watches"
|
|
);
|
|
metrics::describe_counter!(
|
|
PROJECT_UNWATCHES_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Project unwatches"
|
|
);
|
|
|
|
// Issue
|
|
metrics::describe_counter!(ISSUES_OPENED_TOTAL, metrics::Unit::Count, "Issues opened");
|
|
metrics::describe_counter!(ISSUES_CLOSED_TOTAL, metrics::Unit::Count, "Issues closed");
|
|
metrics::describe_counter!(
|
|
ISSUES_REOPENED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Issues reopened"
|
|
);
|
|
metrics::describe_counter!(ISSUES_DELETED_TOTAL, metrics::Unit::Count, "Issues deleted");
|
|
metrics::describe_counter!(ISSUES_UPDATED_TOTAL, metrics::Unit::Count, "Issues updated");
|
|
metrics::describe_counter!(
|
|
ISSUE_COMMENTS_CREATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Issue comments created"
|
|
);
|
|
metrics::describe_counter!(
|
|
ISSUE_COMMENTS_DELETED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Issue comments deleted"
|
|
);
|
|
|
|
// Pull Request
|
|
metrics::describe_counter!(
|
|
PRS_OPENED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Pull requests opened"
|
|
);
|
|
metrics::describe_counter!(
|
|
PRS_MERGED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Pull requests merged"
|
|
);
|
|
metrics::describe_counter!(
|
|
PRS_CLOSED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Pull requests closed (without merge)"
|
|
);
|
|
metrics::describe_counter!(
|
|
PRS_UPDATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Pull requests updated"
|
|
);
|
|
metrics::describe_counter!(
|
|
PR_REVIEWS_SUBMITTED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"PR reviews submitted"
|
|
);
|
|
metrics::describe_counter!(
|
|
PR_REVIEW_COMMENTS_TOTAL,
|
|
metrics::Unit::Count,
|
|
"PR review comments"
|
|
);
|
|
|
|
// Room
|
|
metrics::describe_counter!(
|
|
ROOMS_CREATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Chat rooms created"
|
|
);
|
|
metrics::describe_counter!(
|
|
ROOMS_DELETED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Chat rooms deleted"
|
|
);
|
|
metrics::describe_counter!(
|
|
ROOMS_UPDATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Chat rooms updated"
|
|
);
|
|
metrics::describe_counter!(
|
|
ROOM_MESSAGES_SENT_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Room messages sent (human)"
|
|
);
|
|
metrics::describe_counter!(
|
|
ROOM_MESSAGES_AI_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Room messages sent (AI)"
|
|
);
|
|
metrics::describe_counter!(
|
|
ROOM_THREADS_CREATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Room threads created"
|
|
);
|
|
|
|
// Repo / Git
|
|
metrics::describe_counter!(REPOS_CREATED_TOTAL, metrics::Unit::Count, "Repos created");
|
|
metrics::describe_counter!(
|
|
GIT_COMMITS_PUSHED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Git commits pushed"
|
|
);
|
|
metrics::describe_counter!(
|
|
GIT_BRANCHES_CREATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Git branches created"
|
|
);
|
|
metrics::describe_counter!(
|
|
GIT_BRANCHES_DELETED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Git branches deleted"
|
|
);
|
|
metrics::describe_counter!(
|
|
GIT_TAGS_CREATED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Git tags created"
|
|
);
|
|
metrics::describe_counter!(
|
|
GIT_TAGS_DELETED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Git tags deleted"
|
|
);
|
|
metrics::describe_counter!(
|
|
GIT_CLONES_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Git clone/fetch operations"
|
|
);
|
|
|
|
// Billing
|
|
metrics::describe_counter!(
|
|
BILLING_CREDITS_USED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Billing credits consumed"
|
|
);
|
|
metrics::describe_counter!(BILLING_ERRORS_TOTAL, metrics::Unit::Count, "Billing errors");
|
|
metrics::describe_counter!(
|
|
BILLING_CREDITS_ADDED_TOTAL,
|
|
metrics::Unit::Count,
|
|
"Billing credits added (top-up)"
|
|
);
|
|
|
|
// AI
|
|
metrics::describe_counter!(
|
|
AI_ROOM_CALLS_TOTAL,
|
|
metrics::Unit::Count,
|
|
"AI calls in room context"
|
|
);
|
|
metrics::describe_counter!(
|
|
AI_CHAT_CONVERSATIONS_CREATED,
|
|
metrics::Unit::Count,
|
|
"AI chat conversations created"
|
|
);
|
|
metrics::describe_counter!(
|
|
AI_CHAT_MESSAGES_SENT,
|
|
metrics::Unit::Count,
|
|
"AI chat messages sent"
|
|
);
|
|
|
|
// Gauges
|
|
metrics::describe_gauge!(
|
|
ACTIVE_CONNECTIONS,
|
|
metrics::Unit::Count,
|
|
"Active WebSocket connections"
|
|
);
|
|
metrics::describe_gauge!(
|
|
ACTIVE_ROOM_PARTICIPANTS,
|
|
metrics::Unit::Count,
|
|
"Active room participants"
|
|
);
|
|
}
|