Simplifying Tag Browsing in Grafana
# general
l
Hi, we just released a new article on learn.umh.app. Go check it out, and discuss it here! Title: Simplifying Tag Browsing in Grafana Excerpt: Trent Christopher created a solution to browse UMH Historian tags in Grafana via TimescaleDB, making it easy for non-technical users to access and interact with UNS data. Link: https://learn.umh.app/course/simplifying-tag-browsing-in-grafana/
r
Hey @trentc I had the chance to try this out today. It's pretty slick! One limitation I found — some of the data in my UMH lab is flowing into the tag_string table. I had chatgpt help me rewrite the SQL that creates the tag_hierarchy materialzed view to account for this.
Copy code
-- View: public.tag_hierarchy

-- DROP MATERIALIZED VIEW IF EXISTS public.tag_hierarchy;

CREATE MATERIALIZED VIEW IF NOT EXISTS public.tag_hierarchy
TABLESPACE pg_default
AS
SELECT t.name,
       t.asset_id,
       regexp_replace(t.name, '[$\.]'::text, '/'::text, 'g'::text) AS hierarchy_path
FROM (
    SELECT DISTINCT ON (tag.asset_id, tag.name) 
           tag.name,
           tag.asset_id
    FROM tag
    
    UNION

    SELECT DISTINCT ON (tag_string.asset_id, tag_string.name) 
           tag_string.name,
           tag_string.asset_id
    FROM tag_string
) t
WITH DATA;

ALTER TABLE IF EXISTS public.tag_hierarchy
    OWNER TO kafkatopostgresqlv2;

GRANT SELECT ON TABLE public.tag_hierarchy TO grafanareader;
GRANT ALL ON TABLE public.tag_hierarchy TO kafkatopostgresqlv2;
It gets a little messy downstream once you try to see values in Grafana because the Tag Value pane expects a number field. Right now I have the complete tag browser in Grafana but the values that appear in the tag_string table can't show up.
t
Yes that was a design choice I made, to not include strings because it gets more complicated to handle. I had debated on adding separate resources for strings
In practical use, they aren’t going to be presented the same…. Numbers can be presented on charts but strings will be in tables… as an example.
I ran into a situation where some numbers were being stored as strings… but this is an upstream issue