This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Added test exporter for use in unit tests.#1185
Merged
rghetia merged 7 commits intocensus-instrumentation:masterfrom Dec 4, 2019
jkohen:test_exporter
Merged
Added test exporter for use in unit tests.#1185rghetia merged 7 commits intocensus-instrumentation:masterfrom jkohen:test_exporter
rghetia merged 7 commits intocensus-instrumentation:masterfrom
jkohen:test_exporter
Conversation
With this exporter one can write unit tests to verify that the instrumentation is working. See the included code example.
rghetia
reviewed
Dec 3, 2019
| metrics.ReadAndExport() | ||
| metricValue := getCounter(metrics, myMetric.Name(), newMetricKey("label1")) | ||
| fmt.Printf("increased by %d\n", metricValue-metricBase) | ||
| } |
Contributor
There was a problem hiding this comment.
why not simply display the value of Counter?
Counter value 1
Counter value 3
Counter value 6
why do you need metricBase?
Contributor
Author
There was a problem hiding this comment.
metricBase is needed to isolate test runs. The metric state is global, so if there are two tests that refer to the same metric, a test that looks for absolute values will fail. I confirmed that by removing metricBase, then creating a copy of the example. The output was:
% go test -v go.opencensus.io/metric/test
=== RUN ExampleExporter
--- PASS: ExampleExporter (0.00s)
=== RUN ExampleExporter_2
--- FAIL: ExampleExporter_2 (0.00s)
got:
increased by 7
increased by 9
increased by 12
want:
increased by 1
increased by 3
increased by 6
FAIL
FAIL go.opencensus.io/metric/test 0.005s
jkohen
commented
Dec 4, 2019
Contributor
Author
jkohen
left a comment
There was a problem hiding this comment.
I just added a new example to cover the metric package. @rghetia what do you think? It seems less fragile than the existing tests that use something like:
ms := r.Read()
if got, want := ms[0].TimeSeries[0].Points[0].Value.(int64), int64(3); got != want { ... }
rghetia
reviewed
Dec 4, 2019
rghetia
approved these changes
Dec 4, 2019
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
With this exporter one can write unit tests to verify that the instrumentation is working. See the included code example.