Skip to content

Commit a16b03e

Browse files
committed
logs performance test and some refactoring of metrics performance test
1 parent 454ae64 commit a16b03e

File tree

2 files changed

+150
-12
lines changed

2 files changed

+150
-12
lines changed

test/performance/logsTest.m

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
classdef logsTest < matlab.perftest.TestCase
2+
% performance tests for logs
3+
4+
% Copyright 2024 The MathWorks, Inc.
5+
6+
properties
7+
OtelConfigFile
8+
JsonFile
9+
PidFile
10+
OtelcolName
11+
Otelcol
12+
ListPid
13+
ReadPidList
14+
ExtractPid
15+
Sigint
16+
Sigterm
17+
end
18+
19+
methods (TestClassSetup)
20+
function setupOnce(testCase)
21+
% add directory where common setup and teardown code lives
22+
utilsfolder = fullfile(fileparts(mfilename('fullpath')), "..", "utils");
23+
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(utilsfolder));
24+
25+
commonSetupOnce(testCase);
26+
27+
% create a global logger provider
28+
import opentelemetry.sdk.logs.*
29+
lp = LoggerProvider(BatchLogRecordProcessor());
30+
setLoggerProvider(lp);
31+
end
32+
end
33+
34+
methods (TestMethodSetup)
35+
function setup(testCase)
36+
commonSetup(testCase);
37+
end
38+
end
39+
40+
methods (TestMethodTeardown)
41+
function teardown(testCase)
42+
% Flush any log records that have not yet been exported
43+
lp = opentelemetry.logs.Provider.getLoggerProvider();
44+
opentelemetry.sdk.common.Cleanup.forceFlush(lp);
45+
46+
commonTeardown(testCase);
47+
end
48+
end
49+
50+
methods (Test)
51+
function testEmitLogRecord(testCase)
52+
% create and emit a log record
53+
lg = opentelemetry.logs.getLogger("foo");
54+
55+
testCase.startMeasuring();
56+
% run through a loop since the time for 1 iteration is too short
57+
for i = 1:10
58+
emitLogRecord(lg, "info", "bar");
59+
end
60+
testCase.stopMeasuring();
61+
end
62+
63+
function testAttributes(testCase)
64+
% create and emit a log record with attributes
65+
lg = opentelemetry.logs.getLogger("foo");
66+
attrs = dictionary(["attribute1", "attribute2"], ["value1", "value2"]);
67+
68+
testCase.startMeasuring();
69+
emitLogRecord(lg, "info", "bar", Attributes=attrs);
70+
testCase.stopMeasuring();
71+
end
72+
73+
function testFrontEndAPI(testCase)
74+
% Call frontend API functions to emit a log record (trace,
75+
% debug, info, warn, error, fatal)
76+
lg = opentelemetry.logs.getLogger("foo");
77+
78+
testCase.startMeasuring();
79+
trace(lg, "bar");
80+
debug(lg, "bar");
81+
info(lg, "bar");
82+
warn(lg, "bar");
83+
error(lg, "bar");
84+
fatal(lg, "bar");
85+
testCase.stopMeasuring();
86+
end
87+
88+
function testGetLogger(testCase)
89+
% get a logger from the global logger provider instance
90+
testCase.startMeasuring();
91+
lg = opentelemetry.logs.getLogger("foo"); %#ok<*NASGU>
92+
testCase.stopMeasuring();
93+
end
94+
95+
function testCreateDefaultLoggerProvider(testCase)
96+
% create default LoggerProvider in the sdk
97+
testCase.startMeasuring();
98+
lp = opentelemetry.sdk.logs.LoggerProvider();
99+
testCase.stopMeasuring();
100+
end
101+
end
102+
end

test/performance/metricsTest.m

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,34 @@ function teardown(testCase)
5151
end
5252

5353
methods (Test)
54-
function testCounter(testCase)
55-
% create and increment a counter
54+
function testCreateCounter(testCase)
55+
% create a counter
5656
mt = opentelemetry.metrics.getMeter("foo");
5757

5858
testCase.startMeasuring();
5959
c = createCounter(mt, "bar");
60-
add(c, 5);
6160
testCase.stopMeasuring();
6261
end
6362

64-
function testUpDownCounter(testCase)
65-
% create and increment an up-down-counter
63+
function testCreateUpDownCounter(testCase)
64+
% create an up-down-counter
6665
mt = opentelemetry.metrics.getMeter("foo");
6766

6867
testCase.startMeasuring();
6968
c = createUpDownCounter(mt, "bar");
70-
add(c, -5);
7169
testCase.stopMeasuring();
7270
end
7371

74-
function testHistogram(testCase)
75-
% create a histogram and record a value
72+
function testCreateHistogram(testCase)
73+
% create a histogram
7674
mt = opentelemetry.metrics.getMeter("foo");
7775

7876
testCase.startMeasuring();
7977
h = createHistogram(mt, "bar");
80-
record(h, 111);
8178
testCase.stopMeasuring();
8279
end
8380

84-
function testObservableCounter(testCase)
81+
function testCreateObservableCounter(testCase)
8582
% create an observable counter
8683
mt = opentelemetry.metrics.getMeter("foo");
8784

@@ -90,7 +87,7 @@ function testObservableCounter(testCase)
9087
testCase.stopMeasuring();
9188
end
9289

93-
function testObservableUpDownCounter(testCase)
90+
function testCreateObservableUpDownCounter(testCase)
9491
% create an observable up-down-counter
9592
mt = opentelemetry.metrics.getMeter("foo");
9693

@@ -99,7 +96,7 @@ function testObservableUpDownCounter(testCase)
9996
testCase.stopMeasuring();
10097
end
10198

102-
function testObservableGauge(testCase)
99+
function testCreateObservableGauge(testCase)
103100
% create an observable gauge
104101
mt = opentelemetry.metrics.getMeter("foo");
105102

@@ -108,6 +105,45 @@ function testObservableGauge(testCase)
108105
testCase.stopMeasuring();
109106
end
110107

108+
function testCounterAdd(testCase)
109+
% increment a counter
110+
mt = opentelemetry.metrics.getMeter("foo");
111+
c = createCounter(mt, "bar");
112+
113+
testCase.startMeasuring();
114+
% run through a loop since the time for 1 iteration is too short
115+
for i = 1:10
116+
add(c, 5);
117+
end
118+
testCase.stopMeasuring();
119+
end
120+
121+
function testUpDownCounterAdd(testCase)
122+
% Increment an up-down-counter
123+
mt = opentelemetry.metrics.getMeter("foo");
124+
c = createUpDownCounter(mt, "bar");
125+
126+
testCase.startMeasuring();
127+
% run through a loop since the time for 1 iteration is too short
128+
for i = 1:10
129+
add(c, -5);
130+
end
131+
testCase.stopMeasuring();
132+
end
133+
134+
function testHistogramRecord(testCase)
135+
% record a histogram value
136+
mt = opentelemetry.metrics.getMeter("foo");
137+
h = createHistogram(mt, "bar");
138+
139+
testCase.startMeasuring();
140+
% run through a loop since the time for 1 iteration is too short
141+
for i = 1:10
142+
record(h, 111);
143+
end
144+
testCase.stopMeasuring();
145+
end
146+
111147
function testCounterAttributes(testCase)
112148
% increment counter with attributes
113149
mt = opentelemetry.metrics.getMeter("foo");

0 commit comments

Comments
 (0)