Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXEMPLAR] Update ExemplarFilter and ExemplarReservoir for spec #2372

Merged
merged 73 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a9c4e76
Set ExemplarFilter in SDK
ThomsonTan Oct 16, 2023
574cc83
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Jan 22, 2024
a20d585
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Mar 19, 2024
f7c183a
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Mar 25, 2024
aae3d3d
draft
ThomsonTan Mar 25, 2024
7bb5d47
fix compilation
ThomsonTan Mar 26, 2024
cdb42d4
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Mar 26, 2024
968f4ae
Complete SimpleFixedSizeCellSelector
ThomsonTan Mar 26, 2024
093b133
fix building tests
ThomsonTan Mar 26, 2024
3df58f4
Enable in sync metric strorage
ThomsonTan Mar 26, 2024
ce10f0c
Enable sampling based on trace
ThomsonTan Mar 26, 2024
6254bb2
Fix a header file path
ThomsonTan Mar 26, 2024
3816caa
Move all exemplar code into preview macro
ThomsonTan Mar 26, 2024
6e124ce
Add one more preview macro
ThomsonTan Mar 26, 2024
d76710a
One more macro guard
ThomsonTan Mar 26, 2024
1bd5550
Fix format
ThomsonTan Mar 26, 2024
e651a37
Remove unused file
ThomsonTan Mar 26, 2024
5f132c5
Rename test
ThomsonTan Mar 26, 2024
a2f6e9e
More format
ThomsonTan Mar 26, 2024
01a3455
Even more formatting
ThomsonTan Mar 26, 2024
f4d8eb7
Fix macro name for test
ThomsonTan Mar 27, 2024
5e41d60
More format clean
ThomsonTan Mar 27, 2024
02f2c21
Comment out unused parameters
ThomsonTan Mar 27, 2024
4907453
Comment out more unused parameters
ThomsonTan Mar 27, 2024
7240b1b
Add parenthesis to boolean expression
ThomsonTan Mar 27, 2024
e7c61d6
Fix warning of hidden override
ThomsonTan Mar 27, 2024
aca22e9
Comment out unused var 2
ThomsonTan Mar 27, 2024
a60e01c
Delete unused source file
ThomsonTan Mar 27, 2024
772f2b8
Add one more macro
ThomsonTan Mar 27, 2024
1288e93
One more macro in meter_context.cc
ThomsonTan Mar 27, 2024
06193ce
Remove deleted test in bazel build
ThomsonTan Mar 27, 2024
77f6e12
One more macro
ThomsonTan Mar 27, 2024
a28d8a1
Add macro to test file
ThomsonTan Mar 27, 2024
2efb7f7
Format test code
ThomsonTan Mar 27, 2024
c7e4e72
add header file
ThomsonTan Mar 27, 2024
44737aa
Fix one more test
ThomsonTan Mar 27, 2024
798fc19
Add context header file
ThomsonTan Mar 27, 2024
36bd040
Add one more header
ThomsonTan Mar 27, 2024
729142f
format
ThomsonTan Mar 27, 2024
fab7bf0
Add new lines
ThomsonTan Mar 27, 2024
46b15f5
One more newline
ThomsonTan Mar 27, 2024
239e730
One more macro
ThomsonTan Mar 27, 2024
82b45f2
add one more newline
ThomsonTan Mar 27, 2024
04c0d59
add more newline
ThomsonTan Mar 27, 2024
3b80277
More newline
ThomsonTan Mar 27, 2024
1410a42
One more fix
ThomsonTan Mar 27, 2024
1d9047c
Fix test
ThomsonTan Mar 27, 2024
1db50bf
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Mar 27, 2024
d0f8cca
format
ThomsonTan Mar 27, 2024
6aec1f4
Remove unused test
ThomsonTan Mar 27, 2024
6cc25e4
Collect variable origin on valgrind
ThomsonTan Mar 27, 2024
25077c9
Set exemplar type default to AlwaysOff
ThomsonTan Mar 27, 2024
2ee5267
Set default parameter for MeterProvider::SetExemplarFilter
ThomsonTan Mar 27, 2024
1ef26dd
Revert "Collect variable origin on valgrind"
ThomsonTan Mar 27, 2024
2271886
Update changelog
ThomsonTan Mar 27, 2024
3ccbdaa
Fix oob indexing
ThomsonTan Mar 27, 2024
48ce87f
Use random number generator from common
ThomsonTan Mar 27, 2024
ebf4bbd
add test
ThomsonTan Mar 28, 2024
a7c7973
Add int64_t support to HistogramCellSelector
ThomsonTan Mar 28, 2024
1c92201
Add random lib dependence for bazel
ThomsonTan Mar 28, 2024
0cfec22
Move utils function to a separate file
ThomsonTan Mar 28, 2024
1662339
Revert test code
ThomsonTan Mar 28, 2024
a1e6c94
Fix test
ThomsonTan Mar 28, 2024
ea56f06
Improve testcase name
ThomsonTan Mar 28, 2024
5aa1f67
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Mar 28, 2024
4a59948
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Mar 29, 2024
e276f08
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Apr 3, 2024
3bf5bd4
Merge branch 'main' into SetExemplarInSDK
marcalff Apr 16, 2024
699d7e3
Update CHANGELOG.md
marcalff Apr 16, 2024
a1b4683
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Apr 22, 2024
f2e0df3
Fix changelog
ThomsonTan Apr 22, 2024
d9bb11f
Merge branch 'main' into SetExemplarInSDK
ThomsonTan Apr 29, 2024
8231e1e
Merge branch 'main' into SetExemplarInSDK
marcalff Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Increment the:
[#2631](https://github.com/open-telemetry/opentelemetry-cpp/pull/2631)
* [SDK] DefaultLogHandler to print errors to std::cerr, add LogLevel::None
[#2622](https://github.com/open-telemetry/opentelemetry-cpp/pull/2622)
* [SDK] Update ExemplarFilter and ExemplarReservoir for spec
ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
[#2372](https://github.com/open-telemetry/opentelemetry-cpp/pull/2372)
* [SEMANTIC CONVENTIONS] Upgrade to semantic convention 1.25.0
[#2633](https://github.com/open-telemetry/opentelemetry-cpp/pull/2633)
* [DOC] Add readme and examples for OTLP FILE exporters.
Expand Down Expand Up @@ -124,6 +126,13 @@ Important changes:
* Numbering of log levels like OTEL_INTERNAL_LOG_LEVEL_ERROR
has changed, which requires to rebuild, as the SDK ABI differs.

Notes on experimental features:

* [#2372](https://github.com/open-telemetry/opentelemetry-cpp/issues/2372)
introduced `MeterProvider::SetExemplar()` which accepts en
`ExemplarFilterType` enumeration with `kAlwaysOff`, `kAlwaysOn` and
`kTraceBased`.

ThomsonTan marked this conversation as resolved.
Show resolved Hide resolved
## [1.14.2] 2024-02-27

* [SDK] Fix observable attributes drop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@

#pragma once

#include <memory>
#include <vector>
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW

#include "opentelemetry/sdk/metrics/data/exemplar_data.h"
#include "opentelemetry/sdk/metrics/exemplar/filter.h"
#include "opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h"
#include "opentelemetry/sdk/metrics/exemplar/reservoir.h"
#include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h"
#include "opentelemetry/version.h"
# include <memory>
# include <vector>

# include "opentelemetry/sdk/common/global_log_handler.h"
# include "opentelemetry/sdk/metrics/data/exemplar_data.h"
# include "opentelemetry/sdk/metrics/exemplar/filter_type.h"
# include "opentelemetry/sdk/metrics/exemplar/fixed_size_exemplar_reservoir.h"
# include "opentelemetry/sdk/metrics/exemplar/reservoir.h"
# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace common
Expand All @@ -29,7 +32,7 @@ namespace sdk
namespace metrics
{

class HistogramExemplarReservoir : public FixedSizeExemplarReservoir
class AlignedHistogramBucketExemplarReservoir : public FixedSizeExemplarReservoir
{

public:
Expand All @@ -39,11 +42,11 @@ class HistogramExemplarReservoir : public FixedSizeExemplarReservoir
return std::shared_ptr<ReservoirCellSelector>{new HistogramCellSelector(boundaries)};
}

HistogramExemplarReservoir(size_t size,
std::shared_ptr<ReservoirCellSelector> reservoir_cell_selector,
std::shared_ptr<ExemplarData> (ReservoirCell::*map_and_reset_cell)(
const opentelemetry::sdk::common::OrderedAttributeMap &attributes))
: FixedSizeExemplarReservoir(size, reservoir_cell_selector, map_and_reset_cell)
AlignedHistogramBucketExemplarReservoir(
size_t size,
std::shared_ptr<ReservoirCellSelector> reservoir_cell_selector,
MapAndResetCellType map_and_reset_cell)
: FixedSizeExemplarReservoir(size + 1, reservoir_cell_selector, map_and_reset_cell)
{}

class HistogramCellSelector : public ReservoirCellSelector
Expand Down Expand Up @@ -72,7 +75,9 @@ class HistogramExemplarReservoir : public FixedSizeExemplarReservoir
return static_cast<int>(i);
}
}
return -1;

// The bucket at max_size is for values greater than the last boundary
return static_cast<int>(max_size);
}

private:
Expand All @@ -87,3 +92,5 @@ class HistogramExemplarReservoir : public FixedSizeExemplarReservoir
} // namespace metrics
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

#endif // ENABLE_METRICS_EXEMPLAR_PREVIEW

This file was deleted.

54 changes: 0 additions & 54 deletions sdk/include/opentelemetry/sdk/metrics/exemplar/filter.h

This file was deleted.

46 changes: 46 additions & 0 deletions sdk/include/opentelemetry/sdk/metrics/exemplar/filter_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW

# include <memory>

# include "opentelemetry/sdk/metrics/state/filtered_ordered_attribute_map.h"
# include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace context
{
class Context;
} // namespace context

namespace sdk
{
namespace common
{
class OrderedAttributeMap;
} // namespace common

namespace metrics
{
using MetricAttributes = opentelemetry::sdk::metrics::FilteredOrderedAttributeMap;

/**
* Exemplar filter type is used to pre-filter measurements before attempting to store them in a
* reservoir.
* https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#exemplarfilter
*/
enum class ExemplarFilterType : uint8_t
{
kAlwaysOff,
kAlwaysOn,
kTraceBased
};

} // namespace metrics
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

#endif // ENABLE_METRICS_EXEMPLAR_PREVIEW

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

#pragma once

#include <memory>
#include <vector>
#ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW

#include "opentelemetry/context/context.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/common/attribute_utils.h"
#include "opentelemetry/sdk/metrics/exemplar/reservoir.h"
#include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h"
#include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h"
# include <memory>
# include <vector>

# include "opentelemetry/context/context.h"
# include "opentelemetry/nostd/function_ref.h"
# include "opentelemetry/nostd/shared_ptr.h"
# include "opentelemetry/sdk/common/attribute_utils.h"
# include "opentelemetry/sdk/metrics/exemplar/reservoir.h"
# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell.h"
# include "opentelemetry/sdk/metrics/exemplar/reservoir_cell_selector.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
Expand All @@ -26,13 +28,14 @@ class FixedSizeExemplarReservoir : public ExemplarReservoir
public:
FixedSizeExemplarReservoir(size_t size,
std::shared_ptr<ReservoirCellSelector> reservoir_cell_selector,
std::shared_ptr<ExemplarData> (ReservoirCell::*map_and_reset_cell)(
const opentelemetry::sdk::common::OrderedAttributeMap &attributes))
MapAndResetCellType map_and_reset_cell)
: storage_(size),
reservoir_cell_selector_(reservoir_cell_selector),
map_and_reset_cell_(map_and_reset_cell)
{}

using ExemplarReservoir::OfferMeasurement;

void OfferMeasurement(
int64_t value,
const MetricAttributes &attributes,
Expand Down Expand Up @@ -95,10 +98,11 @@ class FixedSizeExemplarReservoir : public ExemplarReservoir
explicit FixedSizeExemplarReservoir() = default;
std::vector<ReservoirCell> storage_;
std::shared_ptr<ReservoirCellSelector> reservoir_cell_selector_;
std::shared_ptr<ExemplarData> (ReservoirCell::*map_and_reset_cell_)(
const opentelemetry::sdk::common::OrderedAttributeMap &attributes);
MapAndResetCellType map_and_reset_cell_;
};

} // namespace metrics
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

#endif // ENABLE_METRICS_EXEMPLAR_PREVIEW
Loading