-
Notifications
You must be signed in to change notification settings - Fork 11
Add instrumentation and expose measurement in prometheus format #210
base: master
Are you sure you want to change the base?
Changes from 14 commits
8ab1570
2427bce
7b3f07e
955a061
12b4a86
5c065da
c667388
cf5f833
b788df1
e49c64d
ec5a859
bbbd851
acac889
ac7c9ea
5ac289e
d8b3e37
93790ed
786245f
c22faac
cdfe9c1
7514b25
4f37882
96b268a
64929c8
88830d0
6ee8ab8
bee8a32
2687728
5c6526e
546958f
775737c
fc935e6
1fe4649
1099767
1e56d36
d6c6ac3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,9 @@ | |
path = lib/googletest | ||
url = https://github.com/google/googletest | ||
ignore = dirty | ||
[submodule "lib/prometheus-cpp"] | ||
path = lib/prometheus-cpp | ||
url = https://github.com/jupp0r/prometheus-cpp | ||
[submodule "lib/opencensus-cpp"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm always wary of targeting an untagged and unreleased commit. We can fix this later, but just wanted to note this as a concern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. acknowledged. I just follow the pattern we used on other submodules. Once opencensus-cpp offically release their new version, we should check in that specific version. for now, I targeted on a commit which includes all the functionality we need, including prometheus-exporter. |
||
path = lib/opencensus-cpp | ||
url = https://github.com/census-instrumentation/opencensus-cpp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
init-submodules | ||
build-cpp-netlib | ||
build-yaml-cpp | ||
build-prometheus-cpp | ||
build-opencensus-cpp | ||
metadatad |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
#include "measures_utils.h" | ||
|
||
#include <opencensus/exporters/stats/prometheus/prometheus_exporter.h> | ||
#include <prometheus/text_serializer.h> | ||
|
||
namespace google { | ||
namespace internal { | ||
|
||
namespace { | ||
|
||
::prometheus::TextSerializer text_serializer; | ||
|
||
::opencensus::exporters::stats::PrometheusExporter exporter; | ||
|
||
} // namespace | ||
|
||
std::string SerializeMetricsToPrometheusTextFormat() { | ||
return text_serializer.Serialize(exporter.Collect()); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace google |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
#ifndef METADATA_AGENT_INTERNAL_MEASURES_UTILS_H_ | ||
#define METADATA_AGENT_INTERNAL_MEASURES_UTILS_H_ | ||
|
||
#include <string> | ||
|
||
namespace google { | ||
namespace internal { | ||
|
||
std::string SerializeMetricsToPrometheusTextFormat(); | ||
|
||
} // namespace internal | ||
} // namespace google | ||
|
||
#endif /* METADATA_AGENT_INTERNAL_MEASURES_UTILS_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2018 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
#include "measures.h" | ||
StevenYCChou marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#include <absl/strings/string_view.h> | ||
#include <opencensus/stats/stats.h> | ||
|
||
namespace google { | ||
|
||
namespace { | ||
|
||
ABSL_CONST_INIT const absl::string_view kCount = "1"; | ||
StevenYCChou marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
} // namespace | ||
|
||
ABSL_CONST_INIT const absl::string_view | ||
StevenYCChou marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
kGceApiRequestErrors = | ||
"container.googleapis.com/internal/metadata_agent/gce_api_request_errors"; | ||
|
||
::opencensus::stats::MeasureInt64 GceApiRequestErrors() { | ||
StevenYCChou marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
static const auto measure = | ||
::opencensus::stats::MeasureInt64::Register( | ||
kGceApiRequestErrors, | ||
"Number of API request errors encountered.", | ||
kCount); | ||
return measure; | ||
} | ||
|
||
::opencensus::stats::TagKey MethodTagKey() { | ||
static const auto method_tag_key = | ||
::opencensus::stats::TagKey::Register("method"); | ||
return method_tag_key; | ||
} | ||
|
||
const ::opencensus::stats::ViewDescriptor& GceApiRequestErrorsCumulative() { | ||
const static ::opencensus::stats::ViewDescriptor descriptor = | ||
::opencensus::stats::ViewDescriptor() | ||
.set_name("gce_api_request_errors") | ||
.set_measure(kGceApiRequestErrors) | ||
.set_aggregation(::opencensus::stats::Aggregation::Count()) | ||
.add_column(MethodTagKey()); | ||
return descriptor; | ||
} | ||
|
||
void RegisterAllViewsForExport() { | ||
GceApiRequestErrorsCumulative().RegisterForExport(); | ||
} | ||
|
||
} // namespace google |
Uh oh!
There was an error while loading. Please reload this page.