Skip to content

Commit

Permalink
Cherry pick PR #711: Fix issue where only one metrics upload was occu…
Browse files Browse the repository at this point in the history
…rring (#750)

Turns out, the metrics libraries need to be regularly told the app has
not gone idle between metrics uploads.

Added a timer to the demo and a note about the initial upload interval
as well.

b/288915935

Change-Id: I93b322615467344e6db48883950cae644b1e551d
(cherry picked from commit cb1e721)

Co-authored-by: Joel Martinez <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and joeltine authored Jun 27, 2023
1 parent 0ccce81 commit d4e87cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cobalt/browser/metrics/cobalt_metrics_service_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ void CobaltMetricsServiceClient::CollectFinalMetricsForLog(
// Chrome uses this to update memory histograms. Regardless, you must call
// done_callback when done else the uploader will never get invoked.
std::move(done_callback).Run();

// MetricsService will shut itself down if the app doesn't periodically tell
// it it's not idle. In Cobalt's case, we don't want this behavior. Watch
// sessions for LR can happen for extended periods of time with no action by
// the user. So, we always just set the app as "non-idle" immediately after
// each metric log is finalized.
GetMetricsService()->OnApplicationNotIdle();
}

std::string CobaltMetricsServiceClient::GetMetricsServerUrl() {
Expand Down
9 changes: 8 additions & 1 deletion cobalt/demos/content/telemetry/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,20 @@ <h1>LOG OUTPUT:</h1>
}

function init() {
log('Initializing window.h5vcc.metrics');
log('Initializing window.h5vcc.metrics.');
let timer = 0;
let interval = 10000;
setInterval(() => {
timer += interval;
log(`timer: ${timer / 1000}s`);
}, interval);

const metrics = window.h5vcc.metrics;
log(`Getting metrics enabled state metrics.isEnabled(): ${metrics.isEnabled()}`);
log('Enabling metrics reporting: metrics.enable()');
metrics.enable();
log(`Setting metric event interval: metrics.setMetricEventInterval(${EVENT_INTERVAL_SECS})`);
log(`Note that the first upload interval will always be 60 seconds, regardless of metricEventInterval.`);
metrics.setMetricEventInterval(EVENT_INTERVAL_SECS);
log('Binding metric event handler: metrics.onMetricEvent(metricEventHandler)');
metrics.onMetricEvent(metricEventHandler);
Expand Down

0 comments on commit d4e87cc

Please sign in to comment.