-
Notifications
You must be signed in to change notification settings - Fork 2.1k
"wake up" internal prometheus scrapper metrics (up / scrape_xxxx) #3116
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
Merged
bogdandrutu
merged 22 commits into
open-telemetry:main
from
gillg:feat/add-internal-prom-metrics
Jun 21, 2021
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
03a3b39
Try to make internal prometheus scrapper metrics working
gillg 2215a65
Alternative method, working directly on metricFamily
gillg 6a71cc8
Try to fix unittests
gillg 6071e60
Try to fix prometheus exporter tests
gillg a2bb22c
Try to fix prometheus exporter tests
gillg fe1cf0f
Remove unwanted test about internal metrics
gillg 8846595
Try to fix unittests
gillg 2c765b4
Try to fix unittests
gillg 2c0c953
Try to fix unittests
gillg dc925ed
receiver/prometheus: fix e2e tests
Aneurysm9 cec43a7
receiver/prometheus: add e2e tests for label keys and values
Aneurysm9 651d07a
receiver/prometheus: remove unused test metric spec
Aneurysm9 fb3faf1
Add useful logs
gillg 97bf229
Fix useless units and comments
gillg 408c80c
Fix too verbose log and bad test
gillg 701fdbb
Fix prom exporter test if scrap duration is instant
gillg 1018140
Fix lint
gillg 789737d
Update exporter/prometheusexporter/end_to_end_test.go
gillg 1e56159
Try to fix exporter test
gillg d979b1f
Remove unwanted file
gillg e2c4d6d
fix tests after rebasing
dashpole 3ac8fdf
Fix lint
gillg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,15 @@ | |
| package internal | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sort" | ||
| "strings" | ||
|
|
||
| metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1" | ||
| "github.com/prometheus/prometheus/pkg/labels" | ||
| "github.com/prometheus/prometheus/pkg/textparse" | ||
| "github.com/prometheus/prometheus/scrape" | ||
| "go.uber.org/zap" | ||
| "google.golang.org/protobuf/types/known/timestamppb" | ||
| "google.golang.org/protobuf/types/known/wrapperspb" | ||
| ) | ||
|
|
@@ -46,7 +48,7 @@ type metricFamily struct { | |
| groups map[string]*metricGroup | ||
| } | ||
|
|
||
| func newMetricFamily(metricName string, mc MetadataCache) MetricFamily { | ||
| func newMetricFamily(metricName string, mc MetadataCache, logger *zap.Logger) MetricFamily { | ||
| familyName := normalizeMetricName(metricName) | ||
|
|
||
| // lookup metadata based on familyName | ||
|
|
@@ -62,11 +64,17 @@ func newMetricFamily(metricName string, mc MetadataCache) MetricFamily { | |
| metadata.Metric = familyName | ||
| metadata.Type = textparse.MetricTypeUnknown | ||
| } | ||
| } else if !ok && isInternalMetric(metricName) { | ||
| metadata = defineInternalMetric(metricName, metadata, logger) | ||
| } | ||
| ocaMetricType := convToOCAMetricType(metadata.Type) | ||
| if ocaMetricType == metricspb.MetricDescriptor_UNSPECIFIED { | ||
| logger.Debug(fmt.Sprintf("Invalid metric : %s %+v", metricName, metadata)) | ||
| } | ||
|
|
||
| return &metricFamily{ | ||
| name: familyName, | ||
| mtype: convToOCAMetricType(metadata.Type), | ||
| mtype: ocaMetricType, | ||
| mc: mc, | ||
| droppedTimeseries: 0, | ||
| labelKeys: make(map[string]bool), | ||
|
|
@@ -77,6 +85,35 @@ func newMetricFamily(metricName string, mc MetadataCache) MetricFamily { | |
| } | ||
| } | ||
|
|
||
| // Define manually the metadata of prometheus scrapper internal metrics | ||
| func defineInternalMetric(metricName string, metadata scrape.MetricMetadata, logger *zap.Logger) scrape.MetricMetadata { | ||
| if metadata.Metric != "" && metadata.Type != "" && metadata.Help != "" { | ||
| logger.Debug("Internal metric seems already fully defined") | ||
| return metadata | ||
| } | ||
| metadata.Metric = metricName | ||
|
|
||
| switch metricName { | ||
| case scrapeUpMetricName: | ||
| metadata.Type = textparse.MetricTypeGauge | ||
|
gillg marked this conversation as resolved.
|
||
| metadata.Help = "The scraping was successful" | ||
| case "scrape_duration_seconds": | ||
| metadata.Unit = "seconds" | ||
|
Contributor
Author
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. Is There a convention about that ? I saw in test scenarios some
Contributor
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. See the above. We should use "seconds" here. |
||
| metadata.Type = textparse.MetricTypeGauge | ||
| metadata.Help = "Duration of the scrape" | ||
| case "scrape_samples_scraped": | ||
| metadata.Type = textparse.MetricTypeGauge | ||
| metadata.Help = "The number of samples the target exposed" | ||
| case "scrape_series_added": | ||
| metadata.Type = textparse.MetricTypeGauge | ||
| metadata.Help = "The approximate number of new series in this scrape" | ||
| case "scrape_samples_post_metric_relabeling": | ||
| metadata.Type = textparse.MetricTypeGauge | ||
| metadata.Help = "The number of samples remaining after metric relabeling was applied" | ||
| } | ||
| return metadata | ||
| } | ||
|
|
||
| func (mf *metricFamily) IsSameFamily(metricName string) bool { | ||
| // trim known suffix if necessary | ||
| familyName := normalizeMetricName(metricName) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.