Skip to content

Commit

Permalink
Merge pull request #50 from gocardless/lawrence-timeout-metrics
Browse files Browse the repository at this point in the history
Timeout metric queries
  • Loading branch information
lawrencejones authored Sep 10, 2019
2 parents 946f1b4 + b9bf35f commit 21a9fa3
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/que/middleware/queue_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,27 @@ def call(env)
# report metric values that are current in every scrape.
Queued.values.each { |labels, _| Queued.set(0.0, labels: labels) }

# Now we can safely update our gauges, touching only those that exist in our queue
Que.execute(QUEUE_VIEW_SQL).each do |labels|
Queued.set(
labels["count"],
labels: {
queue: labels["queue"],
job_class: labels["job_class"],
priority: labels["priority"],
due: labels["due"],
},
)
end
Que.transaction do
# Ensure metric queries never take more than 500ms to execute, preventing our
# metric collector from hurting the database when it's already under pressure.
Que.execute("set local statement_timeout='500ms';")

# Now we can safely update our gauges, touching only those that exist in our queue
Que.execute(QUEUE_VIEW_SQL).each do |labels|
Queued.set(
labels["count"],
labels: {
queue: labels["queue"],
job_class: labels["job_class"],
priority: labels["priority"],
due: labels["due"],
},
)
end

# DeadTuples has no labels, we can expect this to be a single numeric value
DeadTuples.set(Que.execute(DEAD_TUPLES_SQL).first&.fetch("n_dead_tup"))
# DeadTuples has no labels, we can expect this to be a single numeric value
DeadTuples.set(Que.execute(DEAD_TUPLES_SQL).first&.fetch("n_dead_tup"))
end

@app.call(env)
end
Expand Down

0 comments on commit 21a9fa3

Please sign in to comment.