Skip to content

Commit

Permalink
new retry metrics, better eslint (#2)
Browse files Browse the repository at this point in the history
* new retry metrics, better eslint

* create common getMetricName method
  • Loading branch information
cadgerfeast authored Jul 27, 2021
1 parent 41a46bd commit b20588a
Show file tree
Hide file tree
Showing 21 changed files with 291 additions and 65 deletions.
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"max-len": [2, { "code": 160 }],
"no-unused-expressions": [2, { "allowShortCircuit": true, "allowTernary": true }],
"no-return-await": [2],
"consistent-return": [2],
"default-case-last": [2],
"@typescript-eslint/await-thenable": [2],
"@typescript-eslint/no-unused-vars": [2]
"@typescript-eslint/no-unused-vars": [2],
"semi": "off",
"@typescript-eslint/semi": [2]
}
}
4 changes: 2 additions & 2 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ jobs:
publish_dir: ./docs/dist
- name: Release
if: github.event_name == 'push' && steps.env.outputs.SHOULD_RELEASE == 'true'
run: npx release-it --ci --verbose --disable-metrics --increment=${{steps.env.outputs.VERSION}}
run: npx release-it@14.6.2 --ci --verbose --disable-metrics --increment=${{steps.env.outputs.VERSION}}
env:
GIT_AUTHOR_NAME: Github Action
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: Github Action
GIT_COMMITTER_EMAIL: [email protected]
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
13 changes: 11 additions & 2 deletions docs/content/module/retry.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ title: Mollitia Prometheus - Module - Retry

## Common Metrics

| Name | Description | Type |
|:-------------------|:-----------------------------------------------|:----------|
| Name | Description | Type |
|:-------------------|:----------------------------------------------|:----------|
| `total_executions` | The amount of times the module has been used. | `Counter` |
| `total_success` | The amount of times the module suceeded. | `Counter` |
| `total_failures` | The amount of times the module failed. | `Counter` |
| `duration_max` | The maximum duration of the module execution. | `Gauge` |
| `duration_ave` | The average duration of the module execution. | `Gauge` |
| `duration_min` | The minimum duration of the module execution. | `Gauge` |

## Retry Metrics

| Name | Description | Type |
|:---------------------------|:--------------------------------------------------------|:----------|
| `success_without_retries` | The amount of executions that succeed without retrying. | `Counter` |
| `success_with_retries` | The amount of executions that succeed after retrying. | `Counter` |
| `failures_without_retries` | The amount of executions that failed without retrying. | `Counter` |
| `failures_with_retries` | The amount of executions that failed after retrying. | `Gauge` |
6 changes: 3 additions & 3 deletions docs/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 docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@nuxt/typescript-runtime": "2.1.0",
"@nuxtjs/pwa": "3.3.5",
"core-js": "3.10.1",
"mollitia": "0.0.4",
"mollitia": "0.0.6",
"nuxt": "2.15.4"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
setupFilesAfterEnv: [
"./test/_setup.ts"
],
forceExit: true,
collectCoverage: true,
collectCoverageFrom: [
"src/**/*.ts",
Expand Down
42 changes: 21 additions & 21 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mollitia/prometheus",
"version": "0.0.7",
"version": "0.0.8",
"description": "Prometheus Mollitia Addon",
"main": "dist/mollitia-prometheus.umd.js",
"module": "dist/mollitia-prometheus.es5.js",
Expand Down Expand Up @@ -34,6 +34,7 @@
"graphing"
],
"scripts": {
"install:all": "npm i && cd ./docs && npm i",
"dev": "run-p dev:lib dev:docs",
"dev:lib": "npm run build:lib:tsc && run-p dev:lib:tsc dev:lib:rollup",
"dev:lib:tsc": "tsc --watch --module commonjs",
Expand Down Expand Up @@ -65,7 +66,7 @@
"@typescript-eslint/parser": "4.16.1",
"eslint": "7.24.0",
"jest": "26.6.3",
"mollitia": "0.0.4",
"mollitia": "0.0.6",
"npm-run-all": "4.1.5",
"rimraf": "3.0.2",
"rollup": "2.45.2",
Expand Down
2 changes: 1 addition & 1 deletion src/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ export interface PrometheusCircuitData extends PrometheusCircuitOptions {
export const attachMetrics = (circuit: Mollitia.Circuit, options: Mollitia.CircuitOptions): PrometheusCircuitMetrics => {
const metrics = commonMetrics(circuit, options);
return metrics;
}
};
25 changes: 14 additions & 11 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { PrometheusGauge } from './metrics/gauge';

type durationType = {
[key: string]: number;
}
};

export interface PrometheusCommonMetrics {
[key: string]: PrometheusMetric;
/**
Expand Down Expand Up @@ -38,6 +39,15 @@ export interface PrometheusCommonMetrics {
duration_count: PrometheusGauge;
}

export const getMetricName = (executor: Mollitia.Circuit|Mollitia.Module) => {
if (executor.constructor.name === Mollitia.Circuit.name) {
const circuit = executor as Mollitia.Circuit;
return circuit.prometheus.perMethod ? `${circuit.prometheus.name}_${circuit.prometheus.funcName}` : executor.prometheus.name;
} else {
return executor.prometheus.name;
}
};

export const commonMetrics = (executor: Mollitia.Circuit|Mollitia.Module, options: Mollitia.CircuitOptions|Mollitia.ModuleOptions): PrometheusCommonMetrics => {
let labels = options.prometheus?.labels;
if (executor.constructor.name !== Mollitia.Circuit.name) {
Expand Down Expand Up @@ -97,17 +107,10 @@ export const commonMetrics = (executor: Mollitia.Circuit|Mollitia.Module, option
}
);

// Handlers
// eslint-disable-next-line @typescript-eslint/no-explicit-any
executor.on('execute', (executor: Mollitia.Circuit|Mollitia.Module, promise: Promise<any>) => {
let metricName = '';
if (executor.constructor.name === Mollitia.Circuit.name) {
metricName =
(executor as Mollitia.Circuit).prometheus.perMethod ?
`${executor.prometheus.name}_${(executor as Mollitia.Circuit).prometheus.funcName}` :
executor.prometheus.name;
} else {
metricName = executor.prometheus.name;
}
const metricName = getMetricName(executor);
totalDuration[metricName] = totalDuration[metricName] || 0;

const start = Date.now();
Expand Down Expand Up @@ -143,4 +146,4 @@ export const commonMetrics = (executor: Mollitia.Circuit|Mollitia.Module, option
duration_min,
duration_count
};
}
};
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const scrap = (): string => {
_metrics[metric] = {
help: circuit.prometheus.metrics[metric].scrapHelp(),
value: circuit.prometheus.metrics[metric].scrapValues()
}
};
}
}
}
Expand All @@ -210,8 +210,8 @@ export const scrap = (): string => {
} else {
_metrics[metric] = {
help: module.prometheus.metrics[metric].scrapHelp(),
value: module.prometheus.metrics[metric].scrapValues()
}
value: module.prometheus.metrics[metric].scrapValues()
};
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/metrics/counter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrometheusLabels, PrometheusMetric, PrometheusMetricLabelValues, PrometheusMetricType } from './index'
import { PrometheusLabels, PrometheusMetric, PrometheusMetricLabelValues, PrometheusMetricType } from './index';

interface PrometheusCounterOptions {
description: string;
Expand All @@ -19,7 +19,7 @@ export class PrometheusCounter implements PrometheusMetric {
this.type = PrometheusMetricType.COUNTER;
this.labels = options?.labels || {};
this.values = {};
if (options?.description) { this.description = options?.description }
if (options?.description) { this.description = options?.description; }
}
// Public Methods
public inc (value = 1, circuitName: string): number {
Expand Down
6 changes: 3 additions & 3 deletions src/metrics/gauge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PrometheusLabels, PrometheusMetric, PrometheusMetricLabelValues, PrometheusMetricType } from './index'
import { PrometheusLabels, PrometheusMetric, PrometheusMetricLabelValues, PrometheusMetricType } from './index';

interface PrometheusGaugeOptions {
description: string;
Expand All @@ -19,7 +19,7 @@ export class PrometheusGauge implements PrometheusMetric {
this.type = PrometheusMetricType.GAUGE;
this.labels = options?.labels || {};
this.values = {};
if (options?.description) { this.description = options?.description }
if (options?.description) { this.description = options?.description; }
}
// Public Methods
public inc (value = 1, circuitName: string): number {
Expand Down Expand Up @@ -62,4 +62,4 @@ export class PrometheusGauge implements PrometheusMetric {
this.values = {};
return res;
}
}
}
2 changes: 1 addition & 1 deletion src/module/breaker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export const attachMetrics = (module: Mollitia.Module, options: Mollitia.ModuleO
// TODO total_failures_open
// TODO total_failures_slow
return metrics;
}
};
2 changes: 1 addition & 1 deletion src/module/bulkhead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export const attachMetrics = (module: Mollitia.Module, options: Mollitia.ModuleO
// TODO max_queued
// TODO total_failures_max_queue_wait
return metrics;
}
};
2 changes: 1 addition & 1 deletion src/module/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export const attachMetrics = (module: Mollitia.Module, options: Mollitia.ModuleO
// TODO total_cache_hit
// TODO total_cache_hit_old
return metrics;
}
};
2 changes: 1 addition & 1 deletion src/module/fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export interface PrometheusFallbackData extends PrometheusModuleOptions {
export const attachMetrics = (module: Mollitia.Module, options: Mollitia.ModuleOptions): PrometheusFallbackMetrics => {
const metrics = commonMetrics(module, options);
return metrics;
}
};
2 changes: 1 addition & 1 deletion src/module/ratelimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ export const attachMetrics = (module: Mollitia.Module, options: Mollitia.ModuleO
const metrics = commonMetrics(module, options);
// TODO total_failures_ratelimit
return metrics;
}
};
Loading

0 comments on commit b20588a

Please sign in to comment.