page.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include "counters.h"
  3. #include <library/cpp/monlib/service/pages/pre_mon_page.h>
  4. #include <util/generic/ptr.h>
  5. #include <functional>
  6. namespace NMonitoring {
  7. enum class EUnknownGroupPolicy {
  8. Error, // send 404
  9. Ignore, // send 204
  10. };
  11. struct TDynamicCountersPage: public TPreMonPage {
  12. public:
  13. using TOutputCallback = std::function<void()>;
  14. private:
  15. const TIntrusivePtr<TDynamicCounters> Counters;
  16. TOutputCallback OutputCallback;
  17. EUnknownGroupPolicy UnknownGroupPolicy {EUnknownGroupPolicy::Error};
  18. private:
  19. void HandleAbsentSubgroup(IMonHttpRequest& request);
  20. public:
  21. TDynamicCountersPage(const TString& path,
  22. const TString& title,
  23. TIntrusivePtr<TDynamicCounters> counters,
  24. TOutputCallback outputCallback = nullptr)
  25. : TPreMonPage(path, title)
  26. , Counters(counters)
  27. , OutputCallback(outputCallback)
  28. {
  29. }
  30. void Output(NMonitoring::IMonHttpRequest& request) override;
  31. void BeforePre(NMonitoring::IMonHttpRequest& request) override;
  32. void OutputText(IOutputStream& out, NMonitoring::IMonHttpRequest&) override;
  33. /// If set to Error, responds with 404 if the requested subgroup is not found. This is the default.
  34. /// If set to Ignore, responds with 204 if the requested subgroup is not found
  35. void SetUnknownGroupPolicy(EUnknownGroupPolicy value);
  36. };
  37. }