@lunora/observability 1.0.0-alpha.204 → 1.0.0-alpha.206
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AUTH_METRICS_BUCKETS_TABLE as t,AUTH_METRICS_BUCKET_MS as s,AUTH_METRICS_BUCKET_RETENTION as a,AUTH_METRICS_TABLE as o,ensureAuthMetricsTables as T,readAuthMetrics as E,recordAuthEvent as S}from"./packem_shared/AUTH_METRICS_BUCKETS_TABLE-BpH1ZAgX.mjs";import{createMetrics as i,createSpanCollector as c,createTracedFetch as n,createTracer as I,dispatchRootSpan as u}from"./packem_shared/createMetrics-DQynv3tU.mjs";import{createDatabaseTally as A,formatTally as N,instrumentDatabase as p,instrumentSqlClient as C}from"./packem_shared/createDatabaseTally-fSQyp-qV.mjs";import{FUNCTION_METRICS_BUCKETS_TABLE as f,FUNCTION_METRICS_BUCKET_MS as R,FUNCTION_METRICS_BUCKET_RETENTION as U,FUNCTION_METRICS_INDEX_TABLE as m,FUNCTION_METRICS_MAX_PATHS as l,FUNCTION_METRICS_READ_LIMIT as L,FUNCTION_METRICS_SCANS_TABLE as x,FUNCTION_METRICS_TABLE as B,ensureFunctionMetricsTables as F,mergeScanAttribution as g,readFunctionMetricBuckets as O,readFunctionMetricIndexHits as H,readFunctionMetricScans as y,readFunctionMetrics as b,readFunctionMetricsTotals as h,recordFunctionMetric as v}from"./packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-Dha-40Hv.mjs";import{applyHostRootSpan as K,setHostSpanAttributes as q}from"./packem_shared/applyHostRootSpan-DToRfMn8.mjs";import{DEFAULT_EXPLAIN_ISSUE_MODEL as Q,explainIssue as V,parseExplainIssueArgs as k}from"./packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-BkFTgdkd.mjs";import{ISSUE_SEVERITIES as X,ISSUE_STATE_TABLE as j,ISSUE_STATUSES as w,upsertIssueState as z}from"./packem_shared/ISSUE_SEVERITIES-0SJ0glV4.mjs";import{LogBuffer as W}from"./packem_shared/LogBuffer-CC2ssFlT.mjs";import{MetricBuffer as Z}from"./packem_shared/MetricBuffer-B8e9LgjF.mjs";import{readMetricHistory as ee,recordMetricHistory as re}from"./packem_shared/readMetricHistory-sy8Lp97A.mjs";import{latencyBucketIndex as se,readQueryInsights as ae,readQueryMetrics as oe,recordQueryMetric as Te}from"./packem_shared/latencyBucketIndex
|
|
1
|
+
import{AUTH_METRICS_BUCKETS_TABLE as t,AUTH_METRICS_BUCKET_MS as s,AUTH_METRICS_BUCKET_RETENTION as a,AUTH_METRICS_TABLE as o,ensureAuthMetricsTables as T,readAuthMetrics as E,recordAuthEvent as S}from"./packem_shared/AUTH_METRICS_BUCKETS_TABLE-BpH1ZAgX.mjs";import{createMetrics as i,createSpanCollector as c,createTracedFetch as n,createTracer as I,dispatchRootSpan as u}from"./packem_shared/createMetrics-DQynv3tU.mjs";import{createDatabaseTally as A,formatTally as N,instrumentDatabase as p,instrumentSqlClient as C}from"./packem_shared/createDatabaseTally-fSQyp-qV.mjs";import{FUNCTION_METRICS_BUCKETS_TABLE as f,FUNCTION_METRICS_BUCKET_MS as R,FUNCTION_METRICS_BUCKET_RETENTION as U,FUNCTION_METRICS_INDEX_TABLE as m,FUNCTION_METRICS_MAX_PATHS as l,FUNCTION_METRICS_READ_LIMIT as L,FUNCTION_METRICS_SCANS_TABLE as x,FUNCTION_METRICS_TABLE as B,ensureFunctionMetricsTables as F,mergeScanAttribution as g,readFunctionMetricBuckets as O,readFunctionMetricIndexHits as H,readFunctionMetricScans as y,readFunctionMetrics as b,readFunctionMetricsTotals as h,recordFunctionMetric as v}from"./packem_shared/FUNCTION_METRICS_BUCKETS_TABLE-Dha-40Hv.mjs";import{applyHostRootSpan as K,setHostSpanAttributes as q}from"./packem_shared/applyHostRootSpan-DToRfMn8.mjs";import{DEFAULT_EXPLAIN_ISSUE_MODEL as Q,explainIssue as V,parseExplainIssueArgs as k}from"./packem_shared/DEFAULT_EXPLAIN_ISSUE_MODEL-BkFTgdkd.mjs";import{ISSUE_SEVERITIES as X,ISSUE_STATE_TABLE as j,ISSUE_STATUSES as w,upsertIssueState as z}from"./packem_shared/ISSUE_SEVERITIES-0SJ0glV4.mjs";import{LogBuffer as W}from"./packem_shared/LogBuffer-CC2ssFlT.mjs";import{MetricBuffer as Z}from"./packem_shared/MetricBuffer-B8e9LgjF.mjs";import{readMetricHistory as ee,recordMetricHistory as re}from"./packem_shared/readMetricHistory-sy8Lp97A.mjs";import{latencyBucketIndex as se,readQueryInsights as ae,readQueryMetrics as oe,recordQueryMetric as Te}from"./packem_shared/latencyBucketIndex-C1aY1MtR.mjs";import{N as Se,R as _e,S as ie,a as ce,c as ne,e as Ie,b as ue,d as Me,m as Ae,p as Ne,r as pe,f as Ce,g as de,h as fe,s as Re,i as Ue}from"./packem_shared/request-log-BVf-TLws.mjs";import{MIN_ADMIN_TOKEN_LENGTH as le,MIN_AUTH_SECRET_LENGTH as Le,buildSecurityAudit as xe}from"./packem_shared/MIN_ADMIN_TOKEN_LENGTH-DSOQ6rno.mjs";import{SpanBuffer as Fe,foldTraces as ge}from"./packem_shared/SpanBuffer-DPhjMBAd.mjs";import{findDanglingReferences as He}from"./packem_shared/findDanglingReferences-BaOyIdxz.mjs";import{resolveTraceAnchor as be}from"./packem_shared/resolveTraceAnchor-DDAPZRBB.mjs";export{t as AUTH_METRICS_BUCKETS_TABLE,s as AUTH_METRICS_BUCKET_MS,a as AUTH_METRICS_BUCKET_RETENTION,o as AUTH_METRICS_TABLE,Q as DEFAULT_EXPLAIN_ISSUE_MODEL,f as FUNCTION_METRICS_BUCKETS_TABLE,R as FUNCTION_METRICS_BUCKET_MS,U as FUNCTION_METRICS_BUCKET_RETENTION,m as FUNCTION_METRICS_INDEX_TABLE,l as FUNCTION_METRICS_MAX_PATHS,L as FUNCTION_METRICS_READ_LIMIT,x as FUNCTION_METRICS_SCANS_TABLE,B as FUNCTION_METRICS_TABLE,X as ISSUE_SEVERITIES,j as ISSUE_STATE_TABLE,w as ISSUE_STATUSES,W as LogBuffer,le as MIN_ADMIN_TOKEN_LENGTH,Le as MIN_AUTH_SECRET_LENGTH,Z as MetricBuffer,Se as NO_SENSITIVE_SCOPE,_e as REQUEST_LOG_TABLE,ie as SENSITIVE_ARG_MASK,Fe as SpanBuffer,ce as appendRequestLogEntry,K as applyHostRootSpan,xe as buildSecurityAudit,A as createDatabaseTally,i as createMetrics,ne as createSensitiveScope,c as createSpanCollector,n as createTracedFetch,I as createTracer,u as dispatchRootSpan,Ie as emitLogEvent,ue as emitRequestLogEvent,T as ensureAuthMetricsTables,F as ensureFunctionMetricsTables,Me as ensureRequestLogTable,V as explainIssue,He as findDanglingReferences,ge as foldTraces,N as formatTally,p as instrumentDatabase,C as instrumentSqlClient,se as latencyBucketIndex,Ae as maskSensitiveArgs,g as mergeScanAttribution,k as parseExplainIssueArgs,Ne as parseLogArgs,E as readAuthMetrics,pe as readErrorIssues,O as readFunctionMetricBuckets,H as readFunctionMetricIndexHits,y as readFunctionMetricScans,b as readFunctionMetrics,h as readFunctionMetricsTotals,ee as readMetricHistory,ae as readQueryInsights,oe as readQueryMetrics,Ce as readRequestLog,S as recordAuthEvent,v as recordFunctionMetric,re as recordMetricHistory,Te as recordQueryMetric,de as redactArgs,fe as redactCredentials,be as resolveTraceAnchor,Re as sensitiveNames,Ue as sensitiveValues,q as setHostSpanAttributes,z as upsertIssueState};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import{r as a}from"./run-sql-0aPgJkIw.mjs";const g=2166136261,C=16777619,F=(t,e=g)=>{let r=e;for(let o=0;o<t.length;o+=1)r^=t.charCodeAt(o),r=Math.imul(r,C);return(r>>>0).toString(16).padStart(8,"0")},i="__lunora_metrics_queries",T="__lunora_metrics_queries_buckets",$=`${T}_bucket_ms`,L=6e4,p=90,l=[1,2,5,10,25,50,100,250,500,1e3,5e3],U=512,I=500,y=t=>{let e=t.replaceAll(/\bx'[\da-f]*'/gi,"?").replaceAll(/'(?:[^']|'')*'/g,"?").replaceAll(/\b0x[\da-f]+\b/gi,"?").replaceAll(/(?<![\w$.?:@"])-?\d+(?:\.\d*)?(?:e[+-]?\d+)?(?![\w.])/gi,"?").replaceAll(/(?<![\w$?:@"])-?\.\d+(?:e[+-]?\d+)?(?![\w.])/gi,"?").replaceAll(/\s+/g," ").trim();return e.length>U&&(e=`${e.slice(0,U-1)}…`),e},M=new WeakSet,w=t=>{M.has(t)||(a(t,`CREATE TABLE IF NOT EXISTS "${i}" (
|
|
2
|
+
normalized_sql TEXT PRIMARY KEY,
|
|
3
|
+
exec_count INTEGER NOT NULL DEFAULT 0,
|
|
4
|
+
total_duration_ms REAL NOT NULL DEFAULT 0,
|
|
5
|
+
rows_read INTEGER NOT NULL DEFAULT 0,
|
|
6
|
+
rows_written INTEGER NOT NULL DEFAULT 0
|
|
7
|
+
)`),M.add(t))},h=new WeakMap,N=t=>Math.floor(t/L)*L,D=t=>F(t),B=t=>{const e=l.findIndex(r=>t<=r);return e===-1?l.length:e},m=t=>`lat_${String(t)}`,O=new WeakSet,b=t=>{if(O.has(t))return;const e=Array.from({length:l.length+1},(r,o)=>`${m(o)} INTEGER NOT NULL DEFAULT 0`).join(", ");a(t,`CREATE TABLE IF NOT EXISTS "${T}" (
|
|
8
|
+
sql_hash TEXT NOT NULL,
|
|
9
|
+
bucket_ms INTEGER NOT NULL,
|
|
10
|
+
exec_count INTEGER NOT NULL DEFAULT 0,
|
|
11
|
+
total_duration_ms REAL NOT NULL DEFAULT 0,
|
|
12
|
+
rows_read INTEGER NOT NULL DEFAULT 0,
|
|
13
|
+
rows_written INTEGER NOT NULL DEFAULT 0,
|
|
14
|
+
${e},
|
|
15
|
+
PRIMARY KEY (sql_hash, bucket_ms)
|
|
16
|
+
)`);try{a(t,`CREATE INDEX IF NOT EXISTS "${$}" ON "${T}" (bucket_ms)`)}catch{}O.add(t)},Y=(t,e)=>{a(t,`DELETE FROM "${T}" WHERE bucket_ms < ?`,N(e)-p*L)},Q=(t,e,r,o,_,c,s=1)=>{try{b(t);const u=s>0?r/s:r,E=m(B(u)),S=`INSERT INTO "${T}" (sql_hash, bucket_ms, exec_count, total_duration_ms, rows_read, rows_written, ${E})
|
|
17
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
18
|
+
ON CONFLICT(sql_hash, bucket_ms) DO UPDATE SET
|
|
19
|
+
exec_count = exec_count + excluded.exec_count,
|
|
20
|
+
total_duration_ms = total_duration_ms + excluded.total_duration_ms,
|
|
21
|
+
rows_read = rows_read + excluded.rows_read,
|
|
22
|
+
rows_written = rows_written + excluded.rows_written,
|
|
23
|
+
${E} = ${E} + excluded.${E}`;a(t,S,D(e),N(c),s,r,o,_,s);const n=N(c);h.get(t)!==n&&(h.set(t,n),Y(t,c))}catch{}},k=(t,e)=>{const r=t.reduce((c,s)=>c+s,0);if(r===0)return 0;const o=r*e;let _=0;for(const[c,s]of t.entries())if(_+=s,_>=o)return l[c]??l.at(-1)??0;return l.at(-1)??0},H=(t,e,r=Date.now())=>{try{w(t),b(t)}catch{return{buckets:[],capped:!1,entries:[],trackedStatements:0}}const o=N(r-e),_=Array.from({length:l.length+1},(n,d)=>`SUM(${m(d)}) AS ${m(d)}`).join(", "),c=a(t,`SELECT sql_hash, SUM(exec_count) AS exec_count, SUM(total_duration_ms) AS total_duration_ms,
|
|
24
|
+
SUM(rows_read) AS rows_read, SUM(rows_written) AS rows_written, ${_}
|
|
25
|
+
FROM "${T}" WHERE bucket_ms >= ? GROUP BY sql_hash`,o).toArray(),s=new Map;for(const n of a(t,`SELECT normalized_sql FROM "${i}"`))s.set(D(n.normalized_sql),n.normalized_sql);const u=c.map(n=>{const d=Array.from({length:l.length+1},(W,f)=>Number(n[m(f)]??0)),A=Number(n.exec_count??0),R=Number(n.total_duration_ms??0);return{avgDurationMs:A>0?R/A:0,execCount:A,normalizedSql:s.get(String(n.sql_hash))??String(n.sql_hash),p50DurationMs:k(d,.5),p95DurationMs:k(d,.95),rowsRead:Number(n.rows_read??0),rowsWritten:Number(n.rows_written??0),totalDurationMs:R}});u.sort((n,d)=>d.totalDurationMs-n.totalDurationMs);const E=a(t,`SELECT bucket_ms, SUM(exec_count) AS exec_count, SUM(total_duration_ms) AS total_duration_ms
|
|
26
|
+
FROM "${T}" WHERE bucket_ms >= ? GROUP BY bucket_ms ORDER BY bucket_ms ASC`,o).toArray().map(n=>({avgDurationMs:n.exec_count>0?n.total_duration_ms/n.exec_count:0,bucketMs:n.bucket_ms,execCount:n.exec_count})),S=a(t,`SELECT COUNT(*) AS n FROM "${i}"`).one().n;return{buckets:E,capped:S>=I,entries:u,trackedStatements:S}},x=new WeakMap,z=t=>{let e=x.get(t);return e===void 0&&(e=new Set,x.set(t,e)),e},G=(t,e)=>{const r=z(t);return r.has(e)?!0:a(t,`SELECT 1 AS c FROM "${i}" WHERE normalized_sql = ? LIMIT 1`,e).toArray().length>0?(r.add(e),!0):a(t,`SELECT COUNT(*) AS n FROM "${i}"`).one().n>=I?!1:(r.add(e),!0)},P=(t,e,r,o,_,c=Date.now(),s=1)=>{const u=y(e);if(u.length===0||(w(t),!G(t,u)))return;const E=`INSERT INTO "${i}" (normalized_sql, exec_count, total_duration_ms, rows_read, rows_written)
|
|
27
|
+
VALUES (?, ?, ?, ?, ?)
|
|
28
|
+
ON CONFLICT(normalized_sql) DO UPDATE SET
|
|
29
|
+
exec_count = exec_count + excluded.exec_count,
|
|
30
|
+
total_duration_ms = total_duration_ms + excluded.total_duration_ms,
|
|
31
|
+
rows_read = rows_read + excluded.rows_read,
|
|
32
|
+
rows_written = rows_written + excluded.rows_written`;a(t,E,u,s,r,o,_),Q(t,u,r,o,_,c,s)},K=t=>(w(t),a(t,`SELECT normalized_sql, exec_count, total_duration_ms, rows_read, rows_written FROM "${i}" ORDER BY total_duration_ms DESC`).toArray().map(r=>({execCount:r.exec_count,normalizedSql:r.normalized_sql,rowsRead:r.rows_read,rowsWritten:r.rows_written,totalDurationMs:r.total_duration_ms})));export{p as QUERY_BUCKET_RETENTION,U as QUERY_METRICS_MAX_SQL_LEN,I as QUERY_METRICS_MAX_STATEMENTS,i as QUERY_METRICS_TABLE,B as latencyBucketIndex,y as normalizeSql,Y as pruneQueryBuckets,H as readQueryInsights,K as readQueryMetrics,P as recordQueryMetric};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/observability",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.206",
|
|
4
4
|
"description": "Host-neutral telemetry storage and read models for Lunora, backing the Studio's Logs, Traces, Metrics and Issues views",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lunora",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
47
47
|
"@lunora/fingerprint": "1.0.0-alpha.10",
|
|
48
|
-
"@lunora/shard-engine": "^1.0.0-alpha.
|
|
48
|
+
"@lunora/shard-engine": "^1.0.0-alpha.209",
|
|
49
49
|
"@lunora/wire": "1.0.0-alpha.6",
|
|
50
50
|
"@visulima/redact": "5.0.0"
|
|
51
51
|
},
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import{r as a}from"./run-sql-0aPgJkIw.mjs";const F=2166136261,b=16777619,C=(t,e=F)=>{let r=e;for(let o=0;o<t.length;o+=1)r^=t.charCodeAt(o),r=Math.imul(r,b);return(r>>>0).toString(16).padStart(8,"0")},i="__lunora_metrics_queries",m="__lunora_metrics_queries_buckets",L=6e4,$=90,d=[1,2,5,10,25,50,100,250,500,1e3,5e3],U=512,I=500,p=t=>{let e=t.replaceAll(/\bx'[\da-f]*'/gi,"?").replaceAll(/'(?:[^']|'')*'/g,"?").replaceAll(/\b0x[\da-f]+\b/gi,"?").replaceAll(/(?<![\w$.?:@"])-?\d+(?:\.\d*)?(?:e[+-]?\d+)?(?![\w.])/gi,"?").replaceAll(/(?<![\w$?:@"])-?\.\d+(?:e[+-]?\d+)?(?![\w.])/gi,"?").replaceAll(/\s+/g," ").trim();return e.length>U&&(e=`${e.slice(0,U-1)}…`),e},M=new WeakSet,w=t=>{M.has(t)||(a(t,`CREATE TABLE IF NOT EXISTS "${i}" (
|
|
2
|
-
normalized_sql TEXT PRIMARY KEY,
|
|
3
|
-
exec_count INTEGER NOT NULL DEFAULT 0,
|
|
4
|
-
total_duration_ms REAL NOT NULL DEFAULT 0,
|
|
5
|
-
rows_read INTEGER NOT NULL DEFAULT 0,
|
|
6
|
-
rows_written INTEGER NOT NULL DEFAULT 0
|
|
7
|
-
)`),M.add(t))},h=new WeakMap,A=t=>Math.floor(t/L)*L,f=t=>C(t),y=t=>{const e=d.findIndex(r=>t<=r);return e===-1?d.length:e},T=t=>`lat_${String(t)}`,O=new WeakSet,g=t=>{if(O.has(t))return;const e=Array.from({length:d.length+1},(r,o)=>`${T(o)} INTEGER NOT NULL DEFAULT 0`).join(", ");a(t,`CREATE TABLE IF NOT EXISTS "${m}" (
|
|
8
|
-
sql_hash TEXT NOT NULL,
|
|
9
|
-
bucket_ms INTEGER NOT NULL,
|
|
10
|
-
exec_count INTEGER NOT NULL DEFAULT 0,
|
|
11
|
-
total_duration_ms REAL NOT NULL DEFAULT 0,
|
|
12
|
-
rows_read INTEGER NOT NULL DEFAULT 0,
|
|
13
|
-
rows_written INTEGER NOT NULL DEFAULT 0,
|
|
14
|
-
${e},
|
|
15
|
-
PRIMARY KEY (sql_hash, bucket_ms)
|
|
16
|
-
)`),O.add(t)},B=(t,e)=>{a(t,`DELETE FROM "${m}" WHERE bucket_ms < ?`,A(e)-$*L)},Y=(t,e,r,o,_,c,s=1)=>{try{g(t);const u=s>0?r/s:r,l=T(y(u)),S=`INSERT INTO "${m}" (sql_hash, bucket_ms, exec_count, total_duration_ms, rows_read, rows_written, ${l})
|
|
17
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
18
|
-
ON CONFLICT(sql_hash, bucket_ms) DO UPDATE SET
|
|
19
|
-
exec_count = exec_count + excluded.exec_count,
|
|
20
|
-
total_duration_ms = total_duration_ms + excluded.total_duration_ms,
|
|
21
|
-
rows_read = rows_read + excluded.rows_read,
|
|
22
|
-
rows_written = rows_written + excluded.rows_written,
|
|
23
|
-
${l} = ${l} + excluded.${l}`;a(t,S,f(e),A(c),s,r,o,_,s);const n=A(c);h.get(t)!==n&&(h.set(t,n),B(t,c))}catch{}},x=(t,e)=>{const r=t.reduce((c,s)=>c+s,0);if(r===0)return 0;const o=r*e;let _=0;for(const[c,s]of t.entries())if(_+=s,_>=o)return d[c]??d.at(-1)??0;return d.at(-1)??0},H=(t,e,r=Date.now())=>{try{w(t),g(t)}catch{return{buckets:[],capped:!1,entries:[],trackedStatements:0}}const o=A(r-e),_=Array.from({length:d.length+1},(n,E)=>`SUM(${T(E)}) AS ${T(E)}`).join(", "),c=a(t,`SELECT sql_hash, SUM(exec_count) AS exec_count, SUM(total_duration_ms) AS total_duration_ms,
|
|
24
|
-
SUM(rows_read) AS rows_read, SUM(rows_written) AS rows_written, ${_}
|
|
25
|
-
FROM "${m}" WHERE bucket_ms >= ? GROUP BY sql_hash`,o).toArray(),s=new Map;for(const n of a(t,`SELECT normalized_sql FROM "${i}"`))s.set(f(n.normalized_sql),n.normalized_sql);const u=c.map(n=>{const E=Array.from({length:d.length+1},(G,D)=>Number(n[T(D)]??0)),N=Number(n.exec_count??0),R=Number(n.total_duration_ms??0);return{avgDurationMs:N>0?R/N:0,execCount:N,normalizedSql:s.get(String(n.sql_hash))??String(n.sql_hash),p50DurationMs:x(E,.5),p95DurationMs:x(E,.95),rowsRead:Number(n.rows_read??0),rowsWritten:Number(n.rows_written??0),totalDurationMs:R}});u.sort((n,E)=>E.totalDurationMs-n.totalDurationMs);const l=a(t,`SELECT bucket_ms, SUM(exec_count) AS exec_count, SUM(total_duration_ms) AS total_duration_ms
|
|
26
|
-
FROM "${m}" WHERE bucket_ms >= ? GROUP BY bucket_ms ORDER BY bucket_ms ASC`,o).toArray().map(n=>({avgDurationMs:n.exec_count>0?n.total_duration_ms/n.exec_count:0,bucketMs:n.bucket_ms,execCount:n.exec_count})),S=a(t,`SELECT COUNT(*) AS n FROM "${i}"`).one().n;return{buckets:l,capped:S>=I,entries:u,trackedStatements:S}},k=new WeakMap,Q=t=>{let e=k.get(t);return e===void 0&&(e=new Set,k.set(t,e)),e},z=(t,e)=>{const r=Q(t);return r.has(e)?!0:a(t,`SELECT 1 AS c FROM "${i}" WHERE normalized_sql = ? LIMIT 1`,e).toArray().length>0?(r.add(e),!0):a(t,`SELECT COUNT(*) AS n FROM "${i}"`).one().n>=I?!1:(r.add(e),!0)},P=(t,e,r,o,_,c=Date.now(),s=1)=>{const u=p(e);if(u.length===0||(w(t),!z(t,u)))return;const l=`INSERT INTO "${i}" (normalized_sql, exec_count, total_duration_ms, rows_read, rows_written)
|
|
27
|
-
VALUES (?, ?, ?, ?, ?)
|
|
28
|
-
ON CONFLICT(normalized_sql) DO UPDATE SET
|
|
29
|
-
exec_count = exec_count + excluded.exec_count,
|
|
30
|
-
total_duration_ms = total_duration_ms + excluded.total_duration_ms,
|
|
31
|
-
rows_read = rows_read + excluded.rows_read,
|
|
32
|
-
rows_written = rows_written + excluded.rows_written`;a(t,l,u,s,r,o,_),Y(t,u,r,o,_,c,s)},K=t=>(w(t),a(t,`SELECT normalized_sql, exec_count, total_duration_ms, rows_read, rows_written FROM "${i}" ORDER BY total_duration_ms DESC`).toArray().map(r=>({execCount:r.exec_count,normalizedSql:r.normalized_sql,rowsRead:r.rows_read,rowsWritten:r.rows_written,totalDurationMs:r.total_duration_ms})));export{$ as QUERY_BUCKET_RETENTION,U as QUERY_METRICS_MAX_SQL_LEN,I as QUERY_METRICS_MAX_STATEMENTS,i as QUERY_METRICS_TABLE,y as latencyBucketIndex,p as normalizeSql,B as pruneQueryBuckets,H as readQueryInsights,K as readQueryMetrics,P as recordQueryMetric};
|