1
#pragma once
2

            
3
#include "envoy/extensions/matching/actions/transform_stat/v3/transform_stat.pb.h"
4
#include "envoy/stats/tag.h"
5

            
6
#include "source/common/matcher/matcher.h"
7
#include "source/common/protobuf/utility.h"
8
#include "source/common/stats/symbol_table.h"
9

            
10
namespace Envoy {
11
namespace Extensions {
12
namespace Matching {
13
namespace Actions {
14
namespace TransformStat {
15

            
16
using ProtoTransformStat = envoy::extensions::matching::actions::transform_stat::v3::TransformStat;
17

            
18
struct ActionContext {
19
14
  ActionContext(Envoy::Stats::StatNamePool& pool) : pool_(pool) {}
20
  Envoy::Stats::StatNamePool& pool_;
21
};
22

            
23
class TransformStatAction {
24
public:
25
  /**
26
   * The result of the action application.
27
   */
28
  enum class Result {
29
    // The stat should be kept (emitted).
30
    Keep,
31
    // The stat should be dropped (not emitted).
32
    DropStat,
33
    // The tag should be dropped.
34
    DropTag,
35
  };
36

            
37
14
  virtual ~TransformStatAction() = default;
38

            
39
  /**
40
   * Apply the action to the supplied tags.
41
   * @param tags supplied the tags to be applied.
42
   * @return Result result of the action.
43
   */
44
  virtual Result apply(std::string& tag_value) const PURE;
45
};
46

            
47
class DropStat : public Matcher::ActionBase<ProtoTransformStat>, public TransformStatAction {
48
public:
49
7
  explicit DropStat(const ProtoTransformStat::DropStat&) {}
50

            
51
  Result apply(std::string&) const override;
52
};
53

            
54
class UpdateTag : public Matcher::ActionBase<ProtoTransformStat>, public TransformStatAction {
55
public:
56
  explicit UpdateTag(const std::string& tag_value);
57

            
58
  Result apply(std::string& tag_value) const override;
59

            
60
private:
61
  const std::string tag_value_;
62
};
63

            
64
class DropTag : public Matcher::ActionBase<ProtoTransformStat>, public TransformStatAction {
65
public:
66
2
  explicit DropTag() = default;
67

            
68
  Result apply(std::string& tag_value) const override;
69
};
70

            
71
class NoOpAction : public Matcher::ActionBase<ProtoTransformStat>, public TransformStatAction {
72
public:
73
1
  explicit NoOpAction() {}
74
  Result apply(std::string&) const override;
75
};
76

            
77
} // namespace TransformStat
78
} // namespace Actions
79
} // namespace Matching
80
} // namespace Extensions
81
} // namespace Envoy