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

[EXPORTER] Export resource for prometheus #2301

Merged
merged 34 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dfefb44
Export resource for prometheus
owent Sep 8, 2023
ca3286a
Fix unit test in prometheus, fix resouce exporting for prometheus exp…
owent Sep 9, 2023
1436368
Fix constructor
owent Sep 9, 2023
22b8c94
Fix compiling problem
owent Sep 9, 2023
3b15502
Fix invalid resource pointer in unit test of prometheus
owent Sep 9, 2023
1ffba54
Fix "default member initializer" problem
owent Sep 12, 2023
401a8ac
Merge remote-tracking branch 'github/main' into emits_resource_for_pr…
owent Sep 14, 2023
d2e144a
Add `target_info` metric.
owent Sep 14, 2023
a30ddf7
Merge remote-tracking branch 'github/main' into emits_resource_for_pr…
owent Sep 14, 2023
02f4d04
Fix instance and job exporting
owent Sep 14, 2023
004a4d4
Merge remote-tracking branch 'github/main' into emits_resource_for_pr…
owent Sep 19, 2023
72ed751
Add options to let user to decide whether to populate target_info
owent Sep 19, 2023
00b0b66
Fix warnings
owent Sep 19, 2023
9f01fd4
Fix priority of conflict labels.
owent Sep 21, 2023
5d24d88
Fix unit test
owent Sep 21, 2023
e50a3d6
Allow some attributes in resource attributes but not in metric attrib…
owent Sep 21, 2023
88e9857
Change the info-typed target metric.
owent Sep 21, 2023
a0b322b
Do not ignore metric attributes.
owent Sep 21, 2023
33d3a47
Merge remote-tracking branch 'github/main' into emits_resource_for_pr…
owent Sep 23, 2023
0ab87c0
Merge remote-tracking branch 'github/main' into emits_resource_for_pr…
owent Sep 27, 2023
fcc397f
Fix unit tests after merged.
owent Sep 27, 2023
23f29cd
Merge remote-tracking branch 'github/main' into emits_resource_for_pr…
owent Sep 27, 2023
765eb99
Merge SanitizeName changes
owent Sep 27, 2023
c476939
Remove ignores in resource attributes
owent Sep 28, 2023
3ebe160
Merge remote-tracking branch 'opentelemetry/main'
owent Sep 29, 2023
422bca2
Remove labels conversations that should only be in target info.
owent Sep 29, 2023
d0f15f2
Remove unused variables.
owent Sep 29, 2023
bb62f0a
Populate target_info with every scrape
owent Oct 1, 2023
9826f67
Merge remote-tracking branch 'opentelemetry/main'
owent Oct 1, 2023
db783e2
Fix style
owent Oct 1, 2023
3517444
Merge remote-tracking branch 'opentelemetry/main'
owent Oct 3, 2023
dd737e3
Fix some legacy issues to remove `job` and `instance` labels.
owent Oct 3, 2023
b6ca2f2
Add scope for target-info
owent Oct 3, 2023
0149d5c
Restore `+2` when reserve space for vector.
owent Oct 3, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Increment the:

* [DEPRECATION] Deprecate ZPAGES
[#2291](https://github.com/open-telemetry/opentelemetry-cpp/pull/2291)
* [EXPORTER] Prometheus exporter emit resource attributes
[#2301](https://github.com/open-telemetry/opentelemetry-cpp/pull/2301)

## [1.11.0] 2023-08-21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ class PrometheusExporterUtils
*/
static std::string SanitizeNames(std::string name);

/**
* Append key-value pair to prometheus labels.
*
* @param name label name
* @param value label value
* @param labels target labels
*
* @return true if the attribute should be ignored, false otherwise.
owent marked this conversation as resolved.
Show resolved Hide resolved
*/
static void AddPrometheusLabel(std::string name,
std::string value,
std::vector<::prometheus::ClientMetric::Label> *labels);

/**
* Some attributes should be ignored when converting resource attributes to
* prometheus labels.
*
* @param name resource attribute name
* @return true if the attribute should be ignored, false otherwise.
*/
static bool ShouldIgnoreResourceAttribute(const std::string &name);

static opentelemetry::sdk::metrics::AggregationType getAggregationType(
const opentelemetry::sdk::metrics::PointType &point_type);

Expand All @@ -50,6 +72,12 @@ class PrometheusExporterUtils
static ::prometheus::MetricType TranslateType(opentelemetry::sdk::metrics::AggregationType kind,
bool is_monotonic = true);

/**
* Add a target_info metric to collect resource attributes
*/
static void SetTarget(const sdk::metrics::ResourceMetrics &data,
std::vector<::prometheus::MetricFamily> *output);

/**
* Set metric data for:
* Counter => Prometheus Counter
Expand All @@ -59,7 +87,8 @@ class PrometheusExporterUtils
const opentelemetry::sdk::metrics::PointAttributes &labels,
::prometheus::MetricType type,
std::chrono::nanoseconds time,
::prometheus::MetricFamily *metric_family);
::prometheus::MetricFamily *metric_family,
const opentelemetry::sdk::resource::Resource *resource);

/**
* Set metric data for:
Expand All @@ -71,14 +100,16 @@ class PrometheusExporterUtils
const std::vector<uint64_t> &counts,
const opentelemetry::sdk::metrics::PointAttributes &labels,
std::chrono::nanoseconds time,
::prometheus::MetricFamily *metric_family);
::prometheus::MetricFamily *metric_family,
const opentelemetry::sdk::resource::Resource *resource);

/**
* Set time and labels to metric data
*/
static void SetMetricBasic(::prometheus::ClientMetric &metric,
std::chrono::nanoseconds time,
const opentelemetry::sdk::metrics::PointAttributes &labels);
const opentelemetry::sdk::metrics::PointAttributes &labels,
const opentelemetry::sdk::resource::Resource *resource);

/**
* Convert attribute value to string
Expand Down
Loading