Repository navigation
Add support for emitting metrics from tests. - #1349
Conversation
|
This is an example of what the output looks like: ➜ serving git:(instrumentation_for_realz) ✗ go test -v -tags=e2e -count=1 ./test/e2e --logverbose | grep METRIC
info test/logging.go:63 METRIC WaitForRouteState/noodleburgqvarsail/RouteIsReady 1529981236276165887 1529981270432847842 34.156681955s
info test/logging.go:63 METRIC WaitForEndpointState/CheckingEndpointAfterUpdating 1529981270576805043 1529981283812762584 13.235957541s
info test/logging.go:63 METRIC WaitForEndpointState/MakingConcurrentRequests 1529981283813025438 1529981285673116135 1.860090697s
info test/logging.go:63 METRIC WaitForEndpointState/MakingConcurrentRequests 1529981283812947041 1529981285959616219 2.146669178s
info test/logging.go:63 METRIC WaitForEndpointState/MakingConcurrentRequests 1529981283813026025 1529981285983634101 2.170608076s
info test/logging.go:63 METRIC WaitForEndpointState/MakingConcurrentRequests 1529981283812977474 1529981286747324139 2.934346665s
info test/logging.go:63 METRIC WaitForEndpointState/MakingConcurrentRequests 1529981283812905104 1529981286836372969 3.023467865s
info test/logging.go:63 METRIC WaitForDeploymentState/prodprfkjize-00001-deployment/DeploymentIsScaledUp 1529981286836455986 1529981286924056339 87.600353ms
info test/logging.go:63 METRIC WaitForConfigurationState/prodnysjgqez/ContainerImageNotPresent 1529981287376995074 1529981288520305426 1.143310352s
info test/logging.go:63 METRIC WaitForRevision/prodnysjgqez-00001/ImagePathInvalid 1529981288592364695 1529981288666912666 74.547971ms
info test/logging.go:63 METRIC WaitForRouteState/noodleburgyjzbvgzn/RouteIsReady 1529981323655833226 1529981347821137561 24.165304335s
info test/logging.go:63 METRIC WaitForEndpointState/HelloWorldServesText 1529981347893341482 1529981348040102155 146.760673ms
➜ serving git:(instrumentation_for_realz) ✗ go test -v -tags=e2e -count=1 ./test/conformance --logverbose | grep METRIC
info test/logging.go:63 METRIC WaitForConfigurationState/prodjfviaxqn/ConfigurationUpdatedWithRevision 1529981416402760154 1529981416480262061 77.501907ms
info test/logging.go:63 METRIC WaitForRouteState/pizzaplanetrmauqkut/RouteIsReady 1529981416480317573 1529981437648272488 21.167954915s
info test/logging.go:63 METRIC WaitForEndpointState/WaitForEndpointToServeText 1529981437721763782 1529981437955996195 234.232413ms
info test/logging.go:63 METRIC WaitForConfigurationState/prodjfviaxqn/ConfigurationUpdatedWithRevision 1529981438281815842 1529981438353251548 71.435706ms
info test/logging.go:63 METRIC WaitForRouteState/pizzaplanetrmauqkut/RouteIsReady 1529981438353308860 1529981438425150746 71.841886ms
info test/logging.go:63 METRIC WaitForEndpointState/WaitForEndpointToServeText 1529981438527344791 1529981448773341803 10.245997012s(Definitely open to better ideas for identifying these lines than prefacing them with METRIC XD) |
|
|
||
| ##### Latency metrics | ||
|
|
||
| Running tests with verbose logging will also cause latency metrics to be emitted by |
There was a problem hiding this comment.
Can we have an exclusive flag for emitting latency metrics, as discussed offline?
There was a problem hiding this comment.
discussed offline some more, i am adding a flag such that we can emit metrics without running in verbose mode
| number of nanoseconds since Jan 1, 1970 UTC), and duration is in `ms`, for example: | ||
|
|
||
| ```bash | ||
| METRIC WaitForConfigurationState/prodxiparjxt/ConfigurationUpdatedWithRevision 1529980772357637397 1529980772431586609 73.949212ms |
There was a problem hiding this comment.
Can you please document the format of the metric name? I see 3 items in the name here.
There was a problem hiding this comment.
Okay explanation added below. Note that the name of the metric is arbitrary - the Wait methods use a particular format, but:
- The caller could provide any metric format they wanted, including spaces, commas, slashes
- Test authors can also call
trace.StartSpanat any time, in which case the metric name may not follow the same format
(Let me know if you have suggestions for format improvements - my opinion is we should start simple, i.e. not many constraints, no validation, and add complexity only if it turns out to be needed.)
| @@ -1,56 +0,0 @@ | |||
| /* | |||
There was a problem hiding this comment.
Just confirming that removing this file is also intentional. :)
| } | ||
|
|
||
| // VerboseLogLevel defines verbose log level as 10 | ||
| const VerboseLogLevel glog.Level = 10 |
There was a problem hiding this comment.
I remember Jessie mentioned glog.Level 10 a few times in the docs, would be nice to remove that stale information as well.
There was a problem hiding this comment.
the glog level is still 10, moved into logging.go which i had forgotten to add to this commit initially XD
There was a problem hiding this comment.
yes, --logverbose would still output level 10 logs from k8s, it's not stale.
| LogVerbose bool | ||
| } | ||
|
|
||
| // VerboseLogLevel defines verbose log level as 10 |
There was a problem hiding this comment.
Just confirming the verbose initialization here is intentional. :)
There was a problem hiding this comment.
classic! i forgot to add the new files i created XD
There was a problem hiding this comment.
take a look at logging.go, i moved this code into that file
|
The more i think about it, I really think we should change the way the logger works a bit, instead of passing it around everywhere, I think it's not that evil to make it global. That would also mean that the metric exporter and the logger could have the same scope. Would love to hear your thoughts @jessiezcc @jonjohnsonjr , if you agree I can make that change in a separate PR. |
4ca9469 to
2951066
Compare
|
Edit: I just realized this is entirely scoped to just the e2e tests. I think it's not a huge deal to make the logger/tracer global because the depth is pretty flat if we're just measuring how long the tests take. I also don't expect that we'll want to test the tests, but maybe I'm wrong. Preserved for posterity:
|
|
@bobcatfish, with global logger, it's gonna be tricky to add TC specific contexts which is what zaplog is good for. Knative code passes around logger, I adopted the same approach for test case. |
| 1. [A running `Knative Serving` cluster.](/DEVELOPMENT.md#getting-started) | ||
| 2. The namespaces `pizzaplanet` and `noodleburg`: | ||
| ```bash | ||
| kubectl create namespace pizzaplanet |
There was a problem hiding this comment.
instead of requiring manually creating these namespace, why didn't we auto create them in test code?
There was a problem hiding this comment.
the main reason is b/c deleting the namespaces is slow - it means every test needs to check if the namespace already exists or is being deleted before continuing, it can take on the order of several minutes.
There was a problem hiding this comment.
if the check itself is not terribly slow, I think it's still good to automate this in TC as manually creating won't be any faster.
But it's a separate issue outside of this PR.
There was a problem hiding this comment.
i have a slightly different opinion, i think this should be part of the test environment setup in general, but i dont feel too strongly either way and am fine with seeing it change, as long as it doesn't make the tests slow (i think it probably will, it made back to back runs pretty slow when i tried it initially)
|
|
||
| ##### Metric format | ||
|
|
||
| When a `trace` metric is emitted, the format is `METRIC, start time, end time, duration`. The name |
There was a problem hiding this comment.
missing "name" in the format?
There was a problem hiding this comment.
oops, nice catch!
There was a problem hiding this comment.
also those commas are out of date 😅
| return cond.Status == corev1.ConditionTrue, nil | ||
| } | ||
| }) | ||
| }, "RouteIsReady") |
There was a problem hiding this comment.
can we use enum for a list of scenarios/APIs that we track for latency? and reference . here.
We'd have a single place to go for a complete list of tracking scenarios as well.
There was a problem hiding this comment.
One thing I like about this idea is that we could control the names of the metrics!
One thing I don't like is that test authors will need to update this enum with every scenario they add, I feel like that's going to become a big mess once we have more tests and the chances of people reusing the names are pretty low.
What do you think if we leave it like this now and iterate on it? We can add this enum later on.
There was a problem hiding this comment.
+1 to get results fast and leave non blocking stuff to future PRs.
There was a problem hiding this comment.
I'm already seeing that that same name is referenced in multiple files, for example "RouteIsReady".
With enum, not only there is a single place to look up what's already tracked and what not instead of searching through all test cases, but also become sort of forcing factor so that before a new name is added, people can easily look through existing ones. For example, "RouteIsReady" can easily be named as "IsRouteReady". I don't see why it would become a big mess.
There was a problem hiding this comment.
I've created #1379 to look into this more, also added a comment about this above.
There was a problem hiding this comment.
Thanks! I'm fine with iterating on it.
2951066 to
adb8a93
Compare
|
@bobcatfish Thanks for this. This will make tests so much better! One recommendation though: Rather than calling these metrics, we should call them traces, because they really are end to end traces, which end up emitting timing information at the end of a call. Metrics are generally thought of as aggregated measurements and calling these metrics might cause some confusions (it did for me). Another thing that would be really useful in the future is to adding tracing support to our controller code - that way, we will be able to trace how much time is spent in each step to complete some operation. These changes will enable making these visible! I will open a Github issue to track doing those in the controller code as well to get the finer granularity operation timings. |
thanks @mdemirhan, I'll change the output and the docs to match!
Sounds cool :D |
@jessiezcc I think we can actually have both! tests can initialize the test case specific contexts on the global logger - ill put together a quick PR and see what you think!
I think that's totally the right approach and that's why I keep going back and forth on this. In general, globals cause problems, and passing loggers around is better, however the main sticking point I think is that in general libraries should not log - they should leave logging to the caller. But we explicitly want the test library code to be logging regularly, and so for that reason I feel like it's simpler and cleaner to use a global logger. But anyway I'll throw something together and we can keep discussing! |
|
/test pull-knative-serving-go-coverage |
Talked about this more with @mdemirhan and came to a few conclusions:
So in the context of these particular tests, the term "metric" works. |
382787d to
fa02f4c
Compare
|
Okay ready for another look @adrcunha @jessiezcc ! |
|
#1366 to see what it looks like to use a global logger. |
| * The traces are emitted by [a custom metric exporter](./logging.go) | ||
| that uses the global logger instance. | ||
|
|
||
| TODO(bobcatfish): Either make the test case specific named loggers global or update the metric exporter to use the named loggers. |
There was a problem hiding this comment.
Is this TODO still accurate?
There was a problem hiding this comment.
yes but it is being addressed in #1366 (sorry for the confusion that that PR also has these changes!)
| prefix the metric names with the name of the function, and if applicable, the name of the resource, | ||
| separated by `/`. In the example above, `WaitForConfigurationState` is the name of | ||
| the function, and `prodxiparjxt` is the name of the configuration resource being polled. | ||
| `ConfiguationUpdatedWithRevision` is the string passed to `WaitForConfigurationState` by |
There was a problem hiding this comment.
typo: ConfigurationUpdatedWithRevision
| of the metric is arbitrary and can be any string. | ||
|
|
||
| The values of start time and end time as Unix time in nanoseconds (i.e. the | ||
| number of nanoseconds since Jan 1, 1970 UTC), and duration is in `ms`, for example: |
There was a problem hiding this comment.
Looks like there's a typo here? Maybe instead of "as" it would be "are"?
There was a problem hiding this comment.
i think the sentence is hard to read, will re-word!
| return cond.Status == corev1.ConditionTrue, nil | ||
| } | ||
| }) | ||
| }, "RouteIsReady") |
There was a problem hiding this comment.
+1 to get results fast and leave non blocking stuff to future PRs.
|
/lgtm I'm holding so other reviewers can chime in if they want. My comments are not blockers, feel free to merge it once you think it's time. /hold |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: adrcunha, bobcatfish The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
cc @jeremyeder |
| // 1 second was chosen arbitrarily | ||
| metricViewReportingPeriod = 1 * time.Second | ||
| ) | ||
|
|
There was a problem hiding this comment.
thanks for moving logger stuff into a separate file, cleaner!
| #### Metric format | ||
|
|
||
| When a `trace` metric is emitted, the format is `metric name startTime endTime duration`. The name | ||
| of the metric is arbitrary and can be any string. |
There was a problem hiding this comment.
"can be any string" - before a new name is defined, we should guide people to look up what metrics already being tracked and avoid defining duplicated names for same purpose.
There was a problem hiding this comment.
hmmm how about i try the enum that you suggested, and we can see what happens? probably better than any arbitrary string and i like how it would sidestep the problem of people putting in invalid characters
There was a problem hiding this comment.
I've thought about this again and I'm back to thinking people should feel free to define arbitrary strings, and in fact I think that using different values every time would be better. If people reuse the same metric name but the actions being measured are quite different then the results will be misleading.
As long as the parsing logic is generic, it shouldn't matter if additional metrics are added.
I suggest we open another issue to figure out what standard we need for how we name these metrics and iterate on it - especially after we've seen a test or 2 added because it really doesn't seem clear right now what the best path is.
We want to track latency over time by emitting this information from our end to end tests. In this change we use opencensus metric collection to collect and export metrics to the zap logger. The `Wait` (aka polling) functions used by the end to end tests will automatically emit these metrics, identified by a string provided by the caller. These metrics will be emitted if an end to end test is run with `--emitmetrics`. Some choices made in this implementation: * The metric tracker is global, effectively making the logger global, which is contrary to the current logger interface (it must be passed around) * The fact that the caller can provide any string is a bit weird, but also the metric is not meaningful without some context.
fa02f4c to
e6088e6
Compare
|
/hold cancel |
|
To address @jessiezcc 's feedback re. the (definitely currently dubious) implementation of the metric names I've created #1379 |
|
/lgtm |
We want to track latency over time by emitting this information from
our end to end tests.
In this change we use opencensus metric collection to collect and
export metrics to the zap logger. The
Wait(aka polling) functionsused by the end to end tests will automatically emit these metrics,
identified by a string provided by the caller.
These metrics will be emitted if an end to end test is run with
--emitmetrics.Some choices made in this implementation, which I'd be very interested
to hear some opinions about:
which is contrary to the current logger interface (it must be
passed around)
but also the metric is not meaningful without some context.
Fixes #1008