UNPKG

prometheus-pushgw-kafka-connect

Version:
69 lines (54 loc) 1.84 kB
"use strict"; const { runSinkConnector, ConverterFactory } = require("./../index.js"); const config = require("./config.js"); console.log("******************"); console.log("Produce to kafka topic just like in config, with the following schema:"); console.log({metric: "STRING - required", value: "NUMBER - required", label: "STRING", type: 'ENUM - ("untyped", "gauge", "counter")', help: "STRING"}); console.log("The consumed schema can be different, just need to adjust to that schema in ETL function"); console.log("******************"); console.log("Example:"); console.log({metric: "pi_metric", value: 3.14159}); console.log("******************"); console.log("Waiting for message to be consumed..."); const etl = (message, next) => { let record; if (message.payload.activity!== "order_created") { return next(); } // Do the transformation here // Below is the expected schema of the object try { record = { metric: message.payload.activity, value: message.payload.payload.orderValue, label: message.payload.payload.marketId } } catch(err) { // Continue with throwing return next(err); } if (record && record.metric && record.value) { // Continue with the transformed record console.log(message); console.log("Processed"); return next(null, record); } // Continue without throwing error console.log("Not processed"); return next(); } const converter = ConverterFactory.createSinkSchemaConverter(null,etl); runSinkConnector(config, [converter], console.log.bind(console)).then(sink => { const exit = (isExit = false) => { sink.stop(); if (!isExit) { process.exit(); } }; process.on("SIGINT", () => { exit(false); }); process.on("exit", () => { exit(true); }); });