Skip to content

Commit

Permalink
change placeholder type from identifier to string (#175)
Browse files Browse the repository at this point in the history
* change placeholder type to string

* change from identifier to string type

* dont redefine metrics record

* skip trunk publish when not a release
  • Loading branch information
ChuckHend authored Jan 4, 2024
1 parent e3d8fa0 commit 73ffbc4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/extension_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ jobs:
working-directory: ./
run: trunk build
- name: trunk publish
# only publish release events
if: github.event_name == 'release'
working-directory: ./
env:
TRUNK_API_TOKEN: ${{ secrets.TRUNK_AUTH_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmq"
version = "1.1.0"
version = "1.1.1"
edition = "2021"
authors = ["Tembo.io"]
description = "Postgres extension for PGMQ"
Expand Down
38 changes: 38 additions & 0 deletions sql/pgmq--1.1.0--1.1.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- get metrics for a single queue
CREATE OR REPLACE FUNCTION pgmq.metrics(queue_name TEXT)
RETURNS pgmq.metrics_result AS $$
DECLARE
result_row pgmq.metrics_result;
query TEXT;
BEGIN
query := FORMAT(
$QUERY$
WITH q_summary AS (
SELECT
count(*) as queue_length,
EXTRACT(epoch FROM (NOW() - max(enqueued_at)))::int as newest_msg_age_sec,
EXTRACT(epoch FROM (NOW() - min(enqueued_at)))::int as oldest_msg_age_sec,
NOW() as scrape_time
FROM pgmq.q_%s
),
all_metrics AS (
SELECT CASE
WHEN is_called THEN last_value ELSE 0
END as total_messages
FROM pgmq.q_%s_msg_id_seq
)
SELECT
'%s' as queue_name,
q_summary.queue_length,
q_summary.newest_msg_age_sec,
q_summary.oldest_msg_age_sec,
all_metrics.total_messages,
q_summary.scrape_time
FROM q_summary, all_metrics
$QUERY$,
queue_name, queue_name, queue_name
);
EXECUTE query INTO result_row;
RETURN result_row;
END;
$$ LANGUAGE plpgsql;
4 changes: 2 additions & 2 deletions src/sql_src.sql
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ BEGIN
EXTRACT(epoch FROM (NOW() - max(enqueued_at)))::int as newest_msg_age_sec,
EXTRACT(epoch FROM (NOW() - min(enqueued_at)))::int as oldest_msg_age_sec,
NOW() as scrape_time
FROM pgmq.q_%I
FROM pgmq.q_%s
),
all_metrics AS (
SELECT CASE
WHEN is_called THEN last_value ELSE 0
END as total_messages
FROM pgmq.q_%I_msg_id_seq
FROM pgmq.q_%s_msg_id_seq
)
SELECT
'%s' as queue_name,
Expand Down

0 comments on commit 73ffbc4

Please sign in to comment.