Skip to content

Commit

Permalink
add canary counter
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani committed Apr 3, 2022
1 parent f371ddf commit e91c355
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions vlogql.v
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ fn canary_logs(server string, canary_string string, show_labels bool) ? {
}
}

fn canary_emitter(server string, canary_string string, timer int) ? {
fn canary_emitter(server string, canary_string string, timer int, count int) ? {
labels := '{"canary":"$canary_string","type":"canary"}'
timestamp := now(0)
log := 'ts=$timestamp type=canary data=1111111111111111111111111111111111111111111111'
log := 'ts=$timestamp count=$count type=canary tag=$canary_string'
payload := '{"streams":[{"stream": $labels, "values":[ ["$timestamp", "$log"] ]}]}'
data := http.post_json('$server/loki/api/v1/push', payload) or { exit(1) }
if data.status_code != 204 {
Expand All @@ -181,7 +181,8 @@ fn canary_emitter(server string, canary_string string, timer int) ? {
}
println('Sleeping $timer seconds...')
time.sleep(timer * time.second)
go canary_emitter(server, canary_string, timer)
next := count + 1
go canary_emitter(server, canary_string, timer, next)
}

fn main() {
Expand Down Expand Up @@ -220,7 +221,7 @@ fn main() {
mut tag := rand.string_from_set('abcdefghiklmnopqrestuvwzABCDEFGHIKLMNOPQRSTUVWWZX0123456789',
12)
tag = 'canary_' + tag
go canary_emitter(logql_api, tag, 10)
go canary_emitter(logql_api, tag, 10, 0)
canary_logs(logql_api, tag, logql_labels) or { exit(1) }
} else {
fetch_logs(logql_api, logql_query, logql_limit, logql_labels, logql_start,
Expand All @@ -231,7 +232,7 @@ fn main() {
mut tag := rand.string_from_set('abcdefghiklmnopqrestuvwzABCDEFGHIKLMNOPQRSTUVWWZX0123456789',
12)
tag = 'canary_' + tag
go canary_emitter(logql_api, tag, 10)
go canary_emitter(logql_api, tag, 10, 0)
canary_logs(logql_api, tag, logql_labels) or { exit(1) }
} else if logql_labels {
fetch_labels(logql_api, '')
Expand Down

0 comments on commit e91c355

Please sign in to comment.