Commit d794a4da authored by Paul Asmuth's avatar Paul Asmuth
Browse files

metric service /metrics/value endpoint

parent c3addc8f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
-> remotefeedwriter make max_spread configurable
-> timeouts
-> rpcchannel (rcpclient + servergroup_)
-> rpc numRetries/retryStrategie, onRetry(Duration delay) (instead of ready()/onError!)
+20 −0
Original line number Diff line number Diff line
@@ -204,6 +204,26 @@ void Metric::scanSamples(
  }
}

Sample Metric::getSample() {
  auto snapshot = getSnapshot();
  if (snapshot.get() == nullptr) {
    RAISE(kIndexError, "metric has no samples");
  }

  MetricCursor cursor(snapshot, &token_index_);
  if (!cursor.valid()) {
    RAISE(kIndexError, "invalid metric cusor");
  }

  cursor.seekToMostRecentSample();

  auto smpl_reader = cursor.sample<double>();
  return Sample(
      cursor.time(),
      smpl_reader->value(),
      smpl_reader->labels());
}

void Metric::compact(CompactionPolicy* compaction /* = nullptr */) {
  if (!compaction_mutex_.try_lock()) {
    return;
+2 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ public:
      const fnord::DateTime& time_end,
      std::function<bool (Sample* sample)> callback) override;

  Sample getSample() override;

  void compact(CompactionPolicy* compaction = nullptr);

  void setLiveTableMaxSize(size_t max_size);
+8 −1
Original line number Diff line number Diff line
@@ -25,12 +25,19 @@ MetricCursor::MetricCursor(
    token_index_(token_index),
    table_index_(0) {}

void MetricCursor::seekToMostRecentSample() {
  table_index_ = snapshot_->tables().size() - 1;
  table_cur_ = snapshot_->tables()[table_index_]->cursor();

  // FIXPAUL: this is too slow!
  while (table_cur_->next());
}

bool MetricCursor::next() {
  if (tableCursor()->next()) {
    return true;
  }


  while (table_index_ < (snapshot_->tables().size() - 1)) {
    table_cur_ = snapshot_->tables()[++table_index_]->cursor();

+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public:
  bool next();
  bool valid();

  void seekToMostRecentSample();
  uint64_t time();

  template <typename T>
Loading