-
Notifications
You must be signed in to change notification settings - Fork 181
Add presubmit test to verify v2 metrics are working when enabled #1980
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
Open
cjreynol
wants to merge
4
commits into
google:main
Choose a base branch
from
cjreynol:test_metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−11
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32d205c
Only write metrics event files when enabled
cjreynol 7724afd
Add group metrics directory to `cvd fleet` output
cjreynol b868adf
Install `cuttlefish-metrics` to test container
cjreynol 183b800
Add presubmit test to verify metrics transmission
cjreynol 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
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
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 |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e -x | ||
|
|
||
| BRANCH="" | ||
| TARGET="" | ||
| CREDENTIAL_SOURCE="${CREDENTIAL_SOURCE:-}" | ||
|
|
||
| while getopts "b:c:t:" opt; do | ||
| case "${opt}" in | ||
| b) | ||
| BRANCH="${OPTARG}" | ||
| ;; | ||
| c) | ||
| CREDENTIAL_SOURCE="${OPTARG}" | ||
| ;; | ||
| t) | ||
| TARGET="${OPTARG}" | ||
| ;; | ||
| *) | ||
| echo "Unknown flag: -${opt}" >&2 | ||
| echo "Usage: $0 -b BRANCH -t TARGET" | ||
| exit 1 | ||
| esac | ||
| done | ||
| shift $((OPTIND-1)) | ||
|
|
||
| if [[ "${BRANCH}" == "" ]]; then | ||
| echo "Missing required -b argument" | ||
| fi | ||
|
|
||
| if [[ "${TARGET}" == "" ]]; then | ||
| echo "Missing required -t argument" | ||
| fi | ||
|
|
||
| workdir="$(mktemp -d -t cvd_command_test.XXXXXX)" | ||
|
|
||
| function collect_logs_and_cleanup() { | ||
| # Don't immediately exit on failure anymore | ||
| set +e | ||
| if [[ -n "${TEST_UNDECLARED_OUTPUTS_DIR}" ]] && [[ -d "${TEST_UNDECLARED_OUTPUTS_DIR}" ]]; then | ||
| cp "${workdir}"/*.log "${TEST_UNDECLARED_OUTPUTS_DIR}" | ||
| cp "${workdir}"/cuttlefish_runtime/*.log "${TEST_UNDECLARED_OUTPUTS_DIR}" | ||
| cp "${workdir}"/cuttlefish_runtime/logcat "${TEST_UNDECLARED_OUTPUTS_DIR}" | ||
| cp "${workdir}"/cuttlefish_runtime/cuttlefish_config.json "${TEST_UNDECLARED_OUTPUTS_DIR}" | ||
| fi | ||
| rm -rf "${workdir}" | ||
| # Be nice, don't leave devices behind. | ||
| cvd reset -y | ||
| } | ||
|
|
||
| # Regardless of whether and when a failure occurs logs must collected | ||
| trap collect_logs_and_cleanup EXIT | ||
|
|
||
| # Make sure to run in a clean environment, without any devices running | ||
| cvd reset -y | ||
|
|
||
| credential_arg="" | ||
| if [[ -n "$CREDENTIAL_SOURCE" ]]; then | ||
| credential_arg="--credential_source=${CREDENTIAL_SOURCE}" | ||
| fi | ||
|
|
||
| cvd fetch \ | ||
| --default_build="${BRANCH}/${TARGET}" \ | ||
| --target_directory="${workdir}" \ | ||
| ${credential_arg} | ||
|
|
||
| ( | ||
| cd "${workdir}" | ||
|
|
||
| # generate instantiation, start, and boot complete events | ||
| cvd create --host_path="${workdir}" --product_path="${workdir}" | ||
|
|
||
| # verify transmission by detecting existence of the metrics directory and the debug event files | ||
| metrics_dir=`cvd fleet | jq --raw-output '.groups.[0].metrics_dir'` | ||
| if ! [[ -d "${metrics_dir}" ]]; then | ||
| echo "metrics directory not found" | ||
| exit | ||
| fi | ||
|
|
||
| # file prefixes sourced from `cuttlefish/host/libs/metrics/event_type.cc::EventTypeString` function | ||
| if ! [[ -f "`ls ${metrics_dir}/device_instantiation*.txtpb`" ]]; then | ||
| echo "metrics not transmitted for the expected instantiation event" | ||
| exit | ||
| fi | ||
| if ! [[ -f "`ls ${metrics_dir}/device_boot_start*.txtpb`" ]]; then | ||
| echo "metrics not transmitted for the expected start event" | ||
| exit | ||
| fi | ||
| if ! [[ -f "`ls ${metrics_dir}/device_boot_complete*.txtpb`" ]]; then | ||
| echo "metrics not transmitted for the expected boot complete event" | ||
| exit | ||
| fi | ||
|
|
||
| # generate stop event and verify transmission | ||
| cvd stop | ||
| if ! [[ -f "`ls ${metrics_dir}/device_stop*.txtpb`" ]]; then | ||
| echo "metrics not transmitted for the expected stop event" | ||
| exit | ||
| fi | ||
| ) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs to block this PR but I find this one file per event type quite strange.
It also seems like this file generation as-is right now completely overwrites any existing file (
android-cuttlefish/base/cvd/cuttlefish/host/libs/metrics/metrics_writer.cc
Line 51 in 35f43d8
I think it is feasible to have repeating events. Could the existing boot completed event trigger twice currently if someone did a
adb reboot?I guess I would imagine us having something like a
and then there would be a single "metrics.txtpb" file which can be written to in an appending fashion.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the
<event type>*.txtpbto simplify the checks here because we are controlling thecvdinvocations and know there will only be one event per type, but the full filepath for each event is generated with the format:to avoid the possibility of overwriting.
reference:
android-cuttlefish/base/cvd/cuttlefish/host/libs/metrics/metrics_writer.cc
Line 47 in 35f43d8
Each event is also per group, capturing the details for each instance within the group (since we cannot start/stop individual instances).
Which all means that it is fine to have an invocation sequence like:
and the resulting
<group_root_directory>/metrics/directory could have event files roughly like:The timestamps are the practical differentiator, though the random number suffix is there in the case where two event types somehow occurred on the same group at the same time. I believe
cvdprevents that from being possible in practice, but just in case.I do not think an
adb rebootwill trigger new events, since the V2 metrics are allcvdgenerated (to ideally work identically across any build/host tools). The V1 metrics might capture that, but I do not know either way.All of that said, I am not opposed to a single, expanding file. The main drivers for going this direction were:
cvdis doing the writing (and thus transmitting) at the time of each event rather than gathering up events and doing it all at once (to avoid missing events due to unexpected failures). Coming up with a unique filename and writing a separate file matched that one-event-at-a-time structure.