Skip to content

Commit fdb81ba

Browse files
authored
Fix first bucket otlp issue if invalid end stamp (#665)
1 parent 65e3fa2 commit fdb81ba

24 files changed

+40
-63
lines changed

src/AbstractMetricsManager.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class AbstractMetricsBucket
218218

219219
virtual void to_json(json &j) const = 0;
220220
virtual void to_prometheus(std::stringstream &out, Metric::LabelMap add_labels = {}) const = 0;
221-
virtual void to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels = {}) const = 0;
221+
virtual void to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels = {}) const = 0;
222222
virtual void update_topn_metrics(size_t topn_count, uint64_t percentile_threshold) = 0;
223223
};
224224

@@ -553,8 +553,13 @@ class AbstractMetricsManager
553553
if (!_tap_name.empty() && add_labels.find("tap") == add_labels.end()) {
554554
add_labels["tap"] = _tap_name;
555555
}
556-
557-
_metric_buckets.at(period)->to_opentelemetry(scope, add_labels);
556+
auto bucket = _metric_buckets.at(period).get();
557+
auto start_ts = bucket->start_tstamp();
558+
auto end_ts = bucket->end_tstamp();
559+
if (!end_ts.tv_sec) {
560+
timespec_get(&end_ts, TIME_UTC);
561+
}
562+
bucket->to_opentelemetry(scope, start_ts, end_ts, add_labels);
558563
}
559564

560565
void window_external_opentelemetry(metrics::v1::ScopeMetrics &scope, AbstractMetricsBucket *bucket, Metric::LabelMap add_labels = {}) const
@@ -563,7 +568,13 @@ class AbstractMetricsManager
563568
return;
564569
}
565570
// static because caller guarantees only our own bucket type
566-
static_cast<MetricsBucketClass *>(bucket)->to_opentelemetry(scope, add_labels);
571+
auto sbucket = static_cast<MetricsBucketClass *>(bucket);
572+
auto start_ts = sbucket->start_tstamp();
573+
auto end_ts = sbucket->end_tstamp();
574+
if (!end_ts.tv_sec) {
575+
timespec_get(&end_ts, TIME_UTC);
576+
}
577+
sbucket->to_opentelemetry(scope, start_ts, end_ts, add_labels);
567578
}
568579

569580
void window_external_prometheus(std::stringstream &out, AbstractMetricsBucket *bucket, Metric::LabelMap add_labels = {}) const

src/handlers/bgp/BgpStreamHandler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,8 @@ void BgpMetricsBucket::to_prometheus(std::stringstream &out, Metric::LabelMap ad
189189
_counters.filtered.to_prometheus(out, add_labels);
190190
}
191191

192-
void BgpMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels) const
192+
void BgpMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels) const
193193
{
194-
auto start_ts = start_tstamp();
195-
auto end_ts = end_tstamp();
196-
197194
_rate_total.to_opentelemetry(scope, start_ts, end_ts, add_labels);
198195

199196
{

src/handlers/bgp/BgpStreamHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BgpMetricsBucket final : public visor::AbstractMetricsBucket
7878
void specialized_merge(const AbstractMetricsBucket &other, Metric::Aggregate agg_operator) override;
7979
void to_json(json &j) const override;
8080
void to_prometheus(std::stringstream &out, Metric::LabelMap add_labels = {}) const override;
81-
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels = {}) const override;
81+
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels = {}) const override;
8282
void update_topn_metrics(size_t, uint64_t) override
8383
{
8484
}

src/handlers/dhcp/DhcpStreamHandler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,8 @@ void DhcpMetricsBucket::to_prometheus(std::stringstream &out, Metric::LabelMap a
150150
_dhcp_topServers.to_prometheus(out, add_labels);
151151
}
152152

153-
void DhcpMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels) const
153+
void DhcpMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels) const
154154
{
155-
auto start_ts = start_tstamp();
156-
auto end_ts = end_tstamp();
157-
158155
_rate_total.to_opentelemetry(scope, start_ts, end_ts, add_labels);
159156

160157
{

src/handlers/dhcp/DhcpStreamHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class DhcpMetricsBucket final : public visor::AbstractMetricsBucket
100100
void specialized_merge(const AbstractMetricsBucket &other, Metric::Aggregate agg_operator) override;
101101
void to_json(json &j) const override;
102102
void to_prometheus(std::stringstream &out, Metric::LabelMap add_labels = {}) const override;
103-
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels = {}) const override;
103+
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels = {}) const override;
104104
void update_topn_metrics(size_t, uint64_t) override
105105
{
106106
}

src/handlers/dns/v1/DnsStreamHandler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,11 +1238,8 @@ void DnsMetricsBucket::to_prometheus(std::stringstream &out, Metric::LabelMap ad
12381238
});
12391239
}
12401240

1241-
void DnsMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels) const
1241+
void DnsMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels) const
12421242
{
1243-
auto start_ts = start_tstamp();
1244-
auto end_ts = end_tstamp();
1245-
12461243
_rate_total.to_opentelemetry(scope, start_ts, end_ts, add_labels);
12471244

12481245
{

src/handlers/dns/v1/DnsStreamHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class DnsMetricsBucket final : public visor::AbstractMetricsBucket
199199
void specialized_merge(const AbstractMetricsBucket &other, Metric::Aggregate agg_operator) override;
200200
void to_json(json &j) const override;
201201
void to_prometheus(std::stringstream &out, Metric::LabelMap add_labels = {}) const override;
202-
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels = {}) const override;
202+
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels = {}) const override;
203203
void update_topn_metrics(size_t topn_count, uint64_t percentile_threshold) override
204204
{
205205
_dns_topGeoLocECS.set_settings(topn_count, percentile_threshold);

src/handlers/dns/v2/DnsStreamHandler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,11 +840,8 @@ void DnsMetricsBucket::to_prometheus(std::stringstream &out, Metric::LabelMap ad
840840
}
841841
}
842842

843-
void DnsMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels) const
843+
void DnsMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels) const
844844
{
845-
auto start_ts = start_tstamp();
846-
auto end_ts = end_tstamp();
847-
848845
for (auto &dns : _dns) {
849846
auto dir_labels = add_labels;
850847
dir_labels["direction"] = _dir_str.at(dns.first);

src/handlers/dns/v2/DnsStreamHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class DnsMetricsBucket final : public visor::AbstractMetricsBucket
362362
void specialized_merge(const AbstractMetricsBucket &other, Metric::Aggregate agg_operator) override;
363363
void to_json(json &j) const override;
364364
void to_prometheus(std::stringstream &out, Metric::LabelMap add_labels = {}) const override;
365-
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels = {}) const override;
365+
void to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels = {}) const override;
366366
void update_topn_metrics(size_t topn_count, uint64_t percentile_threshold) override
367367
{
368368
_topn_count = topn_count;

src/handlers/flow/FlowStreamHandler.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,8 @@ void FlowMetricsBucket::to_prometheus(std::stringstream &out, Metric::LabelMap a
885885
}
886886
}
887887

888-
void FlowMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, Metric::LabelMap add_labels) const
888+
void FlowMetricsBucket::to_opentelemetry(metrics::v1::ScopeMetrics &scope, timespec &start_ts, timespec &end_ts, Metric::LabelMap add_labels) const
889889
{
890-
auto start_ts = start_tstamp();
891-
auto end_ts = end_tstamp();
892-
893890
std::shared_lock r_lock(_mutex);
894891

895892
for (const auto &device : _devices_metrics) {

0 commit comments

Comments
 (0)