Skip to content

Commit

Permalink
[PINAX-337] Missing Labels, duplicated Registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Blanchette committed Nov 24, 2023
1 parent 5c37d08 commit a38fdaa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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" };

Expand All @@ -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)

Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/prom.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/victoria_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

0 comments on commit a38fdaa

Please sign in to comment.