@tinkoff/request

@tinkoff/request

  • How to
  • Plugins
  • Internals
  • GitHub

›Plugins

Core

  • Core
  • Context
  • Request execution
  • Plugin

Plugins

  • Plugins
  • Batch
  • Cache - Deduplicate
  • Cache - Fallback
  • Cache - Memory
  • Cache - Etag
  • Cache - Persistent
  • Log
  • Protocol - Http
  • Protocol - Jsonp
  • Transform - Url
  • Validate
  • Circuit Breaker
  • Prom RED metrics
  • Retry

How to

  • How to

Prom RED metrics

Adds RED request metrics for prometheus.

Parameters

Create options

  • metrics: object [={counter, histogram}] - factories for creating prom-client instances;
  • labelNames: array - list of labels for metrics;
  • getLabelsValuesFromContext: function - function for extracting label values from context.
  • prefix: string - prefix for metric names, used to add metrics for more than one plugin instance

Internal meta

  • TIMER_DONE: function - function created at the time of sending and called at the end of the request to calculate its duration.

Example

Base usage

import request from '@tinkoff/request-core';
import promRedMetrics from '@tinkoff/request-plugin-prom-red-metrics';
import promClient from 'prom-client';

const req = request([
    promRedMetrics({
        metrics: {
            counter: (options) => new promClient.Counter(options), // here you can mix any of your own parameters
            histogram: (options) => new promClient.Histogram(options),
        },
        prefix: 'api',
        labelNames: ['host', 'port'],
        getLabelsValuesFromContext: (context) => {
            const { host, port } = context.getRequest()

            return { host, port };
        },
    }),
    // ...other plugins
]);

Use with @tinkoff/request-plugin-protocol-http

import request from '@tinkoff/request-core';
import { httpMetrics } from '@tinkoff/request-plugin-prom-red-metrics';
import http from '@tinkoff/request-plugin-protocol-http';
import promClient from 'prom-client';

const req = request([
    httpMetrics({
        metrics: {
            counter: (options) => new promClient.Counter(options), // here you can mix any of your own parameters
            histogram: (options) => new promClient.Histogram(options),
        },
        // variables for the http protocol are predefined in the httpMetrics file
    }),
    http(),
]);
← Circuit BreakerRetry →
  • Parameters
    • Create options
    • Internal meta
  • Example
    • Base usage
    • Use with @tinkoff/request-plugin-protocol-http
Copyright © 2023 tinkoff.ru