Try<Nothing> PrExecutorPassFilter::consume(const ResourceUsage& in) { ResourceUsage product; product.mutable_total()->CopyFrom(in.total()); for (ResourceUsage_Executor inExec : in.executors()) { if (!inExec.has_executor_info()) { LOG(ERROR) << name << "Executor <unknown>" << " does not include executor_info"; // Filter out these executors. continue; } if (inExec.allocated().size() == 0) { LOG(ERROR) << name << "Executor " << inExec.executor_info().executor_id().value() << " does not include allocated resources."; // Filter out these executors. continue; } Resources allocated(inExec.allocated()); // Check if task uses revocable resources. if (!allocated.revocable().empty()) { continue; } // Add an PR executor. ResourceUsage_Executor* outExec = product.mutable_executors()->Add(); outExec->CopyFrom(inExec); } produce(product); return Nothing(); }
Try<Nothing> EMAFilter::consume(const ResourceUsage& in) { ResourceUsage product; for (ResourceUsage_Executor inExec : in.executors()) { if (!inExec.has_executor_info()) { SERENITY_LOG(ERROR) << "Executor <unknown>" << " does not include executor_info"; // Filter out these executors. continue; } if (!inExec.has_statistics()) { SERENITY_LOG(ERROR) << "Executor " << inExec.executor_info().executor_id().value() << " does not include statistics."; // Filter out these executors. continue; } // Check if EMA for given executor exists. auto emaSample = this->emaSamples->find(inExec.executor_info()); if (emaSample == this->emaSamples->end()) { SERENITY_LOG(ERROR) << "First EMA iteration for: " << WID(inExec.executor_info()).toString(); // If not - insert new one. ExponentialMovingAverage ema(EMA_REGULAR_SERIES, this->alpha); emaSamples->insert(std::pair<ExecutorInfo, ExponentialMovingAverage>( inExec.executor_info(), ema)); } else { // Get proper value. Try<double_t> value = this->valueGetFunction(inExec); if (value.isError()) { SERENITY_LOG(ERROR) << value.error(); continue; } // Perform EMA filtering. double_t emaValue = (emaSample->second).calculateEMA( value.get(), inExec.statistics().perf().timestamp()); // Store EMA value. ResourceUsage_Executor* outExec = new ResourceUsage_Executor(inExec); Try<Nothing> result = this->valueSetFunction(emaValue, outExec); if (result.isError()) { SERENITY_LOG(ERROR) << result.error(); delete outExec; continue; } // Add an executor only when there was no error. product.mutable_executors()->AddAllocated(outExec); } } if (0 != product.executors_size()) { SERENITY_LOG(INFO) << "Continuing with " << product.executors_size() << " executor(s)."; // Continue pipeline. // Copy total agent's capacity. product.mutable_total()->CopyFrom(in.total()); produce(product); } return Nothing(); }