Skip to content

Commit

Permalink
feat: add authentication (#21)
Browse files Browse the repository at this point in the history
* add authentication

* fix build
  • Loading branch information
menduz authored Apr 19, 2021
1 parent b7c19e4 commit 4d21ff4
Show file tree
Hide file tree
Showing 13 changed files with 429 additions and 402 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

`npm i @well-known-components/metrics`

## Configuration via config component

Here is a list of configuration keys that may be used by this component:

- `WKC_METRICS_PUBLIC_PATH`: `string` path to expose metrics, default: `/metrics`
- `WKC_METRICS_BEARER_TOKEN`: `string` bearer token to protect metrics, default: _not set_
- `WKC_METRICS_COLLECT_DEFAULT`: `"true" | "false"` collect default nodejs metrics, default: `true`

## Define your metrics in a static file

```ts
Expand All @@ -19,7 +27,7 @@ export const metricDeclarations = {
type: IMetricsComponent.CounterType,
help: "Count calls to /user/:userId",
labelNames: ["userId"],
}
},
}

// type assertions
Expand All @@ -46,10 +54,10 @@ export async function initComponents(): Promise<AppComponents> {
## Register metrics

```ts
export async function userIdHandler(context: {
components: Pick<AppComponents, "metrics">
}) {
const { components: { metrics } } = context
export async function userIdHandler(context: { components: Pick<AppComponents, "metrics"> }) {
const {
components: { metrics },
} = context

metrics.increment("user_counter", { userId: Math.random() })
// metrics.decrement("user_counter", { userId: Math.random() })
Expand Down
8 changes: 7 additions & 1 deletion etc/metrics.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ import { IHttpServerComponent } from '@well-known-components/interfaces';
import { IMetricsComponent } from '@well-known-components/interfaces';
import { Registry } from 'prom-client';

// @public
export const CONFIG_PREFIX: "WKC_METRICS";

// @internal (undocumented)
export function _configKey(key: Uppercase<string>): string;

// @public (undocumented)
export function createMetricsComponent<K extends string, V extends object = {}>(metricsDefinition: IMetricsComponent.MetricsRecordDefinition<K>, components: {
server: IHttpServerComponent<V>;
server?: IHttpServerComponent<V>;
config: IConfigComponent;
}): Promise<IMetricsComponent<K> & IBaseComponent>;

Expand Down
Loading

0 comments on commit 4d21ff4

Please sign in to comment.