|
5 | 5 |
|
6 | 6 | % Copyright 2023 The MathWorks, Inc. |
7 | 7 |
|
8 | | - properties (SetAccess=immutable) |
9 | | - Endpoint (1,1) string % Export destination |
10 | | - UseCredentials (1,1) logical % Whether to use SSL credentials |
11 | | - CertificatePath (1,1) string % Path to .pem file for SSL encryption |
12 | | - CertificateString (1,1) string % In-memory string representation of .pem file for SSL encryption |
13 | | - Timeout (1,1) duration % Maximum time above which exports will abort |
14 | | - HttpHeaders (1,1) dictionary % Additional HTTP headers |
15 | | - PreferredAggregationTemporality (1,1) string % Preferred Aggregation Temporality |
| 8 | + properties |
| 9 | + Endpoint (1,1) string = "http://localhost:4317" % Export destination |
| 10 | + UseCredentials (1,1) logical = false % Whether to use SSL credentials |
| 11 | + CertificatePath (1,1) string = "" % Path to .pem file for SSL encryption |
| 12 | + CertificateString (1,1) string = "" % In-memory string representation of .pem file for SSL encryption |
| 13 | + Timeout (1,1) duration = seconds(10) % Maximum time above which exports will abort |
| 14 | + HttpHeaders (1,1) dictionary = dictionary(string.empty, string.empty) % Additional HTTP headers |
| 15 | + PreferredAggregationTemporality (1,1) string = "cumulative" % Preferred Aggregation Temporality |
16 | 16 | end |
17 | 17 |
|
18 | 18 | methods |
|
47 | 47 | optionvalues |
48 | 48 | end |
49 | 49 |
|
| 50 | + |
| 51 | + "libmexclass.opentelemetry.exporters.OtlpGrpcMetricExporterProxy"); |
| 52 | + |
50 | 53 | validnames = ["Endpoint", "UseCredentials ", "CertificatePath", ... |
51 | 54 | "CertificateString", "Timeout", "HttpHeaders", "PreferredAggregationTemporality"]; |
52 | | - % set default values to empty or negative |
53 | | - endpoint = ""; |
54 | | - usessl = false; |
55 | | - certificatepath = ""; |
56 | | - certificatestring = ""; |
57 | | - timeout_millis = -1; |
58 | | - headerkeys = string.empty(); |
59 | | - headervalues = string.empty(); |
60 | | - temporality = ""; |
61 | 55 | for i = 1:length(optionnames) |
62 | 56 | namei = validatestring(optionnames{i}, validnames); |
63 | 57 | valuei = optionvalues{i}; |
64 | | - if strcmp(namei, "Endpoint") |
65 | | - if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei))) |
66 | | - error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:EndpointNotScalarText", "Endpoint must be a scalar string."); |
67 | | - end |
68 | | - endpoint = string(valuei); |
69 | | - elseif strcmp(namei, "UseCredentials ") |
70 | | - if ~((islogical(valuei) || isnumeric(valuei)) && isscalar(valuei)) |
71 | | - error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:UseCredentialsNotScalarLogical", "UseCredentials must be a scalar logical.") |
72 | | - end |
73 | | - usessl = logical(valuei); |
74 | | - elseif strcmp(namei, "CertificatePath") |
75 | | - if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei))) |
76 | | - error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificatePathNotScalarText", "CertificatePath must be a scalar string."); |
77 | | - end |
78 | | - certificatepath = string(valuei); |
79 | | - elseif strcmp(namei, "CertificateString") |
80 | | - if ~(isStringScalar(valuei) || (ischar(valuei) && isrow(valuei))) |
81 | | - error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificateStringNotScalarText", "CertificateString must be a scalar string."); |
82 | | - end |
83 | | - certificatestring = string(valuei); |
84 | | - elseif strcmp(namei, "Timeout") |
85 | | - if ~(isduration(valuei) && isscalar(valuei)) |
86 | | - error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration."); |
87 | | - end |
88 | | - timeout = valuei; |
89 | | - timeout_millis = milliseconds(timeout); |
90 | | - elseif strcmp(namei, "HttpHeaders") % HttpHeaders |
91 | | - if ~isa(valuei, "dictionary") |
92 | | - error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary."); |
93 | | - end |
94 | | - httpheaders = valuei; |
95 | | - headerkeys = keys(valuei); |
96 | | - headervalues = values(valuei); |
97 | | - if ~isstring(headervalues) |
98 | | - error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.") |
99 | | - end |
100 | | - elseif strcmp(namei, "PreferredAggregationTemporality") |
101 | | - temporality = validatestring(valuei, ["Cumulative", "Delta"]); |
102 | | - end |
| 58 | + obj.(namei) = valuei; |
103 | 59 | end |
104 | | - |
105 | | - |
106 | | - "libmexclass.opentelemetry.exporters.OtlpGrpcMetricExporterProxy", ... |
107 | | - endpoint, usessl, certificatepath, certificatestring, ... |
108 | | - timeout_millis, headerkeys, headervalues, temporality); |
| 60 | + end |
| 61 | + |
| 62 | + function obj = set.Endpoint(obj, ep) |
| 63 | + if ~(isStringScalar(ep) || (ischar(ep) && isrow(ep))) |
| 64 | + error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:EndpointNotScalarText", "Endpoint must be a scalar string."); |
| 65 | + end |
| 66 | + ep = string(ep); |
| 67 | + obj.Proxy.setEndpoint(ep); |
| 68 | + obj.Endpoint = ep; |
| 69 | + end |
| 70 | + |
| 71 | + function obj = set.UseCredentials(obj, uc) |
| 72 | + if ~((islogical(uc) || isnumeric(uc)) && isscalar(uc)) |
| 73 | + error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:UseCredentialsNotScalarLogical", "UseCredentials must be a scalar logical.") |
| 74 | + end |
| 75 | + uc = logical(uc); |
| 76 | + obj.Proxy.setUseCredentials(uc); |
| 77 | + obj.UseCredentials = uc; |
| 78 | + end |
109 | 79 |
|
110 | | - % populate immutable properties |
111 | | - [defaultendpoint, defaultcertpath, defaultcertstring, defaultmillis, defaulttemporality] = ... |
112 | | - getDefaultOptionValues(obj); |
113 | | - if endpoint == "" % not specified, use default value |
114 | | - obj.Endpoint = defaultendpoint; |
115 | | - else |
116 | | - obj.Endpoint = endpoint; |
117 | | - end |
118 | | - obj.UseCredentials = usessl; |
119 | | - if certificatepath == "" % not specified, use default value |
120 | | - obj.CertificatePath = defaultcertpath; |
121 | | - else |
122 | | - obj.CertificatePath = certificatepath; |
| 80 | + function obj = set.CertificatePath(obj, certpath) |
| 81 | + if ~(isStringScalar(certpath) || (ischar(certpath) && isrow(certpath))) |
| 82 | + error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificatePathNotScalarText", "CertificatePath must be a scalar string."); |
123 | 83 | end |
124 | | - if certificatestring == "" % not specified, use default value |
125 | | - obj.CertificateString = defaultcertstring; |
126 | | - else |
127 | | - obj.CertificateString = certificatestring; |
| 84 | + certpath = string(certpath); |
| 85 | + obj.Proxy.setCertificatePath(certpath); |
| 86 | + obj.CertificatePath = certpath; |
| 87 | + end |
| 88 | + |
| 89 | + function obj = set.CertificateString(obj, certstr) |
| 90 | + if ~(isStringScalar(certstr) || (ischar(certstr) && isrow(certstr))) |
| 91 | + error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:CertificateStringNotScalarText", "CertificateString must be a scalar string."); |
128 | 92 | end |
129 | | - if timeout_millis < 0 % not specified, use default value |
130 | | - obj.Timeout = milliseconds(defaultmillis); |
131 | | - else |
132 | | - obj.Timeout = timeout; |
| 93 | + certstr = string(certstr); |
| 94 | + obj.Proxy.setCertificateString(certstr); |
| 95 | + obj.CertificateString = certstr; |
| 96 | + end |
| 97 | + |
| 98 | + function obj = set.Timeout(obj, timeout) |
| 99 | + if ~(isduration(timeout) && isscalar(timeout)) |
| 100 | + error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:TimeoutNotScalarDuration", "Timeout must be a scalar duration."); |
133 | 101 | end |
134 | | - if isempty(headerkeys) % not specified, return empty dictionary |
135 | | - obj.HttpHeaders = dictionary(headerkeys, headervalues); |
136 | | - else |
137 | | - obj.HttpHeaders = httpheaders; |
| 102 | + obj.Proxy.setTimeout(milliseconds(timeout)); |
| 103 | + obj.Timeout = timeout; |
| 104 | + end |
| 105 | + |
| 106 | + function obj = set.HttpHeaders(obj, httpheaders) |
| 107 | + if ~isa(httpheaders, "dictionary") |
| 108 | + error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNotDictionary", "HttpHeaders input must be a dictionary."); |
138 | 109 | end |
139 | | - if temporality == "" |
140 | | - obj.PreferredAggregationTemporality = defaulttemporality; |
141 | | - else |
142 | | - obj.PreferredAggregationTemporality = temporality; |
| 110 | + headerkeys = keys(httpheaders); |
| 111 | + headervalues = values(httpheaders); |
| 112 | + if ~isstring(headervalues) |
| 113 | + error("opentelemetry:exporters:otlp:OtlpGrpcMetricExporter:HttpHeadersNonStringValues", "HttpHeaders dictionary values must be strings.") |
143 | 114 | end |
| 115 | + obj.Proxy.setHttpHeaders(headerkeys, headervalues); |
| 116 | + obj.HttpHeaders = httpheaders; |
| 117 | + end |
| 118 | + |
| 119 | + function obj = set.PreferredAggregationTemporality(obj, temporality) |
| 120 | + temporality = validatestring(temporality, ["cumulative", "delta"]); |
| 121 | + obj.Proxy.setTemporality(temporality); |
| 122 | + obj.PreferredAggregationTemporality = temporality; |
144 | 123 | end |
145 | 124 | end |
146 | 125 | end |
0 commit comments