• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jupp0r / prometheus-cpp / 7267948222

19 Dec 2023 09:49PM UTC coverage: 96.499%. Remained the same
7267948222

Pull #676

github

web-flow
Merge 8832e95d6 into 540a5a522
Pull Request #676: feat(push): allow timeout for HTTP requests

827 of 857 relevant lines covered (96.5%)

102248.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/pull/src/endpoint.cc
1
#include "endpoint.h"
2

3
#include <utility>
4

5
#include "basic_auth.h"
6
#include "handler.h"
7
#include "prometheus/detail/future_std.h"
8

9
namespace prometheus {
10
namespace detail {
11

12
namespace {
13
class AlwaysAllowAccessHandler : public CivetAuthHandler {
14
  bool authorize(CivetServer*, struct mg_connection*) override { return true; }
×
15
};
16

17
AlwaysAllowAccessHandler alwaysAllowAccessHandler;
18
}  // namespace
19

20
Endpoint::Endpoint(CivetServer& server, std::string uri)
16✔
21
    : server_(server),
22
      uri_(std::move(uri)),
16✔
23
      endpoint_registry_(std::make_shared<Registry>()),
24
      metrics_handler_(
25
          detail::make_unique<MetricsHandler>(*endpoint_registry_)) {
16✔
26
  RegisterCollectable(endpoint_registry_);
16✔
27
  server_.addHandler(uri_, metrics_handler_.get());
16✔
28
}
16✔
29

30
Endpoint::~Endpoint() {
16✔
31
  server_.removeHandler(uri_);
16✔
32
  if (auth_handler_) {
16✔
33
    // work-around https://github.com/civetweb/civetweb/issues/941
34
    // server_.removeAuthHandler(uri_);
35
    server_.addAuthHandler(uri_, alwaysAllowAccessHandler);
2✔
36
  }
37
}
16✔
38

39
void Endpoint::RegisterCollectable(
34✔
40
    const std::weak_ptr<Collectable>& collectable) {
41
  metrics_handler_->RegisterCollectable(collectable);
34✔
42
}
34✔
43

44
void Endpoint::RegisterAuth(
2✔
45
    std::function<bool(const std::string&, const std::string&)> authCB,
46
    const std::string& realm) {
47
  // split creating, assigning, and storing to avoid a race-condition when
48
  // being called the second time and the handler is replaced
49
  auto new_handler =
50
      detail::make_unique<BasicAuthHandler>(std::move(authCB), realm);
4✔
51
  server_.addAuthHandler(uri_, new_handler.get());
2✔
52
  auth_handler_ = std::move(new_handler);
2✔
53
}
2✔
54

55
void Endpoint::RemoveCollectable(
2✔
56
    const std::weak_ptr<Collectable>& collectable) {
57
  metrics_handler_->RemoveCollectable(collectable);
2✔
58
}
2✔
59

60
const std::string& Endpoint::GetURI() const { return uri_; }
8✔
61

62
}  // namespace detail
63
}  // namespace prometheus
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc