Skip to content

Commit

Permalink
Moved methods from ExtMonitor to ExtMonitorBase.
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Pakulski <paker8848@gmail.com>
  • Loading branch information
cpakulski committed Jul 17, 2024
1 parent 03018d5 commit a90e1c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
27 changes: 6 additions & 21 deletions envoy/upstream/outlier_detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,17 @@ class LocalOriginEvent : public ExtResult {
Result result_;
};

// Base class for various types of monitors.
// Base class defining api for various types of monitors.
// Each monitor may implement different health detection algorithm.
class ExtMonitor {
public:
ExtMonitor(const std::string& name, uint32_t enforce) : name_(name), enforce_(enforce) {}
ExtMonitor() = delete;
virtual ~ExtMonitor() {}
virtual void reportResult(const ExtResult&) PURE;

void
setCallback(std::function<void(uint32_t, std::string, absl::optional<std::string>)> callback) {
callback_ = callback;
}

void reset() { onReset(); }
std::string name() const { return name_; }

protected:
virtual bool onError() PURE;
virtual void onSuccess() PURE;
virtual void onReset() PURE;
virtual std::string getFailedExtraInfo() { return ""; }

std::string name_;
uint32_t enforce_{100};
std::function<void(uint32_t, std::string, absl::optional<std::string>)> callback_;
// Method to report a result to extensions.
virtual void reportResult(const ExtResult&) PURE;
virtual void
setCallback(std::function<void(uint32_t, std::string, absl::optional<std::string>)>) PURE;
virtual void reset() PURE;
};

using ExtMonitorPtr = std::unique_ptr<ExtMonitor>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,32 @@ class LocalOriginEventsBucket

class ExtMonitorBase : public ExtMonitor {
public:
ExtMonitorBase(const std::string& name, uint32_t enforce) : ExtMonitor(name, enforce) {}
ExtMonitorBase(const std::string& name, uint32_t enforce) : name_(name), enforce_(enforce) {}
ExtMonitorBase() = delete;
virtual ~ExtMonitorBase() {}
void reportResult(const ExtResult&) override;

void
setCallback(std::function<void(uint32_t, std::string, absl::optional<std::string>)> callback) {
void setCallback(
std::function<void(uint32_t, std::string, absl::optional<std::string>)> callback) override {
callback_ = callback;
}

void reset() { onReset(); }
void reset() override { onReset(); }
std::string name() const { return name_; }

void processBucketsConfig(
const envoy::extensions::outlier_detection_monitors::common::v3::ErrorBuckets& config);
void addErrorBucket(ErrorsBucketPtr&& bucket) { buckets_.push_back(std::move(bucket)); }

protected:
virtual bool onError() PURE;
virtual void onSuccess() PURE;
virtual void onReset() PURE;
virtual std::string getFailedExtraInfo() { return ""; }

std::string name_;
uint32_t enforce_{100};
std::function<void(uint32_t, std::string, absl::optional<std::string>)> callback_;
std::vector<ErrorsBucketPtr> buckets_;
};

Expand Down

0 comments on commit a90e1c0

Please sign in to comment.