Skip to content

Commit 8fc2b43

Browse files
committed
Switches to Gauge/Counter abstractions
1 parent 1265534 commit 8fc2b43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+219
-214
lines changed

doc/developer-guide/api/functions/TSStat.en.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ A plugin can create statistics (metrics) that are accessible in the same way as
2525
statistics. In general monitoring the behavior of plugins in production is easier to do in this way
2626
in contrast to processing log files.
2727

28+
.. note::
29+
30+
These APIs are deprecated as of ATS v10.0.0, and will likely be removed in v11. Instead,
31+
use the new APIs in `Metrics.h` diretly.
32+
2833
Synopsis
2934
========
3035

include/api/Metrics.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ class Metrics
5454
virtual ~AtomicType() = default;
5555

5656
int64_t
57-
load()
57+
load() const
5858
{
5959
return _value.load();
6060
}
6161

62-
// ToDo: This is a little sketchy
62+
// ToDo: This is a little sketchy, but needed for the old InkAPI metrics.
6363
void
6464
store(int64_t val)
6565
{
@@ -391,13 +391,6 @@ class Metrics
391391
metric->_value.fetch_add(val, MEMORY_ORDER);
392392
}
393393

394-
static void
395-
decrement(AtomicType *metric, uint64_t val = 1)
396-
{
397-
ink_assert(metric);
398-
metric->_value.fetch_sub(val, MEMORY_ORDER);
399-
}
400-
401394
static int64_t
402395
load(AtomicType *metric)
403396
{

include/proxy/http/HttpCacheSM.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class HttpCacheSM : public Continuation
160160
abort_read()
161161
{
162162
if (cache_read_vc) {
163-
Metrics::Counter::decrement(http_rsb.current_cache_connections);
163+
Metrics::Gauge::decrement(http_rsb.current_cache_connections);
164164
cache_read_vc->do_io_close(0); // passing zero as aborting read is not an error
165165
cache_read_vc = nullptr;
166166
}
@@ -169,7 +169,7 @@ class HttpCacheSM : public Continuation
169169
abort_write()
170170
{
171171
if (cache_write_vc) {
172-
Metrics::Counter::decrement(http_rsb.current_cache_connections);
172+
Metrics::Gauge::decrement(http_rsb.current_cache_connections);
173173
cache_write_vc->do_io_close(0); // passing zero as aborting write is not an error
174174
cache_write_vc = nullptr;
175175
}
@@ -178,7 +178,7 @@ class HttpCacheSM : public Continuation
178178
close_write()
179179
{
180180
if (cache_write_vc) {
181-
Metrics::Counter::decrement(http_rsb.current_cache_connections);
181+
Metrics::Gauge::decrement(http_rsb.current_cache_connections);
182182
cache_write_vc->do_io_close();
183183
cache_write_vc = nullptr;
184184
}
@@ -187,7 +187,7 @@ class HttpCacheSM : public Continuation
187187
close_read()
188188
{
189189
if (cache_read_vc) {
190-
Metrics::Counter::decrement(http_rsb.current_cache_connections);
190+
Metrics::Gauge::decrement(http_rsb.current_cache_connections);
191191
cache_read_vc->do_io_close();
192192
cache_read_vc = nullptr;
193193
}

include/proxy/http/HttpConfig.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct HttpStatsBlock {
6464
// Need two stats for these for counts and times
6565
Metrics::Counter::AtomicType *background_fill_bytes_aborted;
6666
Metrics::Counter::AtomicType *background_fill_bytes_completed;
67-
Metrics::Counter::AtomicType *background_fill_current_count;
67+
Metrics::Gauge::AtomicType *background_fill_current_count;
6868
Metrics::Counter::AtomicType *background_fill_total_count;
6969
Metrics::Counter::AtomicType *broken_server_connections;
7070
Metrics::Counter::AtomicType *cache_deletes;
@@ -92,13 +92,13 @@ struct HttpStatsBlock {
9292
Metrics::Counter::AtomicType *cache_writes;
9393
Metrics::Counter::AtomicType *completed_requests;
9494
Metrics::Counter::AtomicType *connect_requests;
95-
Metrics::Counter::AtomicType *current_active_client_connections;
96-
Metrics::Counter::AtomicType *current_cache_connections;
97-
Metrics::Counter::AtomicType *current_client_connections;
98-
Metrics::Counter::AtomicType *current_client_transactions;
99-
Metrics::Counter::AtomicType *current_parent_proxy_connections;
100-
Metrics::Counter::AtomicType *current_server_connections;
101-
Metrics::Counter::AtomicType *current_server_transactions;
95+
Metrics::Gauge::AtomicType *current_active_client_connections;
96+
Metrics::Gauge::AtomicType *current_cache_connections;
97+
Metrics::Gauge::AtomicType *current_client_connections;
98+
Metrics::Gauge::AtomicType *current_client_transactions;
99+
Metrics::Gauge::AtomicType *current_parent_proxy_connections;
100+
Metrics::Gauge::AtomicType *current_server_connections;
101+
Metrics::Gauge::AtomicType *current_server_transactions;
102102
Metrics::Counter::AtomicType *delete_requests;
103103
Metrics::Counter::AtomicType *disallowed_post_100_continue;
104104
Metrics::Counter::AtomicType *dns_lookup_begin_time;
@@ -164,7 +164,7 @@ struct HttpStatsBlock {
164164
Metrics::Counter::AtomicType *parent_proxy_request_total_bytes;
165165
Metrics::Counter::AtomicType *parent_proxy_response_total_bytes;
166166
Metrics::Counter::AtomicType *parent_proxy_transaction_time;
167-
Metrics::Counter::AtomicType *pooled_server_connections;
167+
Metrics::Gauge::AtomicType *pooled_server_connections;
168168
Metrics::Counter::AtomicType *post_body_too_large;
169169
Metrics::Counter::AtomicType *post_requests;
170170
Metrics::Counter::AtomicType *proxy_loop_detected;
@@ -265,7 +265,7 @@ struct HttpStatsBlock {
265265
Metrics::Counter::AtomicType *total_transactions_time;
266266
Metrics::Counter::AtomicType *total_x_redirect;
267267
Metrics::Counter::AtomicType *trace_requests;
268-
Metrics::Counter::AtomicType *tunnel_current_active_connections;
268+
Metrics::Gauge::AtomicType *tunnel_current_active_connections;
269269
Metrics::Counter::AtomicType *tunnels;
270270
Metrics::Counter::AtomicType *ua_begin_time;
271271
Metrics::Counter::AtomicType *ua_begin_write_time;
@@ -302,7 +302,7 @@ struct HttpStatsBlock {
302302
Metrics::Counter::AtomicType *user_agent_request_header_total_size;
303303
Metrics::Counter::AtomicType *user_agent_response_document_total_size;
304304
Metrics::Counter::AtomicType *user_agent_response_header_total_size;
305-
Metrics::Counter::AtomicType *websocket_current_active_client_connections;
305+
Metrics::Gauge::AtomicType *websocket_current_active_client_connections;
306306
};
307307

308308
enum CacheOpenWriteFailAction_t {

include/proxy/http2/HTTP2.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ const uint8_t HTTP2_PRIORITY_DEFAULT_WEIGHT = 15;
7777

7878
// Statistics
7979
struct Http2StatsBlock {
80-
Metrics::Counter::AtomicType *current_client_session_count;
81-
Metrics::Counter::AtomicType *current_server_session_count;
82-
Metrics::Counter::AtomicType *current_active_client_connection_count;
83-
Metrics::Counter::AtomicType *current_active_server_connection_count;
84-
Metrics::Counter::AtomicType *current_client_stream_count;
85-
Metrics::Counter::AtomicType *current_server_stream_count;
80+
Metrics::Gauge::AtomicType *current_client_session_count;
81+
Metrics::Gauge::AtomicType *current_server_session_count;
82+
Metrics::Gauge::AtomicType *current_active_client_connection_count;
83+
Metrics::Gauge::AtomicType *current_active_server_connection_count;
84+
Metrics::Gauge::AtomicType *current_client_stream_count;
85+
Metrics::Gauge::AtomicType *current_server_stream_count;
8686
Metrics::Counter::AtomicType *total_client_stream_count;
8787
Metrics::Counter::AtomicType *total_server_stream_count;
8888
Metrics::Counter::AtomicType *total_transactions_time;

include/proxy/http2/Http2ServerSession.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ class Http2ServerSession : public PoolableSession, public Http2CommonSession
7272
void
7373
increment_current_active_connections_stat() override
7474
{
75-
Metrics::Counter::increment(http2_rsb.current_active_server_connection_count);
75+
Metrics::Gauge::increment(http2_rsb.current_active_server_connection_count);
7676
}
7777

7878
void
7979
decrement_current_active_connections_stat() override
8080
{
81-
Metrics::Counter::decrement(http2_rsb.current_active_server_connection_count);
81+
Metrics::Gauge::decrement(http2_rsb.current_active_server_connection_count);
8282
}
8383

8484
// noncopyable

include/proxy/logging/LogConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct LogsStatsBlock {
6060
Metrics::Counter::AtomicType *bytes_lost_before_flush_to_disk;
6161
Metrics::Counter::AtomicType *bytes_written_to_disk;
6262
Metrics::Counter::AtomicType *bytes_lost_before_written_to_disk;
63-
Metrics::Counter::AtomicType *log_files_open;
63+
Metrics::Gauge::AtomicType *log_files_open;
6464
Metrics::Gauge::AtomicType *log_files_space_used;
6565
};
6666

src/api/InkAPI.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6251,20 +6251,20 @@ tsapi::c::TSHttpTxnLookingUpTypeGet(TSHttpTxn txnp)
62516251
int
62526252
tsapi::c::TSHttpCurrentClientConnectionsGet()
62536253
{
6254-
return Metrics::Counter::load(http_rsb.current_client_connections);
6254+
return Metrics::Gauge::load(http_rsb.current_client_connections);
62556255
}
62566256

62576257
int
62586258
tsapi::c::TSHttpCurrentActiveClientConnectionsGet()
62596259
{
6260-
return Metrics::Counter::load(http_rsb.current_active_client_connections);
6260+
return Metrics::Gauge::load(http_rsb.current_active_client_connections);
62616261
}
62626262

62636263
int
62646264
tsapi::c::TSHttpCurrentIdleClientConnectionsGet()
62656265
{
6266-
int64_t total = Metrics::Counter::load(http_rsb.current_client_connections);
6267-
int64_t active = Metrics::Counter::load(http_rsb.current_active_client_connections);
6266+
int64_t total = Metrics::Gauge::load(http_rsb.current_client_connections);
6267+
int64_t active = Metrics::Gauge::load(http_rsb.current_active_client_connections);
62686268

62696269
if (total >= active) {
62706270
return static_cast<int>(total - active);
@@ -6276,13 +6276,13 @@ tsapi::c::TSHttpCurrentIdleClientConnectionsGet()
62766276
int
62776277
tsapi::c::TSHttpCurrentCacheConnectionsGet()
62786278
{
6279-
return Metrics::Counter::load(http_rsb.current_cache_connections);
6279+
return Metrics::Gauge::load(http_rsb.current_cache_connections);
62806280
}
62816281

62826282
int
62836283
tsapi::c::TSHttpCurrentServerConnectionsGet()
62846284
{
6285-
return Metrics::Counter::load(http_rsb.current_server_connections);
6285+
return Metrics::Gauge::load(http_rsb.current_server_connections);
62866286
}
62876287

62886288
/* HTTP alternate selection */

src/api/test_Metrics.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,24 @@ TEST_CASE("Metrics", "[libtsapi][Metrics]")
5757
REQUIRE(m[fooid].load() == 1);
5858
}
5959

60-
SECTION("operator[]")
60+
SECTION("operator[] & store")
6161
{
62-
m[0].store(42);
62+
auto storeid = Metrics::Gauge::create("store");
6363

64-
REQUIRE(m[0].load() == 42);
64+
m[storeid].store(42);
65+
66+
REQUIRE(m[storeid].load() == 42);
6567
}
6668

6769
SECTION("Span allocation")
6870
{
6971
ts::Metrics::IdType span_id;
70-
auto fooid = Metrics::Counter::create("foo"); // To see that span_id gets to 2
72+
auto fooid = m.lookup("foo");
7173
auto span = Metrics::Counter::createSpan(17, &span_id);
7274

7375
REQUIRE(span.size() == 17);
7476
REQUIRE(fooid == 1);
75-
REQUIRE(span_id == 2);
77+
REQUIRE(span_id == 3);
7678

7779
m.rename(span_id + 0, "span.0");
7880
m.rename(span_id + 1, "span.1");

src/iocore/aio/test_AIO.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ dump_summary()
226226
Metrics::Counter::AtomicType *completed = m.lookup(m.lookup("proxy.process.io_uring.completed"));
227227
Metrics::Counter::AtomicType *submitted = m.lookup(m.lookup("proxy.process.io_uring.submitted"));
228228

229-
printf("submissions: %lu\n", Metrics::Counter::load(submitted));
230-
printf("completions: %lu\n", Metrics::Counter::load(completed));
229+
printf("submissions: %lu\n", Metrics::Gauge::load(submitted));
230+
printf("completions: %lu\n", Metrics::Gauge::load(completed));
231231
#endif
232232

233233
if (delete_disks) {

0 commit comments

Comments
 (0)