8000 make statistics available in metrics API no matter what (#14702) · arangodb/arangodb@a9f55eb · GitHub
[go: up one dir, main page]

Skip to content

Commit a9f55eb

Browse files
jsteemannKVS85
andauthored
make statistics available in metrics API no matter what (#14702)
Previously, if `--server.statistics` was set to `false`, the metrics API did not return any values provided by the StatisticsFeature, as the statistics were turned off completely. This prevented the metrics API from returning some useful process statistics (e.g. memory usage, number of threads etc.). This change now enables these process statistics as well as a few others in metrics regardless of the setting of `--server.statistics`. This was already the case in 3.8 and devel, but 3.7 still behaved slightly differently Co-authored-by: Vadim <vadim@arangodb.com>
1 parent 852f3e2 commit a9f55eb

9 files changed

+400
-321
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
v3.7.15 (XXXX-XX-XX)
22
--------------------
33

4+
* Make statistics available in metrics API even if `--server.statistics` is set
5+
to `false`. This allows clients to fetch some process statistics metrics from
6+
instances that have statistics aggregation and storage turned off.
7+
48
* Updated arangosync to 1.8.0.
59

610
* Added protocol specific metrics: histogram about request body size, total

arangod/RestServer/MetricsFeature.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ void MetricsFeature::validateOptions(std::shared_ptr<ProgramOptions>) {
8585
}
8686
}
8787

88-
8988
void MetricsFeature::toPrometheus(std::string& result) const {
90-
9189
// minimize reallocs
9290
result.reserve(32768);
9391

@@ -100,10 +98,8 @@ void MetricsFeature::toPrometheus(std::string& result) const {
10098

10199
// StatisticsFeature
102100
auto& sf = server().getFeature<StatisticsFeature>();
103-
if (sf.enabled()) {
104-
sf.toPrometheus(result, std::chrono::duration<double, std::milli>(
105-
std::chrono::system_clock::now().time_since_epoch()).count());
106-
}
101+
sf.toPrometheus(result, std::chrono::duration<double, std::milli>(
102+
std::chrono::system_clock::now().time_since_epoch()).count());
107103

108104
// RocksDBEngine
109105
auto es = EngineSelectorFeature::ENGINE;

arangod/Statistics/ConnectionStatistics.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ ConnectionStatistics::Item ConnectionStatistics::acquire() {
7272
}
7373

7474
void ConnectionStatistics::getSnapshot(Snapshot& snapshot) {
75-
if (!StatisticsFeature::enabled()) {
76-
// all the below objects may be deleted if we don't have statistics enabled
77-
return;
78-
}
79-
8075
snapshot.httpConnections = statistics::HttpConnections;
8176
snapshot.totalRequests = statistics::TotalRequests;
8277
snapshot.totalRequestsSuperuser = statistics::TotalRequestsSuperuser;

arangod/Statistics/RequestStatistics.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ void RequestStatistics::release() {
195195
}
196196

197197
void RequestStatistics::getSnapshot(Snapshot& snapshot, stats::RequestStatisticsSource source) {
198-
if (!StatisticsFeature::enabled()) {
199-
// all the below objects may be deleted if we don't have statistics enabled
200-
return;
201-
}
202-
203198
statistics::RequestFigures& figures = source == stats::RequestStatisticsSource::USER
204199
? statistics::UserRequestFigures
205200
: statistics::SuperuserRequestFigures;

arangod/Statistics/StatisticsFeature.cpp

Lines changed: 290 additions & 7 deletions
Large diffs are not rendered by default.

arangod/Statistics/StatisticsFeature.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define APPLICATION_FEATURES_STATISTICS_FEATURE_H 1
2525

2626
#include <array>
27+
#include <initializer_list>
2728

2829
#include "ApplicationFeatures/ApplicationFeature.h"
2930
#include "Basics/Result.h"
@@ -115,7 +116,15 @@ class StatisticsFeature final : public application_features::ApplicationFeature
115116

116117
bool allDatabases() const { return _statisticsAllDatabases; }
117118

119+
static arangodb::velocypack::Builder fillDistribution(statistics::Distribution const& dist);
120+
118121
private:
122+
void appendHistogram(
123+
std::string& result, statistics::Distribution const& dist,
124+
std::string const& label, std::initializer_list<std::string> const& les) const;
125+
void appendMetric(
126+
std::string& result, std::string const& val, std::string const& label) const;
127+
119128
bool _statistics;
120129
bool _statisticsHistory;
121130
bool _statisticsHistoryTouched;

arangod/Statistics/StatisticsWorker.cpp

Lines changed: 7 additions & 292 deletions
Large diffs are not rendered by default.

arangod/Statistics/StatisticsWorker.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ class StatisticsWorker final : public Thread {
7373
// save one statistics object
7474
void saveSlice(velocypack::Slice const&, std::string const&) const;
7575

76-
void appendHistogram(
77-
std::string& result, statistics::Distribution const& dist,
78-
std::string const& label, std::initializer_list<std::string> const& les) const;
79-
void appendMetric(
80-
std::string& result, std::string const& val, std::string const& label) const;
81-
8276
static constexpr uint64_t STATISTICS_INTERVAL = 10; // 10 secs
8377
static constexpr uint64_t GC_INTERVAL = 8 * 60; // 8 mins
8478
static constexpr uint64_t HISTORY_INTERVAL = 15 * 60; // 15 mins
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*jshint globalstrict:false, strict:false */
2+
/* global getOptions, assertEqual, assertTrue, arango */
3+
4+
////////////////////////////////////////////////////////////////////////////////
5+
/// @brief test for security-related server options
6+
///
7+
/// @file
8+
///
9+
/// DISCLAIMER
10+
///
11+
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
12+
///
13+
/// Licensed under the Apache License, Version 2.0 (the "License");
14+
/// you may not use this file except in compliance with the License.
15+
/// You may obtain a copy of the License at
16+
///
17+
/// http://www.apache.org/licenses/LICENSE-2.0
18+
///
19+
/// Unless required by applicable law or agreed to in writing, software
20+
/// distributed under the License is distributed on an "AS IS" BASIS,
21+
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
/// See the License for the specific language governing permissions and
23+
/// limitations under the License.
24+
///
25+
/// Copyright holder is ArangoDB Inc, Cologne, Germany
26+
///
27+
/// @author Jan Steemann
28+
/// @author Copyright 2019, ArangoDB Inc, Cologne, Germany
29+
////////////////////////////////////////////////////////////////////////////////
30+
31+
if (getOptions === true) {
32+
return {
33+
'server.statistics': "false",
34+
'server.export-metrics-api': "true",
35+
};
36+
}
37+
38+
const jsunity = require('jsunity');
39+
40+
function testSuite() {
41+
return {
42+
testGetAdminStatistics : function() {
43+
let res = arango.GET("/_admin/statistics");
44+
assertTrue(res.error);
45+
assertEqual(404, res.code);
46+
},
47+
48+
testGetAdminStatisticsDescription : function() {
49+
let res = arango.GET("/_admin/statistics-description");
50+
assertTrue(res.error);
51+
assertEqual(404, res.code);
52+
},
53+
54+
testGetMetrics : function() {
55+
let metrics = {};
56+
String(arango.GET("/_admin/metrics"))
57+
.split("\n")
58+
.filter((line) EC25 => line.match(/^[^#]/))
59+
.filter((line) => line.match(/^arangodb_/))
60+
.forEach((line) => {
61+
let name = line.replace(/[ \{].*$/g, '');
62+
let value = Number(line.replace(/^.+ (\d+)$/, '$1'));
63+
metrics[name] = value;
64+
});
65+
66+
const expected = [
67+
"arangodb_process_statistics_minor_page_faults",
68+
"arangodb_process_statistics_major_page_faults",
69+
"arangodb_process_statistics_user_time",
70+
"arangodb_process_statistics_system_time",
71+
"arangodb_process_statistics_number_of_threads",
72+
"arangodb_process_statistics_resident_set_size",
73+
"arangodb_process_statistics_resident_set_size_percent",
74+
"arangodb_process_statistics_virtual_memory_size",
75+
"arangodb_server_statistics_physical_memory",
76+
"arangodb_server_statistics_server_uptime",
77+
];
78+
79+
expected.forEach((name) => {
80+
assertTrue(metrics.hasOwnProperty(name));
81+
assertEqual("number", typeof metrics[name]);
82+
});
83+
},
84+
};
85+
}
86+
87+
jsunity.run(testSuite);
88+
return jsunity.done();

0 commit comments

Comments
 (0)
0