Skip to content

Commit

Permalink
fix: remove subpath
Browse files Browse the repository at this point in the history
  • Loading branch information
Netail committed May 24, 2024
1 parent fc23083 commit f675811
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 43 deletions.
18 changes: 0 additions & 18 deletions packages/opentelemetry-host-metrics/global.d.ts

This file was deleted.

5 changes: 1 addition & 4 deletions packages/opentelemetry-host-metrics/src/stats/si.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* limitations under the License.
*/

// Import from network file directly as importing from the root imports the /lib/cpu file,
// resulting in also having to add osx-temperature-sensor as a dependency for macOS,
// while /lib/cpu isn't even used by this package (deep-importing not working as expected)
import { networkStats } from 'systeminformation/lib/network';
import { networkStats } from 'systeminformation';
import type { Systeminformation } from 'systeminformation';

export function getNetworkData() {
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-host-metrics/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

export function ObjectKeys<T extends {}>(t: T) {
export function ObjectKeys<T extends Record<string, unknown>>(t: T) {
return Object.keys(t) as (keyof T)[];
}
37 changes: 19 additions & 18 deletions packages/opentelemetry-host-metrics/test/metric.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as Network from 'systeminformation/lib/network';
import * as SI from 'systeminformation';
import type { Systeminformation } from 'systeminformation';
import { Attributes } from '@opentelemetry/api';
import {
Expand Down Expand Up @@ -46,21 +46,23 @@ class TestMetricReader extends MetricReader {
let countSI = 0;
const mockedSI = {
networkStats: function () {
return new Promise<Systeminformation.NetworkStatsData[]>((resolve, reject) => {
countSI++;
const stats: any[] = networkJson
.slice()
.map((obj: any) => Object.assign({}, obj));

for (let i = 0, j = networkJson.length; i < j; i++) {
Object.keys(stats[i]).forEach(key => {
if (typeof stats[i][key] === 'number' && stats[i][key] > 0) {
stats[i][key] = stats[i][key] * countSI;
}
});
return new Promise<Systeminformation.NetworkStatsData[]>(
(resolve, reject) => {
countSI++;
const stats: any[] = networkJson
.slice()
.map((obj: any) => Object.assign({}, obj));

for (let i = 0, j = networkJson.length; i < j; i++) {
Object.keys(stats[i]).forEach(key => {
if (typeof stats[i][key] === 'number' && stats[i][key] > 0) {
stats[i][key] = stats[i][key] * countSI;
}
});
}
resolve(stats);
}
resolve(stats);
});
);
},
};

Expand Down Expand Up @@ -138,12 +140,11 @@ describe('Host Metrics', () => {
sandbox
.stub(process.memoryUsage, 'rss')
.callsFake(mockedProcess.memoryUsage.rss);
sandbox.stub(Network, 'networkStats').callsFake(mockedSI.networkStats);
sandbox.stub(SI, 'networkStats').callsFake(mockedSI.networkStats);

reader = new TestMetricReader();

meterProvider = new MeterProvider();
meterProvider.addMetricReader(reader);
meterProvider = new MeterProvider({ readers: [reader] });

hostMetrics = new HostMetrics({
meterProvider,
Expand Down
3 changes: 1 addition & 2 deletions packages/opentelemetry-host-metrics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
},
"include": [
"src/**/*.ts",
"test/**/*.ts",
"global.d.ts"
"test/**/*.ts"
]
}

0 comments on commit f675811

Please sign in to comment.