///
import type { LogContext } from '@balena/jellyfish-logger';
import express from 'express';
import { Server } from 'http';
import type { StreamChange } from './types';
export { Metric, Histogram, MeasureMetricNames, MetricName, ContractMetricNames, WorkerMetricNames, BackSyncMetricNames, SQLMetricNames, StreamMetricNames, MetricNames, } from './types';
/**
* @summary Extract actor name from logContext ID
* @function
*
* @param logContext - log context
* @returns actor name
*
* @example
* ```typescript
* const actorName = actorFromContext(logContext);
* ```
*/
export declare function actorFromContext(logContext: LogContext): string;
/**
* @summary Create express app using metrics and expose data on /metrics
* @function
*
* @returns express app
* @example
* ```typescript
* const application = metrics.initExpress();
* ```
*/
export declare function initExpress(): express.Application;
/**
* Expose gathered metrics on /metrics
* Reassign port to random port number on collision
*
* @function
*
* @param logContext - log context
* @param port - port to expose metrics on
*
* @example
* ```typescript
* const server = startServer(context, 9000);
* ```
*/
export declare function startServer(logContext: LogContext, port: number): Server;
/**
* @summary Mark that a contract was inserted
* @function
*
* @param contract - contract that was inserted
*
* @example
* ```typescript
* markContractInsert(contract);
* ```
*/
export declare function markContractInsert(contract: any): void;
/**
* @summary Mark that a contract was upserted
* @function
*
* @param contract - contract that was upserted
*
* @example
* ```typescript
* markContractUpsert(contract);
* ```
*/
export declare function markContractUpsert(contract: any): void;
/**
* @summary Mark that a contract was read from the database
* @function
*
* @param contract - contract that was read the database
*
* @example
* ```typescript
* markContractReadFromDatabase(contract);
* ```
*/
export declare function markContractReadFromDatabase(contract: any | null): void;
/**
* @summary Mark that a contract was read from cache
* @function
*
* @param contract - contract that was read from cache
*
* @example
* ```typescript
* markContractReadFromCache(contract);
* ```
*/
export declare function markContractReadFromCache(contract: any | null): void;
/**
* @summary Mark that a contract has been created due to back-sync
* @function
*
* @param integration - name of integration
*
* @example
* ```typescript
* markBackSync('front');
* ```
*/
export declare function markBackSync(integration: string): void;
/**
* @summary Mark that an action request was received
* @function
*
* @param action - action name
*
* @example
* ```typescript
* markActionRequest('action-create-card');
* ```
*/
export declare function markActionRequest(action: string): void;
/**
* @summary Expose current queue concurrency setting
* @function
*
* @example
* ```typescript
* markQueueConcurrency();
* ```
*/
export declare function markQueueConcurrency(): void;
/**
* @summary Mark that a new job was added to the queue
* @function
*
* @param action - action name
* @param id - id of the worker
*
* @example
* ```typescript
* metrics.markJobAdd('action-create-card', context.id);
* ```
*/
export declare function markJobAdd(action: string, id: string): void;
/**
* @summary Mark that a job in the queue has completed
* @function
*
* @param action - action name
* @param id - id of the worker
* @param timestamp - when action was completed
*
* @example
* ```typescript
* const action = 'action-create-card';
* const timestamp = '2020-06-08T09:33:27.481Z';
* markJobDone(action, context.id, timestamp)
* ```
*/
export declare function markJobDone(action: string, id: string, timestamp: string): void;
/**
* @summary Execute a mirror, marking duration and totals
* @function
*
* @param integration - name of external integration
* @param fn - mirror function to execute
* @returns mirror result
*
* @example
* ```typescript
* const result = await metrics.measureMirror('github', mirror());
* ```
*/
export declare function measureMirror(integration: string, fn: () => Promise): Promise;
/**
* @summary Execute a translate, marking duration and totals
* @function
*
* @param integration - name of external integration
* @param fn - mirror function to execute
* @returns translate result
*
* @example
* const result = await metrics.measureTranslate('github', translate())
*/
export declare function measureTranslate(integration: string, fn: () => Promise): Promise;
/**
* @summary Measure the duration of a request to the /query api endpoint
* @function
*
* @param {Promise} fn - api function to execute
* @returns {Any} api result
*/
export declare const measureHttpQuery: (fn: () => Promise) => Promise;
/**
* @summary Measure the duration of a request to the /type api endpoint
* @function
*
* @param {Promise} fn - api function to execute
* @returns {Any} api result
*/
export declare const measureHttpType: (fn: () => Promise) => Promise;
/**
* @summary Measure the duration of a request to the /id api endpoint
* @function
*
* @param {Promise} fn - api function to execute
* @returns {Any} api result
*/
export declare const measureHttpId: (fn: () => Promise) => Promise;
/**
* @summary Measure the duration of a request to the /slug api endpoint
* @function
*
* @param {Promise} fn - api function to execute
* @returns {Any} api result
*/
export declare const measureHttpSlug: (fn: () => Promise) => Promise;
/**
* @summary Measure the duration of a request to the /action api endpoint
* @function
*
* @param {Promise} fn - api function to execute
* @returns {Any} api result
*/
export declare const measureHttpAction: (fn: () => Promise) => Promise;
/**
* @summary Measure the duration of a request to the /action api endpoint
* @function
*
* @param {Promise} fn - api function to execute
* @returns {Any} api result
*/
export declare const measureHttpWhoami: (fn: () => Promise) => Promise;
/**
* @summary Mark how long it took to generate an SQL query from a JSON schema
* @function
*
* @param {Number} ms - number of milliseconds it took to generate the query
*/
export declare function markSqlGenTime(ms: number): void;
/**
* @summary Mark how long it took to execute an SQL query
* @function
*
* @param ms - number of milliseconds it took to execute the query
*/
export declare function markQueryTime(ms: number): void;
/**
* @summary Mark that a new stream was opened
* @function
*
* @param logContext - log context
* @param table - table name
*
* @example
* ```typescript
* markStreamOpened(logContext, 'cards');
* ```
*/
export declare function markStreamOpened(logContext: LogContext, table: string): void;
/**
* @summary Mark that a stream was closed
* @function
*
* @param logContext - log context
* @param table - table name
*
* @example
* ```typescript
* markStreamClosed(logContext, 'cards');
* ```
*/
export declare function markStreamClosed(logContext: LogContext, table: string): void;
/**
* @summary Mark that a stream is querying links
* @function
*
* @param logContext - log context
* @param table - table name
* @param change - change event object
*
* @example
* ```typescript
* markStreamLinkQuery(logContext, 'cards', change);
* ```
*/
export declare function markStreamLinkQuery(logContext: LogContext, table: string, change: StreamChange): void;
/**
* @summary Mark that a stream error has occurred
* @function
*
* @param logContext - log context
* @param table - table name
*
* @example
* ```typescript
* metrics.markStreamError(logContext, 'cards');
* ```
*/
export declare function markStreamError(logContext: LogContext, table: string): void;
/**
* @summary Execute a contract patch, marking duration and totals
* @function
*
* @param fn - contract patch function to execute
* @returns contract patch result
*
* @example
* ```typescript
* const result = await measureContractPatch(fn);
* ```
*/
export declare function measureContractPatch(fn: () => Promise): Promise;