BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlm_metricdescriptor.h
Go to the documentation of this file.
1/// @file bdlm_metricdescriptor.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlm_metricdescriptor.h -*-C++-*-
8#ifndef INCLUDED_BDLM_METRICDESCRIPTOR
9#define INCLUDED_BDLM_METRICDESCRIPTOR
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id$")
13
14/// @defgroup bdlm_metricdescriptor bdlm_metricdescriptor
15/// @brief Provide an attribute class to describe a metric.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlm
19/// @{
20/// @addtogroup bdlm_metricdescriptor
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlm_metricdescriptor-purpose"> Purpose</a>
25/// * <a href="#bdlm_metricdescriptor-classes"> Classes </a>
26/// * <a href="#bdlm_metricdescriptor-description"> Description </a>
27/// * <a href="#bdlm_metricdescriptor-attributes"> Attributes </a>
28/// * <a href="#bdlm_metricdescriptor-usage"> Usage </a>
29///
30/// # Purpose {#bdlm_metricdescriptor-purpose}
31/// Provide an attribute class to describe a metric.
32///
33/// @deprecated This component is not ready for public use.
34///
35/// # Classes {#bdlm_metricdescriptor-classes}
36///
37/// - bdlm::MetricDescriptor: descriptive information for a metric
38///
39/// # Description {#bdlm_metricdescriptor-description}
40/// This component provides a single unconstrained attribute class,
41/// `bdlm::MetricDescriptor`, that is used to supply descriptive information for
42/// a metric. A descriptor is supplied to a `MetricsRegistry` to identify a
43/// metric, which in-turn supplies that description to a higher-level metric
44/// publication system (like BALM or GUTS) via a concrete implementation of the
45/// `bdlm::MetricsAdapter` protocol.
46///
47/// ## Attributes {#bdlm_metricdescriptor-attributes}
48///
49///
50/// @code
51/// Name Type Default
52/// ------------------ ----------- -------
53/// metricNamespace bsl::string [1]
54/// metricName bsl::string ""
55/// instanceNumber Uint64 0
56/// objectTypeName bsl::string ""
57/// objectTypeAbbreviation bsl::string ""
58/// objectIdentifier bsl::string [2]
59/// @endcode
60/// [1] k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION
61/// [2] k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION
62/// @code
63/// : o 'metricNamespace' - a grouping value for published metrics, which is
64/// : expected to be have implementation specific details from the metric
65/// : publishing system. Recommended practice is to use
66/// : 'k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION' indicating concrete
67/// : implementations of 'MetricsAdapter' should determine an appropriate
68/// : value for the metrics framework it adapts (this is often a configured
69/// : value for an application, e.g., a service name).
70/// :
71/// : o 'metricName' - the name of the metric (e.g., "requestCount")
72/// :
73/// : o 'instanceCount' - an instance number expected to ensure that a unique
74/// : 'MetricsDescriptor' is created for each instance of an object reporting
75/// : metrics. Recommended practice is to use 'bdlm::InstanceCount' to
76/// : generate this value.
77/// :
78/// : o 'objectTypeName' - a name that uniquely identifies the type generating
79/// : the metric (e.g., "bdlmt.fixedthreadpool").
80/// :
81/// : o 'objectTypeAbbreviation' - a shortened, but still unique, version of the
82/// : object type name (e.g., "ftp").
83/// :
84/// : o 'objectIdentifier' - an application unique value for identifying a
85/// : metric. Recommended practice is to use
86/// : 'k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION' indicating concrete
87/// : implementations of 'MetricsAdapter' should determine an appropriate value
88/// : for the metrics framework it adapts (this is often a value computed from
89/// : the other descriptor properties).
90/// @endcode
91/// For example, for GUTS (an internal Bloomberg metric framework) using a
92/// `guta::BdlmMetricsAdapter` configured with the namespace "bdlm" and object
93/// identifier prefix "svc", supplying (metricNamespace:
94/// k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION, metricName: "backlog",
95/// instanceNumber: InstanceCount::value<FixedThreadPool>(), objectTypeName:
96/// "bdlmt.fixedthreadpool", objectTypeAbbreviation: "ftp",
97/// objectIdentifier: `_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION`) would result
98/// in a metric that is within the namespace "bdlm", had the metric name
99/// "backlog.g", and the tags
100/// {"identifier":"svc.ftp.1","type":"bdlmt.fixedthreadpool"}, assuming this
101/// was the first invocation of `InstanceCount::value<FixedThreadPool>()`.
102/// Note that the ".g" in "backlock.g" indicates a guage metric type.
103///
104/// ## Usage {#bdlm_metricdescriptor-usage}
105///
106///
107/// The intended use of this component is illustrated in
108/// {@ref bdlm_metricsadapter |Usage}.
109/// @}
110/** @} */
111/** @} */
112
113/** @addtogroup bdl
114 * @{
115 */
116/** @addtogroup bdlm
117 * @{
118 */
119/** @addtogroup bdlm_metricdescriptor
120 * @{
121 */
122
123#include <bdlm_instancecount.h>
124
125#include <bslma_allocator.h>
127
129
130#include <bsl_string.h>
131
132
133namespace bdlm {
134
135 // ======================
136 // class MetricDescriptor
137 // ======================
138
139/// This attribute class characterizes how to describe a metric.
140///
141/// See @ref bdlm_metricdescriptor
143
144 private:
145 // DATA
146 bsl::string d_metricNamespace; // namespace for the metric
147
148 bsl::string d_metricName; // name of the metric
149
150 InstanceCount::Value d_instanceNumber; // instance number of the
151 // type generating the
152 // metric
153
154 bsl::string d_objectTypeName; // name of the type
155 // generating the metric
156
157 bsl::string d_objectTypeAbbreviation; // abbreviation for the
158 // type generating the
159 // metric
160
161 bsl::string d_objectIdentifier; // object identifier
162 // generating the metric
163
164 // FRIENDS
165 friend bool operator==(const MetricDescriptor&, const MetricDescriptor&);
166 friend bool operator!=(const MetricDescriptor&, const MetricDescriptor&);
167
168 public:
169 // CONSTANTS
172
173 // TRAITS
176
177 // CREATORS
178
179 /// Create an object of this class having the default attribute values.
180 /// Optionally specify a `basicAllocator` used to supply memory. If
181 /// `basicAllocator` is 0, the currently installed default allocator is
182 /// used. The default value for the namespace attribute is
183 /// `k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION` and the default value
184 /// for the object identifier attribute is
185 /// `k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION`. The residual attibutes
186 /// default to an empty string, except the instance number which
187 /// defaults to 0. Note that implementations of the
188 /// `bdlm::MetricsAdapter` protocal will typically use an implementation
189 /// specific value for the namespace attribute when
190 /// `metricNamespace == k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION` and
191 /// the object identifier attribute when
192 /// `objectIdentrifier == k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION`.
193 MetricDescriptor(bslma::Allocator *basicAllocator = 0);
194
195 /// Create an object of this class having the specified
196 /// `metricNamespace`, `metricName`, `instanceNumber`, `objectTypeName`,
197 /// `objectTypeAbbreviation`, and `objectIdentifier` attribute values.
198 /// Optionally specify a `basicAllocator` used to supply memory. If
199 /// `basicAllocator` is 0, the currently installed default allocator is
200 /// used. Note that implementations of the `bdlm::MetricsAdapter`
201 /// protocal will typically use an implementation specific value for the
202 /// namespace attribute when
203 /// `metricNamespace == k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION` and
204 /// the object identifier attribute when
205 /// `objectIdentrifier == k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION`.
212 bslma::Allocator *basicAllocator = 0);
213
214 /// Create an object of this class having the same value as the
215 /// specified `original` one. Optionally specify a `basicAllocator`
216 /// used to supply memory. If `basicAllocator` is 0, the currently
217 /// installed default allocator is used.
218 MetricDescriptor(const MetricDescriptor& original,
219 bslma::Allocator *basicAllocator = 0);
220
221 /// Destroy this object.
222 ~MetricDescriptor() = default;
223
224 // MANIPULATORS
225
226 /// Assign to this object the value of the specified `rhs` object, and
227 /// return a reference providing modifiable access to this object.
229
230 /// Set the `instanceNumber` attribute of this object to the specified
231 /// `value`.
232 void setInstanceNumber(const InstanceCount::Value& value);
233
234 /// Set the `metricName` attribute of this object to the specified
235 /// `value`.
236 void setMetricName(const bsl::string_view& value);
237
238 /// Set the `metricNamespace` attribute of this object to the specified
239 /// `value`.
240 void setMetricNamespace(const bsl::string_view& value);
241
242 /// Set the `objectIdentifier` attribute of this object to the specified
243 /// `value`.
244 void setObjectIdentifier(const bsl::string_view& value);
245
246 /// Set the `objectTypeAbbreviation` attribute of this object to the
247 /// specified `value`.
249
250 /// Set the `objectTypeName` attribute of this object to the specified
251 /// `value`.
252 void setObjectTypeName(const bsl::string_view& value);
253
254 // ACCESSORS
255
256 /// Return the `instanceNumber` attribute.
258
259 /// Return the `metricName` attribute.
260 const bsl::string& metricName() const;
261
262 /// Return the `metricNamespace` attribute.
263 const bsl::string& metricNamespace() const;
264
265 /// Return the `objectIdentifier` attribute.
266 const bsl::string& objectIdentifier() const;
267
268 /// Return the `objectTypeAbbreviation` attribute.
269 const bsl::string& objectTypeAbbreviation() const;
270
271 /// Return the `objectTypeName` attribute.
272 const bsl::string& objectTypeName() const;
273
274 /// Return the allocator used by this object to supply memory.
276};
277
278// FREE OPERATORS
279
280/// Return `true` if the specified `lhs` and `rhs` objects have the same
281/// value, and `false` otherwise. Two `MetricDescriptor` objects have the
282/// same value if each of their attributes (respectively) have the same
283/// value.
284bool operator==(const MetricDescriptor& lhs, const MetricDescriptor& rhs);
285
286/// Return `true` if the specified `lhs` and `rhs` objects do not have the
287/// same value, and `false` otherwise. Two `MetricDescriptor` objects do
288/// not have the same value if any of their attributes (respectively) do not
289/// have the same value.
290bool operator!=(const MetricDescriptor& lhs, const MetricDescriptor& rhs);
291
292// ============================================================================
293// INLINE DEFINITIONS
294// ============================================================================
295
296 // ----------------------
297 // class MetricDescriptor
298 // ----------------------
299
300// CREATORS
301inline
303: d_metricNamespace(k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION, basicAllocator)
304, d_metricName(basicAllocator)
305, d_instanceNumber(0)
306, d_objectTypeName(basicAllocator)
307, d_objectTypeAbbreviation(basicAllocator)
308, d_objectIdentifier(k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION, basicAllocator)
309{
310}
311
312inline
314 const bsl::string_view& metricNamespace,
315 const bsl::string_view& metricName,
316 InstanceCount::Value instanceNumber,
317 const bsl::string_view& objectTypeName,
318 const bsl::string_view& objectTypeAbbreviation,
319 const bsl::string_view& objectIdentifier,
320 bslma::Allocator *basicAllocator)
321: d_metricNamespace(metricNamespace, basicAllocator)
322, d_metricName(metricName, basicAllocator)
323, d_instanceNumber(instanceNumber)
324, d_objectTypeName(objectTypeName, basicAllocator)
325, d_objectTypeAbbreviation(objectTypeAbbreviation, basicAllocator)
326, d_objectIdentifier(objectIdentifier, basicAllocator)
327{
328}
329
330inline
332 bslma::Allocator *basicAllocator)
333: d_metricNamespace(original.d_metricNamespace, basicAllocator)
334, d_metricName(original.d_metricName, basicAllocator)
335, d_instanceNumber(original.d_instanceNumber)
336, d_objectTypeName(original.d_objectTypeName, basicAllocator)
337, d_objectTypeAbbreviation(original.d_objectTypeAbbreviation, basicAllocator)
338, d_objectIdentifier(original.d_objectIdentifier, basicAllocator)
339{
340}
341
342// MANIPULATORS
343inline
345{
346 d_metricNamespace = rhs.d_metricNamespace;
347 d_metricName = rhs.d_metricName;
348 d_instanceNumber = rhs.d_instanceNumber;
349 d_objectTypeName = rhs.d_objectTypeName;
350 d_objectTypeAbbreviation = rhs.d_objectTypeAbbreviation;
351 d_objectIdentifier = rhs.d_objectIdentifier;
352
353 return *this;
354}
355
356inline
358{
359 d_instanceNumber = value;
360}
361
362inline
364{
365 d_metricName = value;
366}
367
368inline
370{
371 d_metricNamespace = value;
372}
373
374inline
376{
377 d_objectIdentifier = value;
378}
379
380inline
382{
383 d_objectTypeAbbreviation = value;
384}
385
386inline
388{
389 d_objectTypeName = value;
390}
391
392// ACCESSORS
393inline
395{
396 return d_instanceNumber;
397}
398
399inline
401{
402 return d_metricName;
403}
404
405inline
407{
408 return d_metricNamespace;
409}
410
411inline
413{
414 return d_objectIdentifier;
415}
416
417inline
419{
420 return d_objectTypeAbbreviation;
421}
422
423inline
425{
426 return d_objectTypeName;
427}
428
429 // Aspects
430
431inline
433{
434 return d_metricNamespace.get_allocator().mechanism();
435}
436
437// FREE OPERATORS
438inline
439bool operator==(const MetricDescriptor& lhs, const MetricDescriptor& rhs)
440{
441 return lhs.d_metricNamespace == rhs.d_metricNamespace &&
442 lhs.d_metricName == rhs.d_metricName &&
443 lhs.d_instanceNumber == rhs.d_instanceNumber &&
444 lhs.d_objectTypeName == rhs.d_objectTypeName &&
445 lhs.d_objectTypeAbbreviation == rhs.d_objectTypeAbbreviation &&
446 lhs.d_objectIdentifier == rhs.d_objectIdentifier;
447}
448
449inline
450bool operator!=(const MetricDescriptor& lhs, const MetricDescriptor& rhs)
451{
452 return lhs.d_metricNamespace != rhs.d_metricNamespace ||
453 lhs.d_metricName != rhs.d_metricName ||
454 lhs.d_instanceNumber != rhs.d_instanceNumber ||
455 lhs.d_objectTypeName != rhs.d_objectTypeName ||
456 lhs.d_objectTypeAbbreviation != rhs.d_objectTypeAbbreviation ||
457 lhs.d_objectIdentifier != rhs.d_objectIdentifier;
458}
459
460} // close package namespace
461
462
463#endif
464
465// ----------------------------------------------------------------------------
466// Copyright 2024 Bloomberg Finance L.P.
467//
468// Licensed under the Apache License, Version 2.0 (the "License");
469// you may not use this file except in compliance with the License.
470// You may obtain a copy of the License at
471//
472// http://www.apache.org/licenses/LICENSE-2.0
473//
474// Unless required by applicable law or agreed to in writing, software
475// distributed under the License is distributed on an "AS IS" BASIS,
476// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
477// See the License for the specific language governing permissions and
478// limitations under the License.
479// ----------------------------- END-OF-FILE ----------------------------------
480
481/** @} */
482/** @} */
483/** @} */
Definition bdlm_metricdescriptor.h:142
static const char * k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION
Definition bdlm_metricdescriptor.h:170
void setMetricNamespace(const bsl::string_view &value)
Definition bdlm_metricdescriptor.h:369
MetricDescriptor(bslma::Allocator *basicAllocator=0)
Definition bdlm_metricdescriptor.h:302
~MetricDescriptor()=default
Destroy this object.
const bsl::string & metricNamespace() const
Return the metricNamespace attribute.
Definition bdlm_metricdescriptor.h:406
static const char * k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION
Definition bdlm_metricdescriptor.h:171
bslma::Allocator * allocator() const
Return the allocator used by this object to supply memory.
Definition bdlm_metricdescriptor.h:432
friend bool operator!=(const MetricDescriptor &, const MetricDescriptor &)
Definition bdlm_metricdescriptor.h:450
const bsl::string & objectTypeAbbreviation() const
Return the objectTypeAbbreviation attribute.
Definition bdlm_metricdescriptor.h:418
void setInstanceNumber(const InstanceCount::Value &value)
Definition bdlm_metricdescriptor.h:357
BSLMF_NESTED_TRAIT_DECLARATION(MetricDescriptor, bslma::UsesBslmaAllocator)
friend bool operator==(const MetricDescriptor &, const MetricDescriptor &)
Definition bdlm_metricdescriptor.h:439
MetricDescriptor & operator=(const MetricDescriptor &rhs)
Definition bdlm_metricdescriptor.h:344
const bsl::string & metricName() const
Return the metricName attribute.
Definition bdlm_metricdescriptor.h:400
void setObjectTypeAbbreviation(const bsl::string_view &value)
Definition bdlm_metricdescriptor.h:381
void setObjectIdentifier(const bsl::string_view &value)
Definition bdlm_metricdescriptor.h:375
void setObjectTypeName(const bsl::string_view &value)
Definition bdlm_metricdescriptor.h:387
const bsl::string & objectTypeName() const
Return the objectTypeName attribute.
Definition bdlm_metricdescriptor.h:424
const bsl::string & objectIdentifier() const
Return the objectIdentifier attribute.
Definition bdlm_metricdescriptor.h:412
const InstanceCount::Value & instanceNumber() const
Return the instanceNumber attribute.
Definition bdlm_metricdescriptor.h:394
void setMetricName(const bsl::string_view &value)
Definition bdlm_metricdescriptor.h:363
Definition bslstl_stringview.h:441
Definition bslstl_string.h:1281
allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT
Return the allocator used by this string to supply memory.
Definition bslstl_string.h:6723
Definition bslma_allocator.h:457
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlm_instancecount.h:101
bsls::Types::Uint64 Value
Definition bdlm_instancecount.h:111
Definition bslma_usesbslmaallocator.h:343