Set up config update code path

This sets up a basic code path for implementing modular config updates.

Test: m statsd
Change-Id: I7db188fb0ac2f6a0e021f476f4c1ae5b752dc878
This commit is contained in:
Tej Singh
2020-07-30 13:40:19 -07:00
parent 97683bf1da
commit 906a2e4fb2
6 changed files with 36 additions and 14 deletions

View File

@@ -513,19 +513,34 @@ void StatsLogProcessor::OnConfigUpdated(const int64_t timestampNs, const ConfigK
OnConfigUpdatedLocked(timestampNs, key, config);
}
void StatsLogProcessor::OnConfigUpdatedLocked(
const int64_t timestampNs, const ConfigKey& key, const StatsdConfig& config) {
void StatsLogProcessor::OnConfigUpdatedLocked(const int64_t timestampNs, const ConfigKey& key,
const StatsdConfig& config, bool modularUpdate) {
VLOG("Updated configuration for key %s", key.ToString().c_str());
sp<MetricsManager> newMetricsManager =
new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap, mPullerManager,
mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
if (newMetricsManager->isConfigValid()) {
newMetricsManager->init();
mUidMap->OnConfigUpdated(key);
newMetricsManager->refreshTtl(timestampNs);
mMetricsManagers[key] = newMetricsManager;
VLOG("StatsdConfig valid");
// Create new config if this is not a modular update or if this is a new config.
const auto& it = mMetricsManagers.find(key);
bool configValid = false;
if (!modularUpdate || it == mMetricsManagers.end()) {
sp<MetricsManager> newMetricsManager =
new MetricsManager(key, config, mTimeBaseNs, timestampNs, mUidMap, mPullerManager,
mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
configValid = newMetricsManager->isConfigValid();
if (configValid) {
newMetricsManager->init();
mUidMap->OnConfigUpdated(key);
newMetricsManager->refreshTtl(timestampNs);
mMetricsManagers[key] = newMetricsManager;
VLOG("StatsdConfig valid");
}
} else {
// Preserve the existing MetricsManager, update necessary components and metadata in place.
configValid = it->second->updateConfig(timestampNs, config);
if (configValid) {
// TODO(b/162323476): refresh TTL, ensure init() is handled properly.
mUidMap->OnConfigUpdated(key);
}
}
if (!configValid) {
// If there is any error in the config, don't use it.
// Remove any existing config with the same key.
ALOGE("StatsdConfig NOT valid");

View File

@@ -183,8 +183,8 @@ private:
void resetIfConfigTtlExpiredLocked(const int64_t timestampNs);
void OnConfigUpdatedLocked(
const int64_t currentTimestampNs, const ConfigKey& key, const StatsdConfig& config);
void OnConfigUpdatedLocked(const int64_t currentTimestampNs, const ConfigKey& key,
const StatsdConfig& config, bool modularUpdate = false);
void GetActiveConfigsLocked(const int uid, vector<int64_t>& outActiveConfigs);

View File

@@ -195,6 +195,10 @@ MetricsManager::~MetricsManager() {
VLOG("~MetricsManager()");
}
bool MetricsManager::updateConfig(const int64_t currentTimeNs, const StatsdConfig& config) {
return mConfigValid;
}
void MetricsManager::initLogSourceWhiteList() {
std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
mAllowedLogSources.clear();

View File

@@ -46,6 +46,8 @@ public:
virtual ~MetricsManager();
bool updateConfig(const int64_t currentTimeNs, const StatsdConfig& config);
// Return whether the configuration is valid.
bool isConfigValid() const;

View File

@@ -17,6 +17,8 @@
#ifndef STATSD_PACKAGE_INFO_LISTENER_H
#define STATSD_PACKAGE_INFO_LISTENER_H
#include <utils/RefBase.h>
#include <string>
namespace android {

View File

@@ -17,7 +17,6 @@
#pragma once
#include "config/ConfigKey.h"
#include "config/ConfigListener.h"
#include "packages/PackageInfoListener.h"
#include "stats_util.h"