Skip to content

Commit

Permalink
[suiop] add date to message output (#19233)
Browse files Browse the repository at this point in the history
## Description 

Add date output to make it clear when an incident was closed.
Add the slack channel url to short output.

## Test plan 

```
DEBUG=true cargo run -- i r -i --limit 1
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.54s
     Running `/Users/jkjensen/mysten/sui/target/debug/suiop i r -i --limit 1`
2024-09-05T20:52:01.898863Z  INFO suiop: Debug mode enabled
3511:0d   [FIRING:1] disk used % Infrastructure (/dev/md1 mainnet ext4 ord-mnt-rpcbig-03 localhost:9091 node-exporter /opt/sui mainnet pagerduty/nre rpc active) (https://mystenlabs.pagerduty.com/incidents/Q1OS8GCY2HHNEB)
> Keep this incident for review? Yes
Incidents marked for review: 3511
Here is the message to send in the channel: 
    
Hello everyone and happy Thursday!

We have selected the following incidents for review:
• 3511 09/05/24 [FIRING:1] disk used % Infrastructure (/dev/md1 mainnet ext4 ord-mnt-rpcbig-03 localhost:9091 node-exporter /opt/sui mainnet pagerduty/nre rpc active) 
    
and the following incidents have been excluded from review:


Please comment in the thread to request an adjustment to the list.
    
> Send this message to the #test-notifications channel? Yes
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
after-ephemera authored Sep 6, 2024
1 parent c8c0f60 commit 47ad468
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
32 changes: 22 additions & 10 deletions crates/suiop-cli/src/cli/incidents/pd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ pub struct Incident {
priority: Option<Priority>,
slack_channel: Option<Channel>,
}
const DATE_FORMAT_IN: &str = "%Y-%m-%dT%H:%M:%SZ";
const DATE_FORMAT_OUT: &str = "%m/%d/%Y %H:%M";
const DATE_FORMAT_OUT_SHORT: &str = "%m/%d/%y";

impl Incident {
fn print(&self, long_output: bool) -> Result<()> {
let date_format_in = "%Y-%m-%dT%H:%M:%SZ";
let priority = self.priority();
if long_output {
let date_format_out = "%m/%d/%Y %H:%M";
println!(
"Incident #: {} {}",
self.number.to_string().bright_purple(),
Expand All @@ -57,17 +58,17 @@ impl Incident {
if let Some(created_at) = self.created_at.clone() {
println!(
"Created at: {}",
NaiveDateTime::parse_from_str(&created_at, date_format_in)?
.format(date_format_out)
NaiveDateTime::parse_from_str(&created_at, DATE_FORMAT_IN)?
.format(DATE_FORMAT_OUT)
.to_string()
.yellow()
);
}
if let Some(resolved_at) = self.resolved_at.clone() {
println!(
"Resolved at: {}",
NaiveDateTime::parse_from_str(&resolved_at, date_format_in)?
.format(date_format_out)
NaiveDateTime::parse_from_str(&resolved_at, DATE_FORMAT_IN)?
.format(DATE_FORMAT_OUT)
.to_string()
.yellow()
);
Expand All @@ -81,7 +82,7 @@ impl Incident {
let resolved_at = if let Some(resolved_at) = self.resolved_at.clone() {
let now = Utc::now().naive_utc();

Some(now - NaiveDateTime::parse_from_str(&resolved_at, date_format_in)?)
Some(now - NaiveDateTime::parse_from_str(&resolved_at, DATE_FORMAT_IN)?)
} else {
None
};
Expand All @@ -97,7 +98,11 @@ impl Incident {
format!(" {} ", priority)
},
self.title.green(),
self.html_url.bright_purple(),
if let Some(channel) = self.slack_channel.clone() {
format!("({})", channel.url().bright_magenta())
} else {
self.html_url.bright_purple().to_string()
}
);
}
Ok(())
Expand Down Expand Up @@ -247,17 +252,24 @@ pub async fn review_recent_incidents(incidents: Vec<Incident>) -> Result<()> {

fn short_print(i: &Incident) -> String {
format!(
"• {} {} {}",
"• {} {} {} {}",
if let Some(channel) = i.slack_channel.clone() {
format!("{} ({})", i.number, channel.url())
} else {
i.number.to_string()
},
i.resolved_at
.clone()
.map(|c| NaiveDateTime::parse_from_str(&c, DATE_FORMAT_IN)
.expect("parsing closed date")
.format(DATE_FORMAT_OUT_SHORT)
.to_string())
.unwrap_or("".to_owned()),
i.title,
i.slack_channel
.clone()
.map(|c| c.name)
.unwrap_or("".to_string())
.unwrap_or("".to_string()),
)
}

Expand Down
4 changes: 3 additions & 1 deletion crates/suiop-cli/src/cli/incidents/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ struct SendMessageBody {

impl Slack {
pub async fn new() -> Self {
let token = std::env::var("SLACK_BOT_TOKEN").expect("Please set SLACK_BOT_TOKEN env var");
let token = std::env::var("SLACK_BOT_TOKEN").expect(
"Please set SLACK_BOT_TOKEN env var ('slack bot token (incidentbot)' in 1password)",
);
let mut headers = header::HeaderMap::new();
headers.insert(
header::AUTHORIZATION,
Expand Down

0 comments on commit 47ad468

Please sign in to comment.