-
Notifications
You must be signed in to change notification settings - Fork 508
Expand file tree
/
Copy pathAggregationPolicy.h
More file actions
82 lines (71 loc) · 2.69 KB
/
Copy pathAggregationPolicy.h
File metadata and controls
82 lines (71 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2019-2025 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_FRAMEWORK_METRICAGGREGATOR_AGGREGATIONPOLICY_H
#define O2_FRAMEWORK_METRICAGGREGATOR_AGGREGATIONPOLICY_H
#include <string>
#include <string_view>
#include <vector>
#include <regex>
namespace o2
{
namespace framework
{
namespace metricaggregator
{
/// Defines the selection strategy for devices.
enum class AggregationSelectionType {
All,
Specific
};
/// Defines the reduction strategy for metrics.
enum class AggregationMetricType {
Sum,
Average,
Rate,
Specific,
Simple
};
/// Parses environment configurations and evaluates aggregation rules.
class AggregationPolicy
{
public:
AggregationPolicy() = default;
~AggregationPolicy() = default;
/// Reads configuration from environment variables and sets internal rules.
void configureFromEnv();
/// Returns the configured device selection type.
AggregationSelectionType getSelection() const noexcept;
/// Returns the configured global metric reduction type.
AggregationMetricType getReduction() const noexcept;
/// Determines the specific reduction type required for a given metric name.
AggregationMetricType getAggregationTypeForMetric(std::string_view metricName) const;
/// Evaluates whether the policy allows processing for the provided device name.
bool selectDevice(std::string_view deviceId) const;
private:
/// Maps a regular expression pattern to a specific aggregation type.
struct MetricRule {
std::regex metricPattern;
AggregationMetricType type;
};
std::vector<std::string> split(std::string_view input, char delim) const;
/// Converts a string literal into an AggregationSelectionType enum.
AggregationSelectionType parseSelectionType(const std::string& str);
/// Converts a string literal into an AggregationMetricType enum.
AggregationMetricType parseReductionType(const std::string& str);
AggregationSelectionType mSelection = AggregationSelectionType::All;
AggregationMetricType mReduction = AggregationMetricType::Sum;
std::vector<std::string> mSpecificDevices;
std::vector<MetricRule> mSpecificMetricRules;
};
} // namespace metricaggregator
} // namespace framework
} // namespace o2
#endif // O2_FRAMEWORK_METRICAGGREGATOR_AGGREGATIONPOLICY_H