Skip to content

Commit

Permalink
Changes to view sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dnarula-mw committed Nov 28, 2023
1 parent 489c56e commit 61b93aa
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 68 deletions.
4 changes: 2 additions & 2 deletions sdk/metrics/+opentelemetry/+sdk/+metrics/View.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
aggregation, histogramBinEdges, varargin)

instrumentTypeCategory = int32(find(instrumentType==["kCounter", "kHistogram", "kUpDownCounter", "kObservableCounter", "kObservableGauge", "kObservableUpDownCounter"])-1);
aggregationCategory = int32(find(instrumentType==["kDrop", "kHistogram", "kLastValue", "kSum", "kDefault"])-1);

aggregationCategory = int32(find(aggregation==["kDrop", "kHistogram", "kLastValue", "kSum", "kDefault"])-1);

obj.Proxy = libmexclass.proxy.Proxy("Name", "libmexclass.opentelemetry.sdk.ViewProxy", ...
"ConstructorArguments", {name, description, unit, instrumentName, ...
Expand Down
6 changes: 4 additions & 2 deletions sdk/metrics/src/ViewProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ libmexclass::proxy::MakeResult ViewProxy::make(const libmexclass::proxy::Functio
if(aggregation_type == metrics_sdk::AggregationType::kHistogram){
matlab::data::TypedArray<double> histogramBinEdges_mda = constructor_arguments[10];
std::vector<double> histogramBinEdges;
for (auto h : histogramBinEdges_mda) {
histogramBinEdges.push_back(h);
if(histogramBinEdges_mda.getNumberOfElements() > 0){
for (auto h : histogramBinEdges_mda) {
histogramBinEdges.push_back(h);
}
}
aggregation_config->boundaries_ = histogramBinEdges;
}
Expand Down
155 changes: 91 additions & 64 deletions test/tmetrics_sdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function setup(testCase)
end
end

methods (TestMethodTeardown)
function teardown(testCase)
commonTeardown(testCase);
end
end
% methods (TestMethodTeardown)
% function teardown(testCase)
% commonTeardown(testCase);
% end
% end

methods (Test)
function testDefaultExporter(testCase)
Expand Down Expand Up @@ -146,65 +146,92 @@ function testCustomResource(testCase)
end
end

% function testViewCounter(testCase)
% % testCustomResource: check custom resources are included in
% % emitted metrics
% commonSetup(testCase)
%
% exporter = opentelemetry.exporters.otlp.OtlpHttpMetricExporter();
% reader = opentelemetry.sdk.metrics.PeriodicExportingMetricReader(exporter, ...
% "Interval", seconds(2), "Timeout", seconds(1));
% mp = opentelemetry.sdk.metrics.MeterProvider(reader);
%
% m = getMeter(mp, "mymeter");
% c = createCounter(m, "mycounter");
%
% % create testing value
% val = 10;
%
% % add value and attributes
% c.add(val);
%
% pause(2.5);
%
% view = opentelemetry.sdk.metrics.View("View", "my View", "Unit", "Instrument", "kCounter", "mymeter", "", "", ["One" "Two" "Three"], "kDrop", [0 100 200 300 400 500]);
%
% addView(mp, view);
%
% clear mp;
%
% % % TODO: add test comparisons
% end

% function testViewHistogram(testCase)
% % testCustomResource: check custom resources are included in
% % emitted metrics
% commonSetup(testCase)
%
% exporter = opentelemetry.exporters.otlp.OtlpHttpMetricExporter();
% reader = opentelemetry.sdk.metrics.PeriodicExportingMetricReader(exporter, ...
% "Interval", seconds(2), "Timeout", seconds(1));
% mp = opentelemetry.sdk.metrics.MeterProvider(reader);
% m = mp.getMeter("mymeter");
% hist = m.createHistogram("histogram");
%
% % create value for histogram
% val = 1;
%
% % record value
% hist.record(val);
%
% % wait for collector response
% pause(2.5);
%
% view = opentelemetry.sdk.metrics.View("View", "my View", "Unit", "Instrument", "kHistogram", "mymeter", "", "", ["One" "Two" "Three"], "kHistogram", [0 100 200 300 400 500]);
%
% addView(mp, view);
%
% clear mp;
%
% % % TODO: add test comparisons
% end
function testViewCounter(testCase)
% testCustomResource: check custom resources are included in
% emitted metrics

exporter = opentelemetry.exporters.otlp.OtlpHttpMetricExporter();
reader = opentelemetry.sdk.metrics.PeriodicExportingMetricReader(exporter, ...
"Interval", seconds(2), "Timeout", seconds(1));
mp = opentelemetry.sdk.metrics.MeterProvider(reader);

m = getMeter(mp, "mymeter");
c = createCounter(m, "mycounter");

% create testing value
val = 10;

% add value and attributes
c.add(val);

pause(2.5);

view = opentelemetry.sdk.metrics.View("View", "my View", "", "", "kCounter", "mymeter", "", "", "", "kDrop", []);

addView(mp, view);

clear mp;

% % TODO: add test comparisons
end

function testViewUpDownCounter(testCase)
% test names and added value in UpDownCounter

exporter = opentelemetry.exporters.otlp.OtlpHttpMetricExporter();
reader = opentelemetry.sdk.metrics.PeriodicExportingMetricReader(exporter, ...
"Interval", seconds(2), "Timeout", seconds(1));
mp = opentelemetry.sdk.metrics.MeterProvider(reader);

m = getMeter(mp, "mymeter");
c = createUpDownCounter(m, "mycounter");

% create testing value
val = -10;

% add value and attributes
c.add(val);

% wait for collector response time (2s)
pause(5);

view = opentelemetry.sdk.metrics.View("View", "my View", "Unit", "MyGauge", "kUpDownCounter", "mymeter", "", "", "", "kLastValue", []);

addView(mp, view);

clear mp;

% % TODO: add test comparisons
end

function testViewHistogram(testCase)
% testCustomResource: check custom resources are included in
% emitted metrics

exporter = opentelemetry.exporters.otlp.OtlpHttpMetricExporter();
reader = opentelemetry.sdk.metrics.PeriodicExportingMetricReader(exporter, ...
"Interval", seconds(2), "Timeout", seconds(1));
mp = opentelemetry.sdk.metrics.MeterProvider(reader);
m = mp.getMeter("mymeter");
hist = m.createHistogram("histogram");

% create value for histogram
val = 1;

% record value
hist.record(val);

% wait for collector response
pause(2.5);

view = opentelemetry.sdk.metrics.View("View", "my View", "", "", "kHistogram", "mymeter", "", "", "", "kHistogram", [0 100 200 300 400 500]);

addView(mp, view);

clear mp;

% % TODO: add test comparisons
end

function testShutdown(testCase)
% testShutdown: shutdown method should stop exporting
Expand Down

0 comments on commit 61b93aa

Please sign in to comment.