Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crons): Allow specifying checkin environment #1599

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
4 changes: 4 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2490,11 +2490,13 @@ pub struct MonitorCheckIn {
pub id: Uuid,
pub status: Option<MonitorCheckinStatus>,
pub duration: Option<u64>,
pub environment: Option<String>,
}

#[derive(Debug, Serialize)]
pub struct CreateMonitorCheckIn {
pub status: MonitorCheckinStatus,
pub environment: String,
}

#[derive(Debug, Serialize, Default)]
Expand All @@ -2503,6 +2505,8 @@ pub struct UpdateMonitorCheckIn {
pub status: Option<MonitorCheckinStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub environment: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it Option if we have a default value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not absolutely required to send, this reflects that should the API be used anywhere else

}

#[derive(Deserialize, Debug)]
Expand Down
9 changes: 9 additions & 0 deletions src/commands/monitors/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ pub fn make_command(command: Command) -> Command {
.help("The monitor slug.")
.required(true),
)
.arg(
Arg::new("environment")
.short('e')
.default_value("production")
.help("Specify the environment of the monitor."),
)
.arg(
Arg::new("allow_failure")
.short('f')
Expand Down Expand Up @@ -47,6 +53,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
}

let monitor_slug = matches.get_one::<String>("monitor_slug").unwrap();
let environment = matches.get_one::<String>("environment").unwrap();

let allow_failure = matches.get_flag("allow_failure");
let args: Vec<_> = matches.get_many::<String>("args").unwrap().collect();
Expand All @@ -56,6 +63,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
monitor_slug,
&CreateMonitorCheckIn {
status: MonitorCheckinStatus::InProgress,
environment: environment.to_string(),
},
);

Expand Down Expand Up @@ -93,6 +101,7 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let elapsed = started.elapsed();
elapsed.as_secs() * 1000 + u64::from(elapsed.subsec_millis())
}),
environment: Some(environment.to_string()),
},
)
.ok();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```
$ sentry-cli monitors run -e dev-env foo-monitor -- echo 123
? success
123

```
1 change: 1 addition & 0 deletions tests/integration/_cases/monitors/monitors-run-help.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Arguments:
<ARGS>...

Options:
-e <environment> Specify the environment of the monitor. [default: production]
-f, --allow-failure Run provided command even when Sentry reports an error.
--header <KEY:VALUE> Custom headers that should be attached to all requests
in key:value format.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "85a34e5a-c0b6-11ec-9d64-0242ac120002",
"duration": 1337,
"environment": "dev-env",
"status": "in_progress"
}
1 change: 1 addition & 0 deletions tests/integration/_responses/monitors/post-monitors.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "85a34e5a-c0b6-11ec-9d64-0242ac120002",
"duration": 1337,
"environment": "production",
"status": "in_progress"
}
13 changes: 11 additions & 2 deletions tests/integration/monitors/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ fn command_monitors_run_token_auth() {
}

#[test]
fn command_monitors_run_env() {
fn command_monitors_run_osenv() {
let _server = mock_endpoint(
EndpointOptions::new("POST", "/api/0/monitors/foo-monitor/checkins/", 200)
.with_response_file("monitors/post-monitors.json"),
);
register_test("monitors/monitors-run-env.trycmd");
register_test("monitors/monitors-run-osenv.trycmd");
}

#[test]
fn command_monitors_run_environment() {
let _server = mock_endpoint(
EndpointOptions::new("POST", "/api/0/monitors/foo-monitor/checkins/", 200)
.with_response_file("monitors/post-monitors-environment.json"),
);
register_test("monitors/monitors-run-environment.trycmd");
}

#[test]
Expand Down