-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from mathworks/metrics_view
Adding View Class in metrics sdk and add view method to meter provider
- Loading branch information
Showing
9 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
classdef View | ||
|
||
% Copyright 2023 The MathWorks, Inc. | ||
|
||
properties (GetAccess={?opentelemetry.sdk.metrics.MeterProvider}) | ||
Proxy % Proxy object to interface C++ code | ||
end | ||
|
||
properties (SetAccess=immutable) | ||
Name | ||
Description | ||
Unit | ||
InstrumentName | ||
InstrumentType | ||
MeterName | ||
MeterVersion | ||
MeterSchemaURL | ||
AttributeKeys | ||
Aggregation | ||
HistogramBinEdges | ||
end | ||
|
||
methods | ||
function obj = View(name, description, unit, instrumentName, instrumentType, ... | ||
meterName, meterVersion, meterSchemaURL, attributeKeys, ... | ||
aggregation, histogramBinEdges, varargin) | ||
|
||
instrumentTypeCategory = int32(find(instrumentType==["kCounter", "kHistogram", "kUpDownCounter", "kObservableCounter", "kObservableGauge", "kObservableUpDownCounter"])-1); | ||
|
||
aggregationCategory = int32(find(instrumentType==["kDrop", "kHistogram", "kLastValue", "kSum", "kDefault"])-1); | ||
|
||
obj.Proxy = libmexclass.proxy.Proxy("Name", "libmexclass.opentelemetry.sdk.ViewProxy", ... | ||
"ConstructorArguments", {name, description, unit, instrumentName, ... | ||
instrumentTypeCategory, meterName, meterVersion, meterSchemaURL, ... | ||
attributeKeys, aggregationCategory, histogramBinEdges, varargin}); | ||
obj.Description = description; | ||
obj.Unit = unit; | ||
obj.InstrumentName = instrumentName; | ||
obj.InstrumentType = instrumentType; | ||
obj.MeterName = meterName; | ||
obj.MeterVersion = meterVersion; | ||
obj.MeterSchemaURL = meterSchemaURL; | ||
obj.AttributeKeys = attributeKeys; | ||
obj.Aggregation = aggregation; | ||
obj.HistogramBinEdges = histogramBinEdges; | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
sdk/metrics/include/opentelemetry-matlab/sdk/metrics/ViewProxy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The MathWorks, Inc. | ||
|
||
#pragma once | ||
|
||
#include "libmexclass/proxy/Proxy.h" | ||
#include "libmexclass/proxy/method/Context.h" | ||
|
||
#include "libmexclass/proxy/ProxyManager.h" | ||
|
||
#include "opentelemetry/sdk/metrics/view/view.h" | ||
#include "opentelemetry/sdk/metrics/view/view_factory.h" | ||
#include "opentelemetry/sdk/metrics/instruments.h" | ||
#include "opentelemetry/sdk/metrics/aggregation/aggregation.h" | ||
#include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" | ||
#include "opentelemetry/sdk/metrics/view/attributes_processor.h" | ||
#include "opentelemetry/sdk/metrics/view/instrument_selector.h" | ||
#include "opentelemetry/sdk/metrics/view/instrument_selector_factory.h" | ||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/sdk/metrics/view/meter_selector.h" | ||
#include "opentelemetry/sdk/metrics/view/meter_selector_factory.h" | ||
|
||
|
||
#include "opentelemetry-matlab/sdk/metrics/ViewProxy.h" | ||
|
||
namespace metrics_sdk = opentelemetry::sdk::metrics; | ||
namespace nostd = opentelemetry::nostd; | ||
|
||
namespace libmexclass::opentelemetry::sdk { | ||
class ViewProxy : public libmexclass::proxy::Proxy { | ||
public: | ||
ViewProxy(std::unique_ptr<metrics_sdk::View> view, std::unique_ptr<metrics_sdk::InstrumentSelector> instrumentSelector, std::unique_ptr<metrics_sdk::MeterSelector> meterSelector); | ||
|
||
static libmexclass::proxy::MakeResult make(const libmexclass::proxy::FunctionArguments& constructor_arguments); | ||
|
||
// void processView(libmexclass::proxy::method::Context& context); | ||
|
||
std::unique_ptr<metrics_sdk::View> getView(libmexclass::proxy::method::Context& context); | ||
|
||
std::unique_ptr<metrics_sdk::InstrumentSelector> getInstrumentSelector(libmexclass::proxy::method::Context& context); | ||
|
||
std::unique_ptr<metrics_sdk::MeterSelector> getMeterSelector(libmexclass::proxy::method::Context& context); | ||
|
||
private: | ||
std::unique_ptr<metrics_sdk::View> View; | ||
|
||
std::unique_ptr<metrics_sdk::InstrumentSelector> InstrumentSelector; | ||
|
||
std::unique_ptr<metrics_sdk::MeterSelector> MeterSelector; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2023 The MathWorks, Inc. | ||
|
||
#include "opentelemetry-matlab/sdk/metrics/ViewProxy.h" | ||
|
||
#include "libmexclass/proxy/ProxyManager.h" | ||
|
||
#include <chrono> | ||
|
||
namespace libmexclass::opentelemetry::sdk { | ||
ViewProxy::ViewProxy(std::unique_ptr<metrics_sdk::View> view, std::unique_ptr<metrics_sdk::InstrumentSelector> instrumentSelector, std::unique_ptr<metrics_sdk::MeterSelector> meterSelector){ | ||
View = std::move(view); | ||
InstrumentSelector = std::move(instrumentSelector); | ||
MeterSelector = std::move(meterSelector); | ||
REGISTER_METHOD(ViewProxy, getView); | ||
REGISTER_METHOD(ViewProxy, getInstrumentSelector); | ||
REGISTER_METHOD(ViewProxy, getMeterSelector); | ||
} | ||
|
||
libmexclass::proxy::MakeResult ViewProxy::make(const libmexclass::proxy::FunctionArguments& constructor_arguments) { | ||
libmexclass::proxy::MakeResult out; | ||
|
||
//Create View | ||
matlab::data::StringArray name_mda = constructor_arguments[0]; | ||
auto name = name_mda[0]; | ||
|
||
matlab::data::StringArray description_mda = constructor_arguments[1]; | ||
auto description = description_mda[0]; | ||
|
||
matlab::data::StringArray unit_mda = constructor_arguments[2]; | ||
auto unit = unit_mda[0]; | ||
|
||
matlab::data::TypedArray<int> aggregation_type_mda = constructor_arguments[9]; | ||
auto aggregation_type = static_cast<metrics_sdk::AggregationType>(static_cast<int>(aggregation_type_mda[0])); | ||
|
||
std::shared_ptr<metrics_sdk::HistogramAggregationConfig> aggregation_config = std::shared_ptr<metrics_sdk::HistogramAggregationConfig>(new metrics_sdk::HistogramAggregationConfig()); | ||
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); | ||
} | ||
aggregation_config->boundaries_ = histogramBinEdges; | ||
} | ||
|
||
std::unique_ptr<metrics_sdk::AttributesProcessor> attributes_processor; | ||
matlab::data::StringArray attributes_mda = constructor_arguments[8]; | ||
if(attributes_mda.getNumberOfElements()==0){ | ||
attributes_processor = std::unique_ptr<metrics_sdk::AttributesProcessor>(new metrics_sdk::DefaultAttributesProcessor()); | ||
}else{ | ||
std::unordered_map<std::string, bool> allowed_attribute_keys; | ||
for (auto a : attributes_mda) { | ||
allowed_attribute_keys[a] = true; | ||
} | ||
attributes_processor = std::unique_ptr<metrics_sdk::AttributesProcessor>(new metrics_sdk::FilteringAttributesProcessor(allowed_attribute_keys)); | ||
} | ||
|
||
auto view = metrics_sdk::ViewFactory::Create(name, description, | ||
unit, aggregation_type, std::move(aggregation_config), std::move(attributes_processor)); | ||
|
||
// Create Instrument Selector | ||
matlab::data::TypedArray<int> instrument_type_mda = constructor_arguments[4]; | ||
auto instrument_type = static_cast<metrics_sdk::InstrumentType>(static_cast<int>(instrument_type_mda[0])); | ||
|
||
matlab::data::StringArray instrument_name_mda = constructor_arguments[3]; | ||
auto instrument_name = static_cast<std::string>(instrument_name_mda[0]); | ||
auto instrument_name_view = nostd::string_view(instrument_name); | ||
|
||
auto unit_view = nostd::string_view(static_cast<std::string>(unit)); | ||
|
||
auto instrumentSelector = metrics_sdk::InstrumentSelectorFactory::Create(instrument_type, | ||
instrument_name, unit_view); | ||
|
||
|
||
// Create Meter Selector | ||
matlab::data::StringArray meter_name_mda = constructor_arguments[5]; | ||
auto meter_name = static_cast<std::string>(meter_name_mda[0]); | ||
auto meter_name_view = nostd::string_view(meter_name); | ||
|
||
matlab::data::StringArray meter_version_mda = constructor_arguments[6]; | ||
auto meter_version = static_cast<std::string>(meter_version_mda[0]); | ||
auto meter_version_view = nostd::string_view(meter_version); | ||
|
||
matlab::data::StringArray meter_schema_mda = constructor_arguments[7]; | ||
auto meter_schema = static_cast<std::string>(meter_schema_mda[0]); | ||
auto meter_schema_view = nostd::string_view(meter_schema); | ||
|
||
auto meterSelector = metrics_sdk::MeterSelectorFactory::Create(meter_name_view, | ||
meter_version_view, meter_schema_view); | ||
|
||
|
||
|
||
// out = std::make_shared<ViewProxy>(nostd::shared_ptr<metrics_sdk::View>( | ||
// std::move(metrics_sdk::ViewFactory::Create(name, description, | ||
// unit, aggregation_type, std::move(aggregation_config), std::move(attributes_processor))))); | ||
|
||
|
||
// return out; | ||
|
||
return std::make_shared<ViewProxy>(std::move(view), std::move(instrumentSelector), std::move(meterSelector)); | ||
} | ||
|
||
std::unique_ptr<metrics_sdk::View> ViewProxy::getView(libmexclass::proxy::method::Context& context){ | ||
return std::move(View); | ||
} | ||
|
||
std::unique_ptr<metrics_sdk::InstrumentSelector> ViewProxy::getInstrumentSelector(libmexclass::proxy::method::Context& context){ | ||
return std::move(InstrumentSelector); | ||
} | ||
|
||
std::unique_ptr<metrics_sdk::MeterSelector> ViewProxy::getMeterSelector(libmexclass::proxy::method::Context& context){ | ||
return std::move(MeterSelector); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters