Partial config update: various small things
- init new/replaced metrics - guardrails for number of metrics/matchers/conditions/alerts - report update to statsdstats - update if the config is active Test: atest statsd_test Bug: 162323476 Change-Id: Ieaa2d18903de8020fcee5bb128124ab19f10a152
This commit is contained in:
@@ -549,9 +549,7 @@ void StatsLogProcessor::OnConfigUpdatedLocked(const int64_t timestampNs, const C
|
||||
configValid = it->second->updateConfig(config, mTimeBaseNs, timestampNs,
|
||||
mAnomalyAlarmMonitor, mPeriodicAlarmMonitor);
|
||||
if (configValid) {
|
||||
// TODO(b/162323476): refresh TTL, ensure init() is handled properly.
|
||||
mUidMap->OnConfigUpdated(key);
|
||||
|
||||
}
|
||||
}
|
||||
if (!configValid) {
|
||||
|
||||
@@ -97,40 +97,8 @@ MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config,
|
||||
for (const auto& annotation : config.annotation()) {
|
||||
mAnnotations.emplace_back(annotation.field_int64(), annotation.field_int32());
|
||||
}
|
||||
|
||||
// Guardrail. Reject the config if it's too big.
|
||||
if (mAllMetricProducers.size() > StatsdStats::kMaxMetricCountPerConfig ||
|
||||
mAllConditionTrackers.size() > StatsdStats::kMaxConditionCountPerConfig ||
|
||||
mAllAtomMatchingTrackers.size() > StatsdStats::kMaxMatcherCountPerConfig) {
|
||||
ALOGE("This config is too big! Reject!");
|
||||
mConfigValid = false;
|
||||
}
|
||||
if (mAllAnomalyTrackers.size() > StatsdStats::kMaxAlertCountPerConfig) {
|
||||
ALOGE("This config has too many alerts! Reject!");
|
||||
mConfigValid = false;
|
||||
}
|
||||
|
||||
mIsAlwaysActive = (mMetricIndexesWithActivation.size() != mAllMetricProducers.size()) ||
|
||||
(mAllMetricProducers.size() == 0);
|
||||
bool isActive = mIsAlwaysActive;
|
||||
for (int metric : mMetricIndexesWithActivation) {
|
||||
isActive |= mAllMetricProducers[metric]->isActive();
|
||||
}
|
||||
mIsActive = isActive;
|
||||
VLOG("mIsActive is initialized to %d", mIsActive)
|
||||
|
||||
// no matter whether this config is valid, log it in the stats.
|
||||
StatsdStats::getInstance().noteConfigReceived(
|
||||
key, mAllMetricProducers.size(), mAllConditionTrackers.size(),
|
||||
mAllAtomMatchingTrackers.size(), mAllAnomalyTrackers.size(), mAnnotations,
|
||||
mConfigValid);
|
||||
// Check active
|
||||
for (const auto& metric : mAllMetricProducers) {
|
||||
if (metric->isActive()) {
|
||||
mIsActive = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
verifyGuardrailsAndUpdateStatsdStats();
|
||||
initializeConfigActiveStatus();
|
||||
}
|
||||
|
||||
MetricsManager::~MetricsManager() {
|
||||
@@ -211,6 +179,9 @@ bool MetricsManager::updateConfig(const StatsdConfig& config, const int64_t time
|
||||
mPullAtomUids.clear();
|
||||
mPullAtomPackages.clear();
|
||||
createAllLogSourcesFromConfig(config);
|
||||
|
||||
verifyGuardrailsAndUpdateStatsdStats();
|
||||
initializeConfigActiveStatus();
|
||||
return mConfigValid;
|
||||
}
|
||||
|
||||
@@ -272,6 +243,35 @@ void MetricsManager::createAllLogSourcesFromConfig(const StatsdConfig& config) {
|
||||
}
|
||||
}
|
||||
|
||||
void MetricsManager::verifyGuardrailsAndUpdateStatsdStats() {
|
||||
// Guardrail. Reject the config if it's too big.
|
||||
if (mAllMetricProducers.size() > StatsdStats::kMaxMetricCountPerConfig ||
|
||||
mAllConditionTrackers.size() > StatsdStats::kMaxConditionCountPerConfig ||
|
||||
mAllAtomMatchingTrackers.size() > StatsdStats::kMaxMatcherCountPerConfig) {
|
||||
ALOGE("This config is too big! Reject!");
|
||||
mConfigValid = false;
|
||||
}
|
||||
if (mAllAnomalyTrackers.size() > StatsdStats::kMaxAlertCountPerConfig) {
|
||||
ALOGE("This config has too many alerts! Reject!");
|
||||
mConfigValid = false;
|
||||
}
|
||||
// no matter whether this config is valid, log it in the stats.
|
||||
StatsdStats::getInstance().noteConfigReceived(
|
||||
mConfigKey, mAllMetricProducers.size(), mAllConditionTrackers.size(),
|
||||
mAllAtomMatchingTrackers.size(), mAllAnomalyTrackers.size(), mAnnotations,
|
||||
mConfigValid);
|
||||
}
|
||||
|
||||
void MetricsManager::initializeConfigActiveStatus() {
|
||||
mIsAlwaysActive = (mMetricIndexesWithActivation.size() != mAllMetricProducers.size()) ||
|
||||
(mAllMetricProducers.size() == 0);
|
||||
mIsActive = mIsAlwaysActive;
|
||||
for (int metric : mMetricIndexesWithActivation) {
|
||||
mIsActive |= mAllMetricProducers[metric]->isActive();
|
||||
}
|
||||
VLOG("mIsActive is initialized to %d", mIsActive);
|
||||
}
|
||||
|
||||
void MetricsManager::initAllowedLogSources() {
|
||||
std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex);
|
||||
mAllowedLogSources.clear();
|
||||
|
||||
@@ -292,6 +292,14 @@ private:
|
||||
// Calls initAllowedLogSources and initPullAtomSources. Sets mConfigValid to false on error.
|
||||
void createAllLogSourcesFromConfig(const StatsdConfig& config);
|
||||
|
||||
// Verifies the config meets guardrails and updates statsdStats.
|
||||
// Sets mConfigValid to false on error. Should be called on config creation/update
|
||||
void verifyGuardrailsAndUpdateStatsdStats();
|
||||
|
||||
// Initializes mIsAlwaysActive and mIsActive.
|
||||
// Should be called on config creation/update.
|
||||
void initializeConfigActiveStatus();
|
||||
|
||||
// The metrics that don't need to be uploaded or even reported.
|
||||
std::set<int64_t> mNoReportMetricIds;
|
||||
|
||||
|
||||
@@ -895,6 +895,12 @@ bool updateMetrics(const ConfigKey& key, const StatsdConfig& config, const int64
|
||||
}
|
||||
}
|
||||
|
||||
// Init new/replaced metrics.
|
||||
for (size_t i = 0; i < newMetricProducers.size(); i++) {
|
||||
if (metricsToUpdate[i] == UPDATE_REPLACE || metricsToUpdate[i] == UPDATE_NEW) {
|
||||
newMetricProducers[i]->prepareFirstBucket();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user