Skip to content

Commit

Permalink
fix: feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Netail committed Apr 20, 2024
1 parent a3b898f commit a8196e4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
15 changes: 15 additions & 0 deletions packages/opentelemetry-host-metrics/global.d.ts
@@ -1,3 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'systeminformation/lib/network' {
export { networkStats } from 'systeminformation';
}
3 changes: 1 addition & 2 deletions packages/opentelemetry-host-metrics/src/BaseMetrics.ts
Expand Up @@ -45,8 +45,7 @@ export abstract class BaseMetrics {

constructor(config: MetricsCollectorConfig) {
this._name = config.name || DEFAULT_NAME;
const meterProvider =
config.meterProvider || metrics.getMeterProvider();
const meterProvider = config.meterProvider || metrics.getMeterProvider();
if (!config.meterProvider) {
this._logger.warn('No meter provider, using default');
}
Expand Down
31 changes: 17 additions & 14 deletions packages/opentelemetry-host-metrics/src/metric.ts
Expand Up @@ -15,8 +15,18 @@
*/

import { BaseMetrics } from './BaseMetrics';
import { BatchObservableResult, ObservableCounter, ObservableGauge } from '@opentelemetry/api';
import { ATTRIBUTE_NAMES, CPU_LABELS, MEMORY_LABELS, METRIC_NAMES, NETWORK_LABELS } from './enum';
import {
BatchObservableResult,
ObservableCounter,
ObservableGauge,
} from '@opentelemetry/api';
import {
ATTRIBUTE_NAMES,
CPU_LABELS,
MEMORY_LABELS,
METRIC_NAMES,
NETWORK_LABELS,
} from './enum';

import {
getCpuUsageData,
Expand All @@ -25,11 +35,7 @@ import {
getProcessMemoryData,
} from './stats/common';
import { getNetworkData } from './stats/si';
import type {
CpuUsageData,
MemoryData,
ProcessCpuUsageData,
} from './types';
import type { CpuUsageData, MemoryData, ProcessCpuUsageData } from './types';
import type { Systeminformation } from 'systeminformation';

/**
Expand Down Expand Up @@ -188,13 +194,10 @@ export class HostMetrics extends BaseMetrics {
* Creates metrics
*/
protected _createMetrics(): void {
this._cpuTime = this._meter.createObservableCounter(
METRIC_NAMES.CPU_TIME,
{
description: 'Cpu time in seconds',
unit: 's',
}
);
this._cpuTime = this._meter.createObservableCounter(METRIC_NAMES.CPU_TIME, {
description: 'Cpu time in seconds',
unit: 's',
});
this._cpuUtilization = this._meter.createObservableGauge(
METRIC_NAMES.CPU_UTILIZATION,
{
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-host-metrics/src/stats/common.ts
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { type CpuInfo, cpus, totalmem, freemem } from 'os';

import { cpus, totalmem, freemem } from 'os';
import type { CpuInfo } from 'os';
import type { CpuUsageData, MemoryData, ProcessCpuUsageData } from '../types';

const MILLISECOND = 1 / 1e3;
Expand Down
7 changes: 4 additions & 3 deletions packages/opentelemetry-host-metrics/test/metric.test.ts
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

const SI = require('systeminformation');
import * as Network from 'systeminformation/lib/network';
import type { Systeminformation } from 'systeminformation';
import { Attributes } from '@opentelemetry/api';
import {
AggregationTemporality,
Expand Down Expand Up @@ -45,7 +46,7 @@ class TestMetricReader extends MetricReader {
let countSI = 0;
const mockedSI = {
networkStats: function () {
return new Promise((resolve, reject) => {
return new Promise<Systeminformation.NetworkStatsData[]>((resolve, reject) => {
countSI++;
const stats: any[] = networkJson
.slice()
Expand Down Expand Up @@ -137,7 +138,7 @@ describe('Host Metrics', () => {
sandbox
.stub(process.memoryUsage, 'rss')
.callsFake(mockedProcess.memoryUsage.rss);
sandbox.stub(SI, 'networkStats').callsFake(mockedSI.networkStats);
sandbox.stub(Network, 'networkStats').callsFake(mockedSI.networkStats);

reader = new TestMetricReader();

Expand Down

0 comments on commit a8196e4

Please sign in to comment.