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
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
code: ${{ steps.filter.outputs.code }}
workflows: ${{ steps.filter.outputs.workflows }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: dorny/paths-filter@v2
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
Expand All @@ -39,7 +39,7 @@ jobs:
steps:
- uses: rui314/setup-mold@v1

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: Swatinem/rust-cache@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
working-directory: .

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: 🦀 - Install Rust
run: |
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
if: github.ref_name == 'main' && github.event_name == 'push'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: 📦 - Copy binary artifacts
uses: actions/download-artifact@v4
Expand Down
28 changes: 23 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use alertaemcena::metrics::{
record_event_send_duration, record_event_sent, record_events_fetched,
record_get_events_by_month_duration, record_pipeline_error, record_pipeline_run_duration,
record_pipeline_run_duration_without_event_gather, record_reaction_processing_duration,
record_vote_backup_duration, record_vote_backup_records, set_threads_active, MetricResult,
PipelineErrorKind, PipelineStage,
record_vote, record_vote_backup_duration, record_vote_backup_records, set_threads_active,
MetricResult, PipelineErrorKind, PipelineStage,
};
use alertaemcena::tracing::setup_tracing;
use chrono::Utc;
Expand Down Expand Up @@ -80,7 +80,7 @@ async fn main() {
}
});

backup_votes(&discord, users_to_backup).await;
backup_votes(&discord, users_to_backup, &config.voting_emojis).await;
info!("Starting app");
}
.instrument(root_span)
Expand Down Expand Up @@ -157,8 +157,8 @@ async fn run(
users_with_reactions
}

#[instrument(skip(discord))]
pub async fn backup_votes(discord: &DiscordAPI, vec: Vec<UserId>) {
#[instrument(skip(discord, vote_emojis))]
pub async fn backup_votes(discord: &DiscordAPI, vec: Vec<UserId>, vote_emojis: &[EmojiConfig; 5]) {
let backup_started_at = Instant::now();
let vote_backups_folder = "vote_backups/";
let vote_backup_file_path = format!(
Expand Down Expand Up @@ -205,6 +205,24 @@ pub async fn backup_votes(discord: &DiscordAPI, vec: Vec<UserId>) {
.into_iter()
.flatten()
.concat();

for vote_record in &user_votes {
match vote_emojis
.iter()
.position(|emoji| emoji.to_string() == vote_record.user_vote.vote)
{
Some(index) => record_vote(
index as u64 + 1,
&vote_record.user_id.to_string(),
&vote_record.url,
),
None => warn!(
"Unrecognized vote emoji '{}' for user {}",
vote_record.user_vote.vote, vote_record.user_id
),
}
}

record_vote_backup_records(user_votes.len() as u64);

let backup_votes_file = File::create(&vote_backup_file_path).await;
Expand Down
14 changes: 14 additions & 0 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ lazy_static! {
.u64_gauge("aec_threads_active")
.with_description("Current active thread count per category")
.init();
static ref VOTE: Gauge<u64> = METER
.u64_gauge("aec_vote")
.with_description("Vote number (1-5) cast by a voter")
.init();
}

pub fn record_events_fetched(category: &Category, count: u64) {
Expand Down Expand Up @@ -221,3 +225,13 @@ pub fn record_pipeline_error(stage: PipelineStage, error_kind: PipelineErrorKind
pub fn set_threads_active(category: &Category, count: u64) {
THREADS_ACTIVE.record(count, &[category.into()]);
}

pub fn record_vote(vote_number: u64, voter: &str, event_url: &str) {
VOTE.record(
vote_number,
&[
KeyValue::new("voter", voter.to_string()),
KeyValue::new("event_url", event_url.to_string()),
],
);
}
Loading