diff --git a/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m b/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m index 2ddf70b..e1fa2ee 100644 --- a/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m +++ b/sdk/metrics/+opentelemetry/+sdk/+metrics/View.m @@ -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, ... diff --git a/sdk/metrics/src/ViewProxy.cpp b/sdk/metrics/src/ViewProxy.cpp index 0b80b17..15141ea 100644 --- a/sdk/metrics/src/ViewProxy.cpp +++ b/sdk/metrics/src/ViewProxy.cpp @@ -36,8 +36,10 @@ libmexclass::proxy::MakeResult ViewProxy::make(const libmexclass::proxy::Functio if(aggregation_type == metrics_sdk::AggregationType::kHistogram){ matlab::data::TypedArray histogramBinEdges_mda = constructor_arguments[10]; std::vector 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; } diff --git a/test/tmetrics_sdk.m b/test/tmetrics_sdk.m index ea743a0..f675254 100644 --- a/test/tmetrics_sdk.m +++ b/test/tmetrics_sdk.m @@ -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) @@ -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