Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 906a2e4f authored by Tej Singh's avatar Tej Singh
Browse files

Set up config update code path

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

Test: m statsd
Change-Id: I7db188fb0ac2f6a0e021f476f4c1ae5b752dc878
parent 97683bf1
Loading
Loading
Loading
Loading
+26 −11
Original line number Diff line number Diff line
@@ -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());
    // 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);
    if (newMetricsManager->isConfigValid()) {
        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");
+2 −2
Original line number Diff line number Diff line
@@ -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);

+4 −0
Original line number Diff line number Diff line
@@ -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();
+2 −0
Original line number Diff line number Diff line
@@ -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;

+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
#ifndef STATSD_PACKAGE_INFO_LISTENER_H
#define STATSD_PACKAGE_INFO_LISTENER_H

#include <utils/RefBase.h>

#include <string>

namespace android {
Loading