1
#pragma once
2

            
3
#include <memory>
4
#include <string>
5
#include <vector>
6

            
7
#include "envoy/common/interval_set.h"
8
#include "envoy/common/pure.h"
9
#include "envoy/stats/tag.h"
10

            
11
#include "absl/strings/string_view.h"
12

            
13
namespace Envoy {
14
namespace Stats {
15

            
16
class TagExtractionContext;
17

            
18
/**
19
 * Class to extract tags from the stat names.
20
 */
21
class TagExtractor {
22
public:
23
526324
  virtual ~TagExtractor() = default;
24

            
25
  /**
26
   * Identifier for the tag extracted by this object.
27
   */
28
  virtual absl::string_view name() const PURE;
29

            
30
  /**
31
   * Finds tags for stat_name and adds them to the tags vector. If the tag is not
32
   * represented in the name, the tags vector will remain unmodified. Also finds the
33
   * character indexes for the tags in stat_name and adds them to remove_characters (an
34
   * in/out arg). Returns true if a tag-match was found. The characters removed from the
35
   * name may be different from the values put into the tag vector for readability
36
   * purposes. Note: The extraction process is expected to be run iteratively, aggregating
37
   * the character intervals to be removed from the name after all the tag extractions are
38
   * complete. This approach simplifies the tag searching process because without mutations,
39
   * the tag extraction will be order independent, apart from the order of the tag array.
40
   * @param context identifies the name from which to extract tags.
41
   * @param tags list of tags updated with the tag name and value if found in the name.
42
   * @param remove_characters set of intervals of character-indices to be removed from name.
43
   * @return bool indicates whether a tag was found in the name.
44
   */
45
  virtual bool extractTag(TagExtractionContext& context, TagVector& tags,
46
                          IntervalSet<size_t>& remove_characters) const PURE;
47

            
48
  /**
49
   * Finds a prefix string associated with the matching criteria owned by the
50
   * extractor. This is used to reduce the number of extractors required for
51
   * processing each stat, by pulling the first "."-separated token on the tag.
52
   *
53
   * If a prefix cannot be extracted, an empty string_view is returned, and the
54
   * matcher must be applied on all inputs.
55
   *
56
   * The storage for the prefix is owned by the TagExtractor.
57
   *
58
   * @return absl::string_view the prefix, or an empty string_view if none was found.
59
   */
60
  virtual absl::string_view prefixToken() const PURE;
61

            
62
  virtual bool otherExtractorWithSameNameExists() const PURE;
63
  virtual void setOtherExtractorWithSameNameExists(bool e) PURE;
64
};
65

            
66
using TagExtractorPtr = std::unique_ptr<TagExtractor>;
67

            
68
} // namespace Stats
69
} // namespace Envoy