Skip to content

Add support for emitting metrics from tests. - #1349

Merged
google-prow-robot merged 1 commit into
knative:masterfrom
bobcatfish:instrumentation_for_realz
Jun 27, 2018
Merged

google-prow-robot merged 1 commit into
knative:masterfrom
bobcatfish:instrumentation_for_realz

Conversation

@bobcatfish

@bobcatfish bobcatfish commented Jun 26, 2018 •

Copy link
Copy Markdown
Contributor

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, which I'd be very interested
to hear some opinions about:

  • 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.

Fixes #1008

NONE

@google-prow-robot google-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 26, 2018
@bobcatfish

Copy link
Copy Markdown
Contributor Author

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)

@adrcunha

Copy link
Copy Markdown
Contributor

It's interesting that the build tests don't include //test. This is fixed by #1350

I found this in the integration tests log:

W0626 02:58:59.777] test/e2e_flags.go:66:3: undefined: setVerboseLevel

Ignore the error about BUILD.bazel and .sh files, #1347 should fix that once merged.

Comment thread test/README.md Outdated

##### Latency metrics

Running tests with verbose logging will also cause latency metrics to be emitted by

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have an exclusive flag for emitting latency metrics, as discussed offline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline some more, i am adding a flag such that we can emit metrics without running in verbose mode

Comment thread test/adding_tests.md Outdated
number of nanoseconds since Jan 1, 1970 UTC), and duration is in `ms`, for example:

```bash
METRIC WaitForConfigurationState/prodxiparjxt/ConfigurationUpdatedWithRevision 1529980772357637397 1529980772431586609 73.949212ms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please document the format of the metric name? I see 3 items in the name here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay explanation added below. Note that the name of the metric is arbitrary - the Wait methods use a particular format, but:

  1. The caller could provide any metric format they wanted, including spaces, commas, slashes
  2. Test authors can also call trace.StartSpan at 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.)

Comment thread test/kube_polling.go
@@ -1,56 +0,0 @@
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirming that removing this file is also intentional. :)

Comment thread test/e2e_flags.go
}

// VerboseLogLevel defines verbose log level as 10
const VerboseLogLevel glog.Level = 10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember Jessie mentioned glog.Level 10 a few times in the docs, would be nice to remove that stale information as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the glog level is still 10, moved into logging.go which i had forgotten to add to this commit initially XD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, --logverbose would still output level 10 logs from k8s, it's not stale.

Comment thread test/e2e_flags.go
LogVerbose bool
}

// VerboseLogLevel defines verbose log level as 10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirming the verbose initialization here is intentional. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classic! i forgot to add the new files i created XD

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take a look at logging.go, i moved this code into that file

@bobcatfish

bobcatfish commented Jun 26, 2018 •

Copy link
Copy Markdown
Contributor Author

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.

@bobcatfish
bobcatfish force-pushed the instrumentation_for_realz branch 2 times, most recently from 4ca9469 to 2951066 Compare June 26, 2018 17:01
@jonjohnsonjr

jonjohnsonjr commented Jun 26, 2018 •

Copy link
Copy Markdown
Contributor

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 I like passing around loggers rather than using a global logger, since it makes it easier (possible) to test what gets logged. Similarly reasoning would apply to the metrics.

My opinion on this has been recently colored by reading this (excellent) post:
https://peter.bourgon.org/go-for-industrial-programming/#logging
https://peter.bourgon.org/go-for-industrial-programming/#context-use-and-misuse

I'm happy to be persuaded otherwise, though 😄

@jessiezcc

Copy link
Copy Markdown
Contributor

@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.

Comment thread test/README.md
1. [A running `Knative Serving` cluster.](/DEVELOPMENT.md#getting-started)
2. The namespaces `pizzaplanet` and `noodleburg`:
```bash
kubectl create namespace pizzaplanet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of requiring manually creating these namespace, why didn't we auto create them in test code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread test/adding_tests.md Outdated

##### Metric format

When a `trace` metric is emitted, the format is `METRIC, start time, end time, duration`. The name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing "name" in the format?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, nice catch!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also those commas are out of date 😅

return cond.Status == corev1.ConditionTrue, nil
}
})
}, "RouteIsReady")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to get results fast and leave non blocking stuff to future PRs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #1379 to look into this more, also added a comment about this above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm fine with iterating on it.

@bobcatfish
bobcatfish force-pushed the instrumentation_for_realz branch from 2951066 to adb8a93 Compare June 26, 2018 17:32
@mdemirhan

Copy link
Copy Markdown
Contributor

@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.

@bobcatfish

Copy link
Copy Markdown
Contributor Author

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).

thanks @mdemirhan, I'll change the output and the docs to match!

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.

Sounds cool :D

@bobcatfish

Copy link
Copy Markdown
Contributor Author

@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.

@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!

Knative code passes around logger, I adopted the same approach for test case.

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!

@steuhs

steuhs commented Jun 26, 2018

Copy link
Copy Markdown
Contributor

/test pull-knative-serving-go-coverage

@bobcatfish

Copy link
Copy Markdown
Contributor Author

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).

thanks @mdemirhan, I'll change the output and the docs to match!

Talked about this more with @mdemirhan and came to a few conclusions:

  • We are using a trace to measure the latency, but the duration we are outputting is a metric, so the term 'metric' is still accurate
  • We could benefit from using the trace functionality more, e.g. tracing requests through controllers, but that's not something we can do with these tests in their current form, created Add controller specific integration/performance tests #1359 to look into it more

So in the context of these particular tests, the term "metric" works.

@bobcatfish
bobcatfish force-pushed the instrumentation_for_realz branch 3 times, most recently from 382787d to fa02f4c Compare June 26, 2018 22:38
@bobcatfish

Copy link
Copy Markdown
Contributor Author

Okay ready for another look @adrcunha @jessiezcc !

@bobcatfish

Copy link
Copy Markdown
Contributor Author

#1366 to see what it looks like to use a global logger.

Comment thread test/adding_tests.md
* 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO still accurate?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but it is being addressed in #1366 (sorry for the confusion that that PR also has these changes!)

Comment thread test/adding_tests.md Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: ConfigurationUpdatedWithRevision

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty!

Comment thread test/adding_tests.md Outdated
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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a typo here? Maybe instead of "as" it would be "are"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the sentence is hard to read, will re-word!

return cond.Status == corev1.ConditionTrue, nil
}
})
}, "RouteIsReady")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to get results fast and leave non blocking stuff to future PRs.

@adrcunha

Copy link
Copy Markdown
Contributor

/lgtm
/approve

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

@google-prow-robot google-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Jun 27, 2018
@google-prow-robot

Copy link
Copy Markdown

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pmorie

pmorie commented Jun 27, 2018

Copy link
Copy Markdown
Contributor

cc @jeremyeder

Comment thread test/logging.go
// 1 second was chosen arbitrarily
metricViewReportingPeriod = 1 * time.Second
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for moving logger stuff into a separate file, cleaner!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! :D

Comment thread test/adding_tests.md Outdated
#### 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.

@jessiezcc jessiezcc Jun 27, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@bobcatfish
bobcatfish force-pushed the instrumentation_for_realz branch from fa02f4c to e6088e6 Compare June 27, 2018 21:45
@google-prow-robot google-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 27, 2018
@bobcatfish

Copy link
Copy Markdown
Contributor Author

/hold cancel

@google-prow-robot google-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 27, 2018
@bobcatfish

Copy link
Copy Markdown
Contributor Author

To address @jessiezcc 's feedback re. the (definitely currently dubious) implementation of the metric names I've created #1379

@jessiezcc

Copy link
Copy Markdown
Contributor

/lgtm

@google-prow-robot google-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 27, 2018
@google-prow-robot
google-prow-robot merged commit fdba26d into knative:master Jun 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants