Skip to content

Commit

Permalink
feat: update host-metrics to api-metrics v0.27.0 (open-telemetry#779)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <[email protected]>
Co-authored-by: Daniel Dyla <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2021
1 parent c60e934 commit 9cef8a7
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 233 deletions.
4 changes: 2 additions & 2 deletions packages/opentelemetry-host-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
"typescript": "4.3.5"
},
"dependencies": {
"@opentelemetry/api-metrics": "^0.26.0",
"@opentelemetry/api-metrics": "^0.27.0",
"@opentelemetry/core": "^1.0.0",
"@opentelemetry/sdk-metrics-base": "^0.26.0",
"@opentelemetry/sdk-metrics-base": "^0.27.0",
"systeminformation": "^5.0.0"
}
}
52 changes: 0 additions & 52 deletions packages/opentelemetry-host-metrics/src/BaseMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export interface MetricsCollectorConfig {

const DEFAULT_MAX_TIMEOUT_UPDATE_MS = 500;
const DEFAULT_NAME = 'opentelemetry-host-metrics';
const DEFAULT_METRIC_NAME_SEPARATOR = '.';

// default label name to be used to store metric name
const DEFAULT_KEY = 'name';

/**
* Base Class for metrics
Expand All @@ -51,15 +47,11 @@ export abstract class BaseMetrics {
protected _maxTimeoutUpdateMS: number;
protected _meter: metrics.Meter;
private _name: string;
private _boundCounters: { [key: string]: apiMetrics.BoundCounter } = {};
private _metricNameSeparator: string;

constructor(config: MetricsCollectorConfig) {
this._name = config.name || DEFAULT_NAME;
this._maxTimeoutUpdateMS =
config.maxTimeoutUpdateMS || DEFAULT_MAX_TIMEOUT_UPDATE_MS;
this._metricNameSeparator =
config.metricNameSeparator || DEFAULT_METRIC_NAME_SEPARATOR;
const meterProvider =
config.meterProvider! || apiMetrics.metrics.getMeterProvider();
if (!config.meterProvider) {
Expand All @@ -68,50 +60,6 @@ export abstract class BaseMetrics {
this._meter = meterProvider.getMeter(this._name, VERSION);
}

/**
* Creates a metric key name based on metric name and a key
* @param metricName
* @param key
*/
protected _boundKey(metricName: string, key: string) {
if (!key) {
return metricName;
}
return `${metricName}${this._metricNameSeparator}${key}`;
}

/**
* Updates counter based on boundkey
* @param metricName
* @param key
* @param value
*/
protected _counterUpdate(metricName: string, key: string, value = 0) {
const boundKey = this._boundKey(metricName, key);
this._boundCounters[boundKey].add(value);
}

/**
* @param metricName metric name - this will be added as label under name
* "name"
* @param values values to be used to generate bound counters for each
* value prefixed with metricName
* @param description metric description
*/
protected _createCounter(
metricName: string,
values: string[],
description?: string
) {
const keys = values.map(key => this._boundKey(metricName, key));
const counter = this._meter.createCounter(metricName, {
description: description || metricName,
});
keys.forEach(key => {
this._boundCounters[key] = counter.bind({ [DEFAULT_KEY]: key });
});
}

/**
* Creates metrics
*/
Expand Down
Loading

0 comments on commit 9cef8a7

Please sign in to comment.