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
44 changes: 44 additions & 0 deletions src/agent_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,48 @@ const RESOURCE_SPECS: &[ResourceSpec] = &[
"PUBLIC reports also mark their runs public.",
],
},
ResourceSpec {
name: "monitors",
commands: &[
"context",
"list",
"get",
"create",
"update",
"delete",
"test-evaluate",
"events.list",
],
description: "Monitors evaluate runs and dispatch alerts when configured conditions match.",
id_name: "monitor_id",
id_format: "Coval monitor ID",
requires: &["runs"],
optional: &["agents", "tags", "scheduled-runs"],
produces: &["monitor events", "alerts"],
related: &["runs", "metrics", "agents", "scheduled-runs"],
workflows: &[WorkflowSpec {
name: "Inspect monitors",
argv: &["monitors", "list"],
}],
pitfalls: &[
"Create requests require at least one condition.",
"Channel auth tokens are redacted in CLI output.",
],
},
ResourceSpec {
name: "tags",
commands: &["context", "list", "get", "create", "update", "delete"],
description: "Tags label Coval resources for filtering, organization, and monitor targeting.",
id_name: "tag_id",
id_format: "Coval tag ID",
requires: &[],
optional: &["agents", "monitors"],
produces: &["resource labels"],
related: &["agents", "monitors"],
workflows: &[WorkflowSpec {
name: "Inspect tags",
argv: &["tags", "list"],
}],
pitfalls: &["Tag colors should be valid CSS-style color values when provided."],
},
];
12 changes: 12 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ pub enum Commands {
#[command(subcommand)]
command: commands::reports::ReportCommands,
},
Monitors {
#[command(subcommand)]
command: commands::monitors::MonitorCommands,
},
Comment thread
callumreid marked this conversation as resolved.
Tags {
#[command(subcommand)]
command: commands::tags::TagCommands,
Expand Down Expand Up @@ -149,6 +153,7 @@ impl Commands {
Self::ReviewAnnotations { .. } => "review-annotations",
Self::ReviewProjects { .. } => "review-projects",
Self::Reports { .. } => "reports",
Self::Monitors { .. } => "monitors",
Self::Tags { .. } => "tags",
}
}
Expand Down Expand Up @@ -176,6 +181,7 @@ impl Commands {
Self::ReviewAnnotations { command } => command.operation(),
Self::ReviewProjects { command } => command.operation(),
Self::Reports { command } => command.operation(),
Self::Monitors { command } => command.operation(),
Self::Tags { command } => command.operation(),
}
}
Expand Down Expand Up @@ -266,6 +272,9 @@ pub async fn run(cli: Cli, ctx: &OutputContext) -> anyhow::Result<()> {
Commands::Reports {
command: commands::reports::ReportCommands::Context,
} => commands::agent::resource_context("reports", ctx),
Commands::Monitors {
command: commands::monitors::MonitorCommands::Context,
} => commands::agent::resource_context("monitors", ctx),
Commands::Tags {
command: commands::tags::TagCommands::Context,
} => commands::agent::resource_context("tags", ctx),
Expand Down Expand Up @@ -327,6 +336,9 @@ pub async fn run(cli: Cli, ctx: &OutputContext) -> anyhow::Result<()> {
Commands::Reports { command } => {
commands::reports::execute(command, &client, ctx).await
}
Commands::Monitors { command } => {
commands::monitors::execute(command, &client, ctx).await
}
Commands::Tags { command } => commands::tags::execute(command, &client, ctx).await,
_ => unreachable!(),
}
Expand Down
69 changes: 69 additions & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ impl CovalClient {
}
}

pub fn monitors(&self) -> MonitorsClient<'_> {
MonitorsClient(self)
}

pub fn tags(&self) -> TagsClient<'_> {
TagsClient(self)
}
Expand Down Expand Up @@ -247,6 +251,8 @@ pub struct WidgetsClient<'a> {
}
pub struct TagsClient<'a>(&'a CovalClient);

pub struct MonitorsClient<'a>(&'a CovalClient);

impl AgentsClient<'_> {
pub async fn list(
&self,
Expand Down Expand Up @@ -1232,6 +1238,69 @@ impl WidgetsClient<'_> {
}
}

impl MonitorsClient<'_> {
pub async fn list(
&self,
params: models::ListParams,
) -> Result<models::ListMonitorsResponse, ApiError> {
let mut url = self.0.url("/v1/monitors");
params.apply_to(&mut url);
self.0.get(url).await
}

pub async fn get(&self, id: &str) -> Result<models::Monitor, ApiError> {
let url = self.0.url(&format!("/v1/monitors/{id}"));
let resp: models::GetMonitorResponse = self.0.get(url).await?;
Ok(resp.monitor)
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.

pub async fn create(
&self,
req: models::CreateMonitorRequest,
) -> Result<models::Monitor, ApiError> {
let url = self.0.url("/v1/monitors");
self.0.post(url, &req).await
}

pub async fn update(
&self,
id: &str,
req: models::UpdateMonitorRequest,
) -> Result<models::Monitor, ApiError> {
let url = self.0.url(&format!("/v1/monitors/{id}"));
self.0.patch(url, &req).await
}

pub async fn delete(&self, id: &str) -> Result<(), ApiError> {
let url = self.0.url(&format!("/v1/monitors/{id}"));
self.0.delete(url).await
}

pub async fn test_evaluate(
&self,
monitor_id: &str,
run_id: &str,
) -> Result<models::TestEvaluateResponse, ApiError> {
let url = self
.0
.url(&format!("/v1/monitors/{monitor_id}/test-evaluate"));
let req = models::TestEvaluateRequest {
run_id: run_id.to_string(),
};
self.0.post(url, &req).await
}

pub async fn list_events(
&self,
monitor_id: &str,
params: models::ListParams,
) -> Result<models::ListMonitorEventsResponse, ApiError> {
let mut url = self.0.url(&format!("/v1/monitors/{monitor_id}/events"));
params.apply_to(&mut url);
self.0.get(url).await
}
}

impl TagsClient<'_> {
pub async fn list(&self) -> Result<models::ListTagsResponse, ApiError> {
let url = self.0.url("/v1/tags");
Expand Down
2 changes: 2 additions & 0 deletions src/client/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod conversation;
mod dashboard;
mod metric;
mod metric_model;
mod monitor;
mod mutation;
mod persona;
mod report;
Expand All @@ -28,6 +29,7 @@ pub use conversation::*;
pub use dashboard::*;
pub use metric::*;
pub use metric_model::*;
pub use monitor::*;
pub use mutation::*;
pub use persona::*;
pub use report::*;
Expand Down
Loading
Loading