From a38fdaa6b2d90662f6e656122916b5b719d15806 Mon Sep 17 00:00:00 2001 From: Francois Blanchette Date: Thu, 23 Nov 2023 19:19:42 -0500 Subject: [PATCH] [PINAX-337] Missing Labels, duplicated Registry --- index.ts | 8 ++++++-- package-lock.json | 10 +++++----- package.json | 2 +- src/prom.ts | 6 ++++-- src/victoria_metrics.ts | 3 +++ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index 21d1992..f3188c3 100644 --- a/index.ts +++ b/index.ts @@ -1,7 +1,7 @@ import { commander, setup, logger } from "substreams-sink"; import { fetchSubstream, createHash } from "@substreams/core"; import { handleImport } from "./src/victoria_metrics.js"; -import { handleOperations } from "./src/prom.js"; +import { handleOperations, register } from "./src/prom.js"; import pkg from "./package.json" assert { type: "json" }; @@ -26,6 +26,7 @@ export interface ActionOptions extends commander.RunOptions { } export async function action(options: ActionOptions) { + const url = `${options.host}/api/v1/import/prometheus` logger.info("url", url) @@ -34,11 +35,14 @@ export async function action(options: ActionOptions) { const hash = createHash(spkg.toBinary()); logger.info("download", options.manifest, hash); + // inject labels + if (options.labels) register.setDefaultLabels(options.labels); + // Run substreams const { emitter } = await setup(options); emitter.on("anyMessage", (messages, _cursor, clock) => { + handleOperations(messages); handleImport(url, options.scrapeInterval, clock); - handleOperations(messages as any); }); // Start streaming diff --git a/package-lock.json b/package-lock.json index a92b699..0b71f5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "substreams-sink-victoria-metrics", - "version": "0.0.14", + "version": "0.0.15", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "substreams-sink-victoria-metrics", - "version": "0.0.14", + "version": "0.0.15", "license": "MIT OR Apache-2.0", "dependencies": { "@substreams/core": "^0.7.0", @@ -285,9 +285,9 @@ } }, "node_modules/bun-types": { - "version": "1.0.13", - "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.0.13.tgz", - "integrity": "sha512-QQH6NLAOU+2tWgQuDSAYBFy+kQwVhPJLB0Q38QLjCmFUZJEYCiiq7tzvU784LAIX2onzO6gr+gIGXt8yCt0cJw==", + "version": "1.0.14", + "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.0.14.tgz", + "integrity": "sha512-hLVfM2fk8xSJeobfuPGilfvxM5gLtEy1bn7RJhrtw3u4OaC0kieXKYFFTVHU8jZ3hj8YyPLIFClIUodkFSrMBQ==", "dev": true }, "node_modules/color-convert": { diff --git a/package.json b/package.json index aa5ceea..a5ee2cd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "substreams-sink-victoria-metrics", - "version": "0.0.14", + "version": "0.0.15", "description": "Substreams VictoriaMetrics sink module", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/prom.ts b/src/prom.ts index f0233da..ffe27dc 100644 --- a/src/prom.ts +++ b/src/prom.ts @@ -1,7 +1,9 @@ import { logger } from "../index.js"; import { Counter, Gauge, Histogram, Summary } from "prom-client"; -import client from "prom-client"; -export const register = new client.Registry(); +import { prometheus } from "substreams-sink" +// prom-client was getting confused because there was +// more than one registy +export const register = prometheus.registry type CounterOp = { operation: string diff --git a/src/victoria_metrics.ts b/src/victoria_metrics.ts index c0b82c0..9d52cb5 100644 --- a/src/victoria_metrics.ts +++ b/src/victoria_metrics.ts @@ -18,5 +18,8 @@ export async function handleImport(url: string, scrapeInterval: number, clock: a const body = appendEpoch(metrics, epoch); await fetch(url, { method: 'POST', body }).catch((error) => { logger.error(error) + }).then(() => { + // console.log(metrics) + // process.exit(0); }); }