From ebafc19506a1e2878a0b2b22227817be989ea16e Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Mon, 10 Jul 2023 17:51:51 -0600 Subject: [PATCH 01/13] New API Metrics, and start of a libtapi.so structure The new API metrics are backwards compatible with previous APIs, since the old API wraps these new APIs. New plugins / code could chose to use the Metrics.h API directly. Work to be finished here includes 1. Decide what goes into include/api ? Do we have one new include file to #include all the include/api/*.h files? 2. What should be moved to src/api and include/api. Lost in this merge is all the work from Chris McFarlen. Thanks! Co-Author: Chris McFarlen --- CMakeLists.txt | 1 + configure.ac | 1 + include/api/Metrics.h | 223 ++++++++++++++++++ include/records/I_RecordsConfig.h | 3 - include/records/P_RecCore.h | 2 +- include/records/P_RecDefs.h | 10 +- .../experimental/remap_stats/remap_stats.cc | 3 - src/Makefile.am | 2 +- src/api/CMakeLists.txt | 26 ++ src/api/Makefile.am | 38 +++ src/api/Metrics.cc | 140 +++++++++++ src/api/test_Metrics.cc | 75 ++++++ src/records/RecCore.cc | 19 +- src/records/RecUtils.cc | 4 +- src/traffic_crashlog/Makefile.inc | 1 + src/traffic_layout/Makefile.inc | 1 + src/traffic_logcat/Makefile.inc | 4 + src/traffic_logstats/Makefile.inc | 8 + src/traffic_server/InkAPI.cc | 86 ++----- src/traffic_server/Makefile.inc | 3 + src/traffic_server/traffic_server.cc | 2 - 21 files changed, 556 insertions(+), 96 deletions(-) create mode 100644 include/api/Metrics.h create mode 100644 src/api/CMakeLists.txt create mode 100644 src/api/Makefile.am create mode 100644 src/api/Metrics.cc create mode 100644 src/api/test_Metrics.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index d771148036a..eda1b79b234 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,6 +355,7 @@ configure_file(include/ts/apidefs.h.in include/ts/apidefs.h) enable_testing() +add_subdirectory(src/api) add_subdirectory(src/tscpp/util) add_subdirectory(src/tscpp/api) add_subdirectory(src/tscore) diff --git a/configure.ac b/configure.ac index 0eb82490533..73d8a2c587f 100644 --- a/configure.ac +++ b/configure.ac @@ -2400,6 +2400,7 @@ AC_CONFIG_FILES([ src/tscpp/util/Makefile src/tscore/Makefile src/records/Makefile + src/api/Makefile tools/Makefile tools/trafficserver.pc tools/tsxs diff --git a/include/api/Metrics.h b/include/api/Metrics.h new file mode 100644 index 00000000000..733c815bb62 --- /dev/null +++ b/include/api/Metrics.h @@ -0,0 +1,223 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "tscore/ink_assert.h" + +namespace ts +{ +class Metrics +{ +private: + using self_type = Metrics; + using IdType = int32_t; // Could be a tuple, but one way or another, they have to be combined to an int32_t. + using AtomicType = std::atomic; + +public: + static constexpr uint16_t METRICS_MAX_BLOBS = 8192; + static constexpr uint16_t METRICS_MAX_SIZE = 2048; // For a total of 16M metrics + static constexpr IdType NOT_FOUND = std::numeric_limits::min(); // <16-bit,16-bit> = + +private: + using NameAndId = std::tuple; + using NameContainer = std::array; + using AtomicContainer = std::array; + using MetricStorage = std::tuple; + using MetricBlobs = std::array; + using LookupTable = std::unordered_map; + +public: + Metrics(const self_type &) = delete; + self_type &operator=(const self_type &) = delete; + Metrics &operator=(Metrics &&) = delete; + Metrics(Metrics &&) = delete; + + virtual ~Metrics() = default; + + Metrics() + { + _blobs[0] = new MetricStorage(); + ink_release_assert(_blobs[0]); + ink_release_assert(0 == newMetric("proxy.node.api.metrics.bad_id")); // Reserve slot 0 for errors, this should always be 0 + } + + // Singleton + static Metrics &getInstance(); + + // Yes, we don't return objects here, but rather ID's and atomic's directly. Treat + // the std::atomic as the underlying class for a single metric, and be happy. + IdType newMetric(const std::string_view name); + IdType lookup(const std::string_view name) const; + AtomicType *lookup(IdType id, std::string_view *name = nullptr) const; + + AtomicType & + operator[](IdType id) + { + return *lookup(id); + } + + IdType + operator[](const std::string_view name) const + { + return lookup(name); + } + + int64_t + increment(IdType id, uint64_t val = 1) + { + auto metric = lookup(id); + + return (metric ? metric->fetch_add(val) : NOT_FOUND); + } + + // ToDo: Do we even need these inc/dec functions? + int64_t + decrement(IdType id, uint64_t val = 1) + { + auto metric = lookup(id); + + return (metric ? metric->fetch_sub(val) : NOT_FOUND); + } + + std::string_view name(IdType id) const; + + bool + valid(IdType id) const + { + auto [blob, entry] = _splitID(id); + + return (id >= 0 && ((blob < _cur_blob && entry < METRICS_MAX_SIZE) || (blob == _cur_blob && entry <= _cur_off))); + } + + class iterator + { + public: + using iterator_category = std::input_iterator_tag; + using value_type = std::tuple; + using difference_type = ptrdiff_t; + using pointer = value_type *; + using reference = value_type &; + + iterator(const Metrics &m, IdType pos) : _metrics(m), _it(pos) {} + + iterator & + operator++() + { + next(); + + return *this; + } + + iterator + operator++(int) + { + iterator result = *this; + + next(); + + return result; + } + + value_type + operator*() const + { + std::string_view name; + auto metric = _metrics.lookup(_it, &name); + + return std::make_tuple(name, metric->load()); + } + + bool + operator==(const iterator &o) const + { + return _it == o._it && std::addressof(_metrics) == std::addressof(o._metrics); + } + + bool + operator!=(const iterator &o) const + { + return _it != o._it || std::addressof(_metrics) != std::addressof(o._metrics); + } + + private: + void next(); + + const Metrics &_metrics; + IdType _it; + }; + + iterator + begin() const + { + return iterator(*this, 0); + } + + iterator + end() const + { + _mutex.lock(); + int16_t blob = _cur_blob; + int16_t offset = _cur_off; + _mutex.unlock(); + + return iterator(*this, _makeId(blob, offset)); + } + +private: + static constexpr std::tuple + _splitID(IdType value) + { + return std::make_tuple(static_cast(value >> 16), static_cast(value & 0xFFFF)); + } + + static constexpr IdType + _makeId(uint16_t blob, uint16_t offset) + { + return (blob << 16 | offset); + } + + static constexpr IdType + _makeId(std::tuple id) + { + return _makeId(std::get<0>(id), std::get<1>(id)); + } + + void _addBlob(); + + mutable std::mutex _mutex; + LookupTable _lookups; + MetricBlobs _blobs; + uint16_t _cur_blob = 0; + uint16_t _cur_off = 0; +}; // class Metrics + +} // namespace ts diff --git a/include/records/I_RecordsConfig.h b/include/records/I_RecordsConfig.h index 2b16f7c030e..df9ea60254f 100644 --- a/include/records/I_RecordsConfig.h +++ b/include/records/I_RecordsConfig.h @@ -25,9 +25,6 @@ #include "records/P_RecCore.h" -// This is to manage the librecords table sizes. Not awesome, but better than the earlier recompiling of ATS requirement... -extern int max_records_entries; - enum RecordRequiredType { RR_NULL, // config is _not_ required to be defined in records.yaml RR_REQUIRED // config _is_ required to be defined in record.config diff --git a/include/records/P_RecCore.h b/include/records/P_RecCore.h index 062bdec9df1..1818ddd2a62 100644 --- a/include/records/P_RecCore.h +++ b/include/records/P_RecCore.h @@ -37,7 +37,7 @@ #include // records, record hash-table, and hash-table rwlock -extern RecRecord *g_records; +extern RecRecord g_records[REC_MAX_RECORDS]; extern std::unordered_map g_records_ht; extern ink_rwlock g_records_rwlock; extern int g_num_records; diff --git a/include/records/P_RecDefs.h b/include/records/P_RecDefs.h index f4da85e75ab..6755494a97f 100644 --- a/include/records/P_RecDefs.h +++ b/include/records/P_RecDefs.h @@ -27,12 +27,10 @@ #define REC_MESSAGE_ELE_MAGIC 0xF00DF00D -// We need at least this many internal record entries for our configurations and metrics. Any -// additional slots in librecords will be allocated to the plugin metrics. These should be -// updated if we change the internal librecords size significantly. -#define REC_INTERNAL_RECORDS 1100 -#define REC_DEFAULT_API_RECORDS 1400 - +// We need at least this many internal record entries for our configurations and metrics. +// This may need adjustments if we make significant additions to librecords. Note that +// plugins are using their own metrics systems. +#define REC_MAX_RECORDS 1500 #define REC_CONFIG_UPDATE_INTERVAL_MS 3000 #define REC_REMOTE_SYNC_INTERVAL_MS 5000 diff --git a/plugins/experimental/remap_stats/remap_stats.cc b/plugins/experimental/remap_stats/remap_stats.cc index 71e2c628bd8..27924404e34 100644 --- a/plugins/experimental/remap_stats/remap_stats.cc +++ b/plugins/experimental/remap_stats/remap_stats.cc @@ -46,9 +46,6 @@ struct config_t { int txn_slot{-1}; }; -// From "core".... sigh, but we need it for now at least. -extern int max_records_entries; - namespace { void diff --git a/src/Makefile.am b/src/Makefile.am index 8e95c0c4a92..e6aaddec1dd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,7 +23,7 @@ TESTS = lib_LTLIBRARIES = noinst_PROGRAMS = -SUBDIRS = tscpp/api +SUBDIRS = tscpp/api api if BUILD_WCCP SUBDIRS += wccp diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt new file mode 100644 index 00000000000..b0f0bbc5d23 --- /dev/null +++ b/src/api/CMakeLists.txt @@ -0,0 +1,26 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# +####################### + +add_library(tsapi SHARED Metrics.cc) + +add_executable(test_Metrics + test_Metrics.cc + ) +target_link_libraries(test_Metrics PRIVATE tsapi tscore) +target_include_directories(test_Metrics PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR}) + +add_test(NAME test_Metrics COMMAND $) diff --git a/src/api/Makefile.am b/src/api/Makefile.am new file mode 100644 index 00000000000..993a68ee1b2 --- /dev/null +++ b/src/api/Makefile.am @@ -0,0 +1,38 @@ +# libts Makefile.am +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include $(top_srcdir)/mk/tidy.mk + +lib_LTLIBRARIES = libtsapi.la + +AM_CPPFLAGS += \ + @SWOC_INCLUDES@ \ + $(TS_INCLUDES) + +libtsapi_la_LDFLAGS = @AM_LDFLAGS@ -no-undefined -version-info @TS_LIBTOOL_VERSION@ @SWOC_LDFLAGS@ + +libtsapi_la_LIBADD = \ + $(top_builddir)/src/tscore/libtscore.la \ + @SWOC_LIBS@ + + +libtsapi_la_SOURCES = \ + Metrics.cc + +clang-tidy-local: $(DIST_SOURCES) + $(CXX_Clang_Tidy) diff --git a/src/api/Metrics.cc b/src/api/Metrics.cc new file mode 100644 index 00000000000..f45d7a36d3d --- /dev/null +++ b/src/api/Metrics.cc @@ -0,0 +1,140 @@ +/** @file + + The implementations of the Metrics API class. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "ts/ts.h" +#include "api/Metrics.h" + +namespace ts +{ + +// This is the singleton instance of the metrics class. +Metrics & +Metrics::getInstance() +{ + static ts::Metrics _instance; + + return _instance; +} + +void +Metrics::_addBlob() // The mutex must be held before calling this! +{ + auto blob = new Metrics::MetricStorage(); + + ink_assert(blob); + ink_assert(_cur_blob < Metrics::METRICS_MAX_BLOBS); + + _blobs[++_cur_blob] = blob; + _cur_off = 0; +} + +Metrics::IdType +Metrics::newMetric(std::string_view name) +{ + std::lock_guard lock(_mutex); + auto it = _lookups.find(name); + + if (it != _lookups.end()) { + return it->second; + } + + Metrics::IdType id = _makeId(_cur_blob, _cur_off); + Metrics::MetricStorage *blob = _blobs[_cur_blob]; + Metrics::NameContainer &names = std::get<0>(*blob); + Metrics::AtomicContainer &atomics = std::get<1>(*blob); + + atomics[_cur_off].store(0); + names[_cur_off] = std::make_tuple(std::string(name), id); + _lookups.emplace(std::get<0>(names[_cur_off]), id); + + if (++_cur_off >= Metrics::METRICS_MAX_SIZE) { + _addBlob(); // This resets _cur_off to 0 as well + } + + return id; +} + +Metrics::IdType +Metrics::lookup(const std::string_view name) const +{ + std::lock_guard lock(_mutex); + auto it = _lookups.find(name); + + if (it != _lookups.end()) { + return it->second; + } + + return NOT_FOUND; +} + +Metrics::AtomicType * +Metrics::lookup(IdType id, std::string_view *name) const +{ + auto [blob_ix, offset] = _splitID(id); + Metrics::MetricStorage *blob = _blobs[blob_ix]; + + // Do a sanity check on the ID, to make sure we don't index outside of the realm of possibility. + if (!blob || (blob_ix == _cur_blob && offset > _cur_off)) { + blob = _blobs[0]; + offset = 0; + } + + if (name) { + *name = std::get<0>(std::get<0>(*blob)[offset]); + } + + return &((std::get<1>(*blob)[offset])); +} + +std::string_view +Metrics::name(Metrics::IdType id) const +{ + auto [blob_ix, offset] = _splitID(id); + Metrics::MetricStorage *blob = _blobs[blob_ix]; + + // Do a sanity check on the ID, to make sure we don't index outside of the realm of possibility. + if (!blob || (blob_ix == _cur_blob && offset > _cur_off)) { + blob = _blobs[0]; + offset = 0; + } + + const std::string &result = std::get<0>(std::get<0>(*blob)[offset]); + + return result; +} + +// Iterator implementation +void +Metrics::iterator::next() +{ + auto [blob, offset] = _metrics._splitID(_it); + + if (++offset == METRICS_MAX_SIZE) { + ++blob; + offset = 0; + } + + _it = _makeId(blob, offset); +} + +} // namespace ts diff --git a/src/api/test_Metrics.cc b/src/api/test_Metrics.cc new file mode 100644 index 00000000000..d3713da0b31 --- /dev/null +++ b/src/api/test_Metrics.cc @@ -0,0 +1,75 @@ +/** @file + + TextView unit tests. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#define CATCH_CONFIG_MAIN +#include "catch.hpp" + +#include "api/Metrics.h" + +TEST_CASE("Metrics", "[libtsapi][Metrics]") +{ + ts::Metrics m; + + SECTION("iterator") + { + auto [name, value] = *m.begin(); + REQUIRE(value == 0); + REQUIRE(name == "proxy.node.bad_id.metrics"); + + REQUIRE(m.begin() != m.end()); + REQUIRE(++m.begin() == m.end()); + + auto it = m.begin(); + it++; + REQUIRE(it == m.end()); + } + + SECTION("New metric") + { + auto fooid = m.newMetric("foo"); + + REQUIRE(fooid == 1); + REQUIRE(m.get_name(fooid) == "foo"); + + REQUIRE(m.get(fooid) == 0); + m.increment(fooid); + REQUIRE(m.get(fooid) == 1); + } + + SECTION("operator[]") + { + m[0].store(42); + + REQUIRE(m.get(0) == 42); + } + + SECTION("dump") + { + m.recordsDump([](RecT, void *, int, const char *name, int value, RecData *) { printf("Fooo: %s: %d\n", name, value); }, + nullptr); + + for (auto [name, metric] : m) { + std::cout << name << ": " << metric << "\n"; + } + } +} diff --git a/src/records/RecCore.cc b/src/records/RecCore.cc index 8fa774aaddc..dca90bd1d1a 100644 --- a/src/records/RecCore.cc +++ b/src/records/RecCore.cc @@ -34,14 +34,11 @@ #include "records/P_RecUtils.h" #include "tscore/I_Layout.h" #include "tscpp/util/ts_errata.h" - -// This is needed to manage the size of the librecords record. It can't be static, because it needs to be modified -// and used (read) from several binaries / modules. -int max_records_entries = REC_INTERNAL_RECORDS + REC_DEFAULT_API_RECORDS; +#include "api/Metrics.h" static bool g_initialized = false; -RecRecord *g_records = nullptr; +RecRecord g_records[REC_MAX_RECORDS]; std::unordered_map g_records_ht; ink_rwlock g_records_rwlock; int g_num_records = 0; @@ -205,9 +202,6 @@ RecCoreInit(Diags *_diags) g_num_records = 0; - // initialize record array for our internal stats (this can be reallocated later) - g_records = static_cast(ats_malloc(max_records_entries * sizeof(RecRecord))); - // initialize record rwlock ink_rwlock_init(&g_records_rwlock); @@ -1062,6 +1056,15 @@ RecDumpRecords(RecT rec_type, RecDumpEntryCb callback, void *edata) rec_mutex_release(&(r->lock)); } } + // Also dump the new ts::Metrics if asked for + if (rec_type & TS_RECORDTYPE_PLUGIN) { + RecData datum; + + for (auto &&[name, val] : ts::Metrics::getInstance()) { + datum.rec_int = val; + callback(RECT_PLUGIN, edata, true, name.data(), TS_RECORDDATATYPE_INT, &datum); + } + } } void diff --git a/src/records/RecUtils.cc b/src/records/RecUtils.cc index e229a41f6f0..53f27afcbf9 100644 --- a/src/records/RecUtils.cc +++ b/src/records/RecUtils.cc @@ -50,8 +50,8 @@ RecRecordFree(RecRecord *r) RecRecord * RecAlloc(RecT rec_type, const char *name, RecDataT data_type) { - if (g_num_records >= max_records_entries) { - Warning("too many stats/configs, please increase max_records_entries using the --maxRecords command line option"); + if (g_num_records >= REC_MAX_RECORDS) { + Warning("too many stats/configs, please report a bug to dev@trafficserver.apache.org"); return nullptr; } diff --git a/src/traffic_crashlog/Makefile.inc b/src/traffic_crashlog/Makefile.inc index f7c69fe6d89..e73314ab6c4 100644 --- a/src/traffic_crashlog/Makefile.inc +++ b/src/traffic_crashlog/Makefile.inc @@ -41,4 +41,5 @@ traffic_crashlog_traffic_crashlog_LDADD = \ $(top_builddir)/iocore/net/libinknet.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/src/api/libtsapi.la \ @HWLOC_LIBS@ @SWOC_LIBS@ @YAMLCPP_LIBS@ @LIBPCRE@ @LIBCAP@ diff --git a/src/traffic_layout/Makefile.inc b/src/traffic_layout/Makefile.inc index 6f7409c9d02..d4f2637a900 100644 --- a/src/traffic_layout/Makefile.inc +++ b/src/traffic_layout/Makefile.inc @@ -45,4 +45,5 @@ traffic_layout_traffic_layout_LDADD = \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/src/api/libtsapi.la \ @SWOC_LIBS@ @HWLOC_LIBS@ @YAMLCPP_LIBS@ @LIBLZMA@ @LIBPCRE@ @LIBCAP@ diff --git a/src/traffic_logcat/Makefile.inc b/src/traffic_logcat/Makefile.inc index 44677d66f3a..f1962011ca4 100644 --- a/src/traffic_logcat/Makefile.inc +++ b/src/traffic_logcat/Makefile.inc @@ -46,6 +46,10 @@ traffic_logcat_traffic_logcat_LDADD = \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/mgmt/utils/libutils_p.la \ + $(top_builddir)/src/api/libtsapi.la + +traffic_logcat_traffic_logcat_LDADD += \ @SWOC_LIBS@ @HWLOC_LIBS@ \ @YAMLCPP_LIBS@ @LIBPCRE@ @OPENSSL_LIBS@ @LIBCAP@ \ @LIBPROFILER@ -lm diff --git a/src/traffic_logstats/Makefile.inc b/src/traffic_logstats/Makefile.inc index 3afd3960d88..2954189d6af 100644 --- a/src/traffic_logstats/Makefile.inc +++ b/src/traffic_logstats/Makefile.inc @@ -58,3 +58,11 @@ traffic_logstats_traffic_logstats_LDADD = \ @YAMLCPP_LIBS@ \ @LIBCAP@ \ @LIBPROFILER@ -lm + $(top_builddir)/mgmt/utils/libutils_p.la \ + $(top_builddir)/src/api/libtsapi.la + +traffic_logstats_traffic_logstats_LDADD += \ + @SWOC_LIBS@ \ + @HWLOC_LIBS@ \ + @YAMLCPP_LIBS@ \ + @LIBPROFILER@ -lm diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index a400fc3d361..3ad360b06aa 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -34,6 +34,7 @@ #include "tscore/I_Layout.h" #include "tscore/I_Version.h" #include "tscore/Diags.h" +#include "api/Metrics.h" #include "InkAPIInternal.h" #include "Log.h" @@ -102,10 +103,6 @@ extern AppVersionInfo appVersionInfo; -// Globals for new librecords stats -static int api_rsb_index; -static RecRawStatBlock *api_rsb; - /** Reservation for a user arg. */ struct UserArg { @@ -389,6 +386,7 @@ HttpAPIHooks *http_global_hooks = nullptr; SslAPIHooks *ssl_hooks = nullptr; LifecycleAPIHooks *lifecycle_hooks = nullptr; ConfigUpdateCbTable *global_config_cbs = nullptr; +static ts::Metrics &global_api_metrics = ts::Metrics::getInstance(); static char traffic_server_version[128] = ""; static int ts_major_version = 0; @@ -752,11 +750,7 @@ sdk_sanity_check_null_ptr(void const *ptr) static TSReturnCode sdk_sanity_check_stat_id(int id) { - if (id < 0 || id >= api_rsb->max_stats) { - return TS_ERROR; - } - - return TS_SUCCESS; + return (global_api_metrics.valid(id) ? TS_SUCCESS : TS_ERROR); } static TSReturnCode @@ -1829,18 +1823,6 @@ api_init() lifecycle_hooks = new LifecycleAPIHooks; global_config_cbs = new ConfigUpdateCbTable; - int api_metrics = max_records_entries - REC_INTERNAL_RECORDS; - if (api_metrics > 0) { - api_rsb = RecAllocateRawStatBlock(api_metrics); - if (nullptr == api_rsb) { - Warning("Can't allocate API stats block"); - } else { - Debug("sdk", "initialized SDK stats APIs with %d slots", api_metrics); - } - } else { - api_rsb = nullptr; - } - // Setup the version string for returning to plugins ink_strlcpy(traffic_server_version, appVersionInfo.VersionStr, sizeof(traffic_server_version)); // Extract the elements. @@ -7511,40 +7493,9 @@ TSCacheScan(TSCont contp, TSCacheKey key, int KB_per_second) int TSStatCreate(const char *the_name, TSRecordDataType the_type, TSStatPersistence persist, TSStatSync sync) { - int id = ink_atomic_increment(&api_rsb_index, 1); - RecRawStatSyncCb syncer = RecRawStatSyncCount; - - // TODO: This only supports "int" data types at this point, since the "Raw" stats - // interfaces only supports integers. Going forward, we could extend either the "Raw" - // stats APIs, or make non-int use the direct (synchronous) stats APIs (slower). - if ((sdk_sanity_check_null_ptr((void *)the_name) != TS_SUCCESS) || (sdk_sanity_check_null_ptr((void *)api_rsb) != TS_SUCCESS) || - (id >= api_rsb->max_stats)) { - return TS_ERROR; - } - - switch (sync) { - case TS_STAT_SYNC_SUM: - syncer = RecRawStatSyncSum; - break; - case TS_STAT_SYNC_AVG: - syncer = RecRawStatSyncAvg; - break; - case TS_STAT_SYNC_TIMEAVG: - syncer = RecRawStatSyncHrTimeAvg; - break; - default: - syncer = RecRawStatSyncCount; - break; - } + int id = global_api_metrics.newMetric(the_name); - switch (persist) { - case TS_STAT_PERSISTENT: - RecRegisterRawStat(api_rsb, RECT_PLUGIN, the_name, (RecDataT)the_type, RECP_PERSISTENT, id, syncer); - break; - case TS_STAT_NON_PERSISTENT: - RecRegisterRawStat(api_rsb, RECT_PLUGIN, the_name, (RecDataT)the_type, RECP_NON_PERSISTENT, id, syncer); - break; - default: + if (id == ts::Metrics::NOT_FOUND) { return TS_ERROR; } @@ -7555,49 +7506,44 @@ void TSStatIntIncrement(int id, TSMgmtInt amount) { sdk_assert(sdk_sanity_check_stat_id(id) == TS_SUCCESS); - RecIncrRawStat(api_rsb, nullptr, id, amount); + global_api_metrics[id].fetch_add(amount); } void TSStatIntDecrement(int id, TSMgmtInt amount) { - RecDecrRawStat(api_rsb, nullptr, id, amount); + sdk_assert(sdk_sanity_check_stat_id(id) == TS_SUCCESS); + global_api_metrics[id].fetch_sub(amount); } TSMgmtInt TSStatIntGet(int id) { - TSMgmtInt value; - sdk_assert(sdk_sanity_check_stat_id(id) == TS_SUCCESS); - RecGetGlobalRawStatSum(api_rsb, id, &value); - return value; + return global_api_metrics[id].load(); } void TSStatIntSet(int id, TSMgmtInt value) { sdk_assert(sdk_sanity_check_stat_id(id) == TS_SUCCESS); - RecSetGlobalRawStatSum(api_rsb, id, value); + global_api_metrics[id].store(value); } TSReturnCode TSStatFindName(const char *name, int *idp) { - int id; - sdk_assert(sdk_sanity_check_null_ptr((void *)name) == TS_SUCCESS); + sdk_assert(sdk_sanity_check_null_ptr((void *)idp) == TS_SUCCESS); - if (RecGetRecordOrderAndId(name, nullptr, &id, true, true) != REC_ERR_OKAY) { - return TS_ERROR; - } + int id = global_api_metrics.lookup(name); - if (RecGetGlobalRawStatPtr(api_rsb, id) == nullptr) { + if (id == ts::Metrics::NOT_FOUND) { return TS_ERROR; + } else { + *idp = id; + return TS_SUCCESS; } - - *idp = id; - return TS_SUCCESS; } /************************** Tracing API ****************************/ diff --git a/src/traffic_server/Makefile.inc b/src/traffic_server/Makefile.inc index 136c1a52aaf..52a4e14b3c7 100644 --- a/src/traffic_server/Makefile.inc +++ b/src/traffic_server/Makefile.inc @@ -78,6 +78,9 @@ traffic_server_traffic_server_LDADD = \ $(top_builddir)/iocore/cache/libinkcache.a \ $(top_builddir)/lib/fastlz/libfastlz.a \ $(top_builddir)/iocore/aio/libinkaio.a \ + $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/proxy/libproxy.a \ $(top_builddir)/iocore/net/libinknet.a \ $(top_builddir)/src/records/librecords_p.a \ diff --git a/src/traffic_server/traffic_server.cc b/src/traffic_server/traffic_server.cc index fd9a3635b08..cd52b915a77 100644 --- a/src/traffic_server/traffic_server.cc +++ b/src/traffic_server/traffic_server.cc @@ -207,8 +207,6 @@ static ArgumentDescription argument_descriptions[] = { {"disable_freelist", 'f', "Disable the freelist memory allocator", "T", &cmd_disable_freelist, "PROXY_DPRINTF_LEVEL", nullptr}, {"disable_pfreelist", 'F', "Disable the freelist memory allocator in ProxyAllocator", "T", &cmd_disable_pfreelist, "PROXY_DPRINTF_LEVEL", nullptr}, - {"maxRecords", 'm', "Max number of librecords metrics and configurations (default & minimum: 1600)", "I", &max_records_entries, - "PROXY_MAX_RECORDS", nullptr}, #if TS_HAS_TESTS {"regression", 'R', "Regression Level (quick:1..long:3)", "I", ®ression_level, "PROXY_REGRESSION", nullptr}, From 2fa498726ae0073971cf8080d49ccd4fe3183a9e Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 09:15:10 -0600 Subject: [PATCH 02/13] Fixes make check --- iocore/aio/Makefile.am | 1 + iocore/cache/Makefile.am | 2 ++ iocore/eventsystem/Makefile.am | 1 + iocore/hostdb/Makefile.am | 1 + iocore/net/Makefile.am | 15 ++++++++++++++- mgmt/rpc/Makefile.am | 1 + proxy/hdrs/Makefile.am | 3 +++ proxy/http/Makefile.am | 5 +++++ proxy/http/remap/Makefile.am | 15 +++++++++++++++ proxy/http2/Makefile.am | 1 + src/api/Makefile.am | 1 + src/api/Metrics.cc | 1 - src/records/Makefile.am | 2 ++ 13 files changed, 47 insertions(+), 2 deletions(-) diff --git a/iocore/aio/Makefile.am b/iocore/aio/Makefile.am index 0f767f235f1..f816f97298b 100644 --- a/iocore/aio/Makefile.am +++ b/iocore/aio/Makefile.am @@ -56,6 +56,7 @@ test_AIO_LDADD = \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ @SWOC_LIBS@ @HWLOC_LIBS@ @YAMLCPP_LIBS@ @LIBPCRE@ @LIBCAP@ diff --git a/iocore/cache/Makefile.am b/iocore/cache/Makefile.am index c021764d6e5..19d59681a7a 100644 --- a/iocore/cache/Makefile.am +++ b/iocore/cache/Makefile.am @@ -98,7 +98,9 @@ test_LDADD = \ $(top_builddir)/proxy/shared/libdiagsconfig.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/iocore/aio/libinkaio.a \ + $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/lib/fastlz/libfastlz.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ diff --git a/iocore/eventsystem/Makefile.am b/iocore/eventsystem/Makefile.am index bb7965b1675..082aac58fb6 100644 --- a/iocore/eventsystem/Makefile.am +++ b/iocore/eventsystem/Makefile.am @@ -97,6 +97,7 @@ test_LD_ADD = \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ @HWLOC_LIBS@ @SWOC_LIBS@ @YAMLCPP_LIBS@ @LIBPCRE@ @LIBCAP@ diff --git a/iocore/hostdb/Makefile.am b/iocore/hostdb/Makefile.am index 6db40ac3de1..87333102a73 100644 --- a/iocore/hostdb/Makefile.am +++ b/iocore/hostdb/Makefile.am @@ -67,6 +67,7 @@ test_LD_ADD = \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ @SWOC_LIBS@ @HWLOC_LIBS@ @YAMLCPP_LIBS@ @OPENSSL_LIBS@ @LIBPCRE@ @LIBCAP@ diff --git a/iocore/net/Makefile.am b/iocore/net/Makefile.am index 929dc79a864..9ffdcd9a583 100644 --- a/iocore/net/Makefile.am +++ b/iocore/net/Makefile.am @@ -52,7 +52,12 @@ test_certlookup_SOURCES = \ test_certlookup_LDADD = \ @OPENSSL_LIBS@ \ +<<<<<<< HEAD $(top_builddir)/src/tscore/libtscore.a $(top_builddir)/src/tscpp/util/libtscpputil.la \ +======= + $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/tscpp/util/libtscpputil.la \ +>>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/proxy/ParentSelectionStrategy.o \ @YAMLCPP_LIBS@ \ @@ -83,8 +88,11 @@ test_UDPNet_LDADD = \ libinknet.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ + $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/proxy/hdrs/libhdrs.a \ - $(top_builddir)/src/tscore/libtscore.a $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/src/tscore/libtscore.a + $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/proxy/ParentSelectionStrategy.o \ @HWLOC_LIBS@ @OPENSSL_LIBS@ @LIBPCRE@ @YAMLCPP_LIBS@ @SWOC_LIBS@ @LIBPCRE@ @LIBCAP@ if ENABLE_QUIC @@ -124,7 +132,12 @@ test_libinknet_LDADD = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/proxy/hdrs/libhdrs.a \ +<<<<<<< HEAD $(top_builddir)/src/tscore/libtscore.a \ +======= + $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/api/libtsapi.la \ +>>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/proxy/ParentSelectionStrategy.o \ @HWLOC_LIBS@ @OPENSSL_LIBS@ @LIBPCRE@ @YAMLCPP_LIBS@ @SWOC_LIBS@ @LIBCAP@ diff --git a/mgmt/rpc/Makefile.am b/mgmt/rpc/Makefile.am index 9ad923155e7..0b17bed31a5 100644 --- a/mgmt/rpc/Makefile.am +++ b/mgmt/rpc/Makefile.am @@ -104,6 +104,7 @@ test_jsonrpcserver_LDADD = \ libjsonrpc_protocol.la \ libjsonrpc_server.la \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ diff --git a/proxy/hdrs/Makefile.am b/proxy/hdrs/Makefile.am index 8b9cf9b9b2d..8e188bc9652 100644 --- a/proxy/hdrs/Makefile.am +++ b/proxy/hdrs/Makefile.am @@ -85,6 +85,7 @@ test_proxy_hdrs_SOURCES = \ test_proxy_hdrs_LDFLAGS = @AM_LDFLAGS@ @SWOC_LDFLAGS@ @YAMLCPP_LDFLAGS@ @OPENSSL_LDFLAGS@ test_proxy_hdrs_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ @@ -100,6 +101,8 @@ test_hdr_heap_SOURCES = \ test_hdr_heap_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ + $(top_builddir)/src/api/libtsapi.la \ + $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ diff --git a/proxy/http/Makefile.am b/proxy/http/Makefile.am index ae6493d87fa..25006d1b68e 100644 --- a/proxy/http/Makefile.am +++ b/proxy/http/Makefile.am @@ -104,6 +104,11 @@ test_proxy_http_SOURCES = \ HttpBodyFactory.h test_proxy_http_LDADD = \ +<<<<<<< HEAD +======= + $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/api/libtsapi.la \ +>>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/proxy/logging/liblogging.a \ $(top_builddir)/src/records/librecords_p.a \ diff --git a/proxy/http/remap/Makefile.am b/proxy/http/remap/Makefile.am index 3bb9da1ff34..7c65244e369 100644 --- a/proxy/http/remap/Makefile.am +++ b/proxy/http/remap/Makefile.am @@ -134,6 +134,11 @@ test_NextHopStrategyFactory_CPPFLAGS = \ @YAMLCPP_INCLUDES@ test_NextHopStrategyFactory_LDADD = \ +<<<<<<< HEAD +======= + $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/api/libtsapi.la \ +>>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ @@ -168,6 +173,11 @@ test_NextHopRoundRobin_CPPFLAGS = \ @YAMLCPP_INCLUDES@ test_NextHopRoundRobin_LDADD = \ +<<<<<<< HEAD +======= + $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/api/libtsapi.la \ +>>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ @@ -202,6 +212,11 @@ test_NextHopConsistentHash_CPPFLAGS = \ @YAMLCPP_INCLUDES@ test_NextHopConsistentHash_LDADD = \ +<<<<<<< HEAD +======= + $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/api/libtsapi.la \ +>>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ diff --git a/proxy/http2/Makefile.am b/proxy/http2/Makefile.am index 02ed791f32e..b9575093d77 100644 --- a/proxy/http2/Makefile.am +++ b/proxy/http2/Makefile.am @@ -125,6 +125,7 @@ test_Http2FrequencyCounter_SOURCES = \ test_HPACK_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ diff --git a/src/api/Makefile.am b/src/api/Makefile.am index 993a68ee1b2..5998822d8e8 100644 --- a/src/api/Makefile.am +++ b/src/api/Makefile.am @@ -21,6 +21,7 @@ include $(top_srcdir)/mk/tidy.mk lib_LTLIBRARIES = libtsapi.la AM_CPPFLAGS += \ + -I$(abs_top_srcdir)/include \ @SWOC_INCLUDES@ \ $(TS_INCLUDES) diff --git a/src/api/Metrics.cc b/src/api/Metrics.cc index f45d7a36d3d..1d38e04ea2f 100644 --- a/src/api/Metrics.cc +++ b/src/api/Metrics.cc @@ -21,7 +21,6 @@ limitations under the License. */ -#include "ts/ts.h" #include "api/Metrics.h" namespace ts diff --git a/src/records/Makefile.am b/src/records/Makefile.am index c2188a73bdb..62325ea907d 100644 --- a/src/records/Makefile.am +++ b/src/records/Makefile.am @@ -72,6 +72,7 @@ test_librecords_LDADD = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ @SWOC_LIBS@ @HWLOC_LIBS@ @LIBCAP@ @YAMLCPP_LIBS@ @LIBPCRE@ @OPENSSL_LIBS@ test_librecords_on_eventsystem_CPPFLAGS = $(AM_CPPFLAGS)\ @@ -86,6 +87,7 @@ test_librecords_on_eventsystem_LDADD = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ @HWLOC_LIBS@ @LIBCAP@ @YAMLCPP_LIBS@ @SWOC_LIBS@ @LIBPCRE@ @OPENSSL_LIBS@ clang-tidy-local: $(sort $(DIST_SOURCES)) From 76bc3f1b76d8a6b7178e815471d71f025af7c9ce Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 11:09:59 -0600 Subject: [PATCH 03/13] Fixes type mismatch, shouldn't use apidefs.h symbols --- include/api/Metrics.h | 2 +- iocore/cache/Makefile.am | 1 - src/records/RecCore.cc | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/api/Metrics.h b/include/api/Metrics.h index 733c815bb62..10f8143d5a9 100644 --- a/include/api/Metrics.h +++ b/include/api/Metrics.h @@ -122,7 +122,7 @@ class Metrics { public: using iterator_category = std::input_iterator_tag; - using value_type = std::tuple; + using value_type = std::tuple; using difference_type = ptrdiff_t; using pointer = value_type *; using reference = value_type &; diff --git a/iocore/cache/Makefile.am b/iocore/cache/Makefile.am index 19d59681a7a..34e65c2bbc3 100644 --- a/iocore/cache/Makefile.am +++ b/iocore/cache/Makefile.am @@ -98,7 +98,6 @@ test_LDADD = \ $(top_builddir)/proxy/shared/libdiagsconfig.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/iocore/aio/libinkaio.a \ - $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscore/libtscore.a \ diff --git a/src/records/RecCore.cc b/src/records/RecCore.cc index dca90bd1d1a..1d50554c4da 100644 --- a/src/records/RecCore.cc +++ b/src/records/RecCore.cc @@ -1057,7 +1057,7 @@ RecDumpRecords(RecT rec_type, RecDumpEntryCb callback, void *edata) } } // Also dump the new ts::Metrics if asked for - if (rec_type & TS_RECORDTYPE_PLUGIN) { + if (rec_type & RECT_PLUGIN) { RecData datum; for (auto &&[name, val] : ts::Metrics::getInstance()) { From c467b6e114a3400205dbbe79d680b1f556d3db8c Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 13:00:56 -0600 Subject: [PATCH 04/13] More Makefile fixes --- mgmt/rpc/Makefile.am | 2 +- proxy/hdrs/Makefile.am | 3 --- proxy/http/Makefile.am | 8 +++----- proxy/http/remap/Makefile.am | 17 +++++++++++++---- proxy/http2/Makefile.am | 5 ++++- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/mgmt/rpc/Makefile.am b/mgmt/rpc/Makefile.am index 0b17bed31a5..682c5708bae 100644 --- a/mgmt/rpc/Makefile.am +++ b/mgmt/rpc/Makefile.am @@ -103,10 +103,10 @@ test_jsonrpcserver_SOURCES = \ test_jsonrpcserver_LDADD = \ libjsonrpc_protocol.la \ libjsonrpc_server.la \ - $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/src/tscore/libtscore.a \ @YAMLCPP_LIBS@ @HWLOC_LIBS@ @SWOC_LIBS@ @YAMLCPP_LIBS@ @LIBPCRE@ @LIBCAP@ diff --git a/proxy/hdrs/Makefile.am b/proxy/hdrs/Makefile.am index 8e188bc9652..8b9cf9b9b2d 100644 --- a/proxy/hdrs/Makefile.am +++ b/proxy/hdrs/Makefile.am @@ -85,7 +85,6 @@ test_proxy_hdrs_SOURCES = \ test_proxy_hdrs_LDFLAGS = @AM_LDFLAGS@ @SWOC_LDFLAGS@ @YAMLCPP_LDFLAGS@ @OPENSSL_LDFLAGS@ test_proxy_hdrs_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ - $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ @@ -101,8 +100,6 @@ test_hdr_heap_SOURCES = \ test_hdr_heap_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ - $(top_builddir)/src/api/libtsapi.la \ - $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ diff --git a/proxy/http/Makefile.am b/proxy/http/Makefile.am index 25006d1b68e..5f1debf3662 100644 --- a/proxy/http/Makefile.am +++ b/proxy/http/Makefile.am @@ -104,17 +104,14 @@ test_proxy_http_SOURCES = \ HttpBodyFactory.h test_proxy_http_LDADD = \ -<<<<<<< HEAD -======= - $(top_builddir)/src/tscore/libtscore.la \ - $(top_builddir)/src/api/libtsapi.la \ ->>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/proxy/logging/liblogging.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ @SWOC_LIBS@ @HWLOC_LIBS@ \ @LIBCAP@ \ @@ -163,6 +160,7 @@ test_HttpTransact_LDADD = \ $(top_builddir)/iocore/net/libinknet.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ -lz -llzma -lcrypto -lresolv -lssl \ @LIBPCRE@ @HWLOC_LIBS@ @SWOC_LIBS@ @YAMLCPP_LIBS@ @LIBCAP@ diff --git a/proxy/http/remap/Makefile.am b/proxy/http/remap/Makefile.am index 7c65244e369..0c020a7e371 100644 --- a/proxy/http/remap/Makefile.am +++ b/proxy/http/remap/Makefile.am @@ -134,14 +134,15 @@ test_NextHopStrategyFactory_CPPFLAGS = \ @YAMLCPP_INCLUDES@ test_NextHopStrategyFactory_LDADD = \ -<<<<<<< HEAD -======= - $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/src/api/libtsapi.la \ ->>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/proxy/hdrs/libhdrs.a \ + $(top_builddir)/iocore/eventsystem/libinkevent.a \ + $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ + $(top_builddir)/proxy/logging/liblogging.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/proxy/logging/liblogging.a \ @@ -176,11 +177,15 @@ test_NextHopRoundRobin_LDADD = \ <<<<<<< HEAD ======= $(top_builddir)/src/tscore/libtscore.la \ +<<<<<<< HEAD $(top_builddir)/src/api/libtsapi.la \ >>>>>>> b6a133f27 (Fixes make check) +======= +>>>>>>> b2c0a316d (More Makefile fixes) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/proxy/logging/liblogging.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ @@ -215,11 +220,15 @@ test_NextHopConsistentHash_LDADD = \ <<<<<<< HEAD ======= $(top_builddir)/src/tscore/libtscore.la \ +<<<<<<< HEAD $(top_builddir)/src/api/libtsapi.la \ >>>>>>> b6a133f27 (Fixes make check) +======= +>>>>>>> b2c0a316d (More Makefile fixes) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/proxy/logging/liblogging.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ diff --git a/proxy/http2/Makefile.am b/proxy/http2/Makefile.am index b9575093d77..fd042f12db8 100644 --- a/proxy/http2/Makefile.am +++ b/proxy/http2/Makefile.am @@ -72,6 +72,7 @@ test_libhttp2_LDADD = \ Http2Frame.o \ HPACK.o \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ @@ -125,11 +126,13 @@ test_Http2FrequencyCounter_SOURCES = \ test_HPACK_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ - $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/iocore/eventsystem/libinkevent.a \ + $(top_builddir)/src/api/libtsapi.la \ @SWOC_LIBS@ @HWLOC_LIBS@ @LIBPCRE@ @OPENSSL_LIBS@ @YAMLCPP_LIBS@ @LIBCAP@ test_HPACK_SOURCES = \ From b3ee523add910575d424373f3a7af2862a44a080 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 13:16:48 -0600 Subject: [PATCH 05/13] Adds missing include files --- include/api/Metrics.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/api/Metrics.h b/include/api/Metrics.h index 10f8143d5a9..17b1fd01fe5 100644 --- a/include/api/Metrics.h +++ b/include/api/Metrics.h @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include "tscore/ink_assert.h" From 4eec9eb842f7bb82224eb81bd5c417823a48df7b Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 13:33:23 -0600 Subject: [PATCH 06/13] Updates the regression tests, adds to Makefile --- .gitignore | 1 + src/api/Makefile.am | 12 ++++++++++++ src/api/test_Metrics.cc | 20 +++++--------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index a4983d434be..c288e1470ea 100644 --- a/.gitignore +++ b/.gitignore @@ -102,6 +102,7 @@ src/tscore/test_tscore src/tscpp/util/test_tscpputil src/records/test_librecords src/records/test_librecords_on_eventsystem +src/api/test_Metrics lib/perl/lib/Apache/TS.pm iocore/net/test_certlookup diff --git a/src/api/Makefile.am b/src/api/Makefile.am index 5998822d8e8..21f96d04317 100644 --- a/src/api/Makefile.am +++ b/src/api/Makefile.am @@ -18,6 +18,10 @@ include $(top_srcdir)/mk/tidy.mk +check_PROGRAMS = test_Metrics + +TESTS = $(check_PROGRAMS) + lib_LTLIBRARIES = libtsapi.la AM_CPPFLAGS += \ @@ -35,5 +39,13 @@ libtsapi_la_LIBADD = \ libtsapi_la_SOURCES = \ Metrics.cc +test_Metrics_SOURCES = test_Metrics.cc + +test_Metrics_CPPFLAGS = $(AM_CPPFLAGS)\ + -I$(abs_top_srcdir)/lib/catch2 + +test_Metrics_LDADD = libtsapi.la + + clang-tidy-local: $(DIST_SOURCES) $(CXX_Clang_Tidy) diff --git a/src/api/test_Metrics.cc b/src/api/test_Metrics.cc index d3713da0b31..6556754c845 100644 --- a/src/api/test_Metrics.cc +++ b/src/api/test_Metrics.cc @@ -34,7 +34,7 @@ TEST_CASE("Metrics", "[libtsapi][Metrics]") { auto [name, value] = *m.begin(); REQUIRE(value == 0); - REQUIRE(name == "proxy.node.bad_id.metrics"); + REQUIRE(name == "proxy.node.api.metrics.bad_id"); REQUIRE(m.begin() != m.end()); REQUIRE(++m.begin() == m.end()); @@ -49,27 +49,17 @@ TEST_CASE("Metrics", "[libtsapi][Metrics]") auto fooid = m.newMetric("foo"); REQUIRE(fooid == 1); - REQUIRE(m.get_name(fooid) == "foo"); + REQUIRE(m.name(fooid) == "foo"); - REQUIRE(m.get(fooid) == 0); + REQUIRE(m[fooid].load() == 0); m.increment(fooid); - REQUIRE(m.get(fooid) == 1); + REQUIRE(m[fooid].load() == 1); } SECTION("operator[]") { m[0].store(42); - REQUIRE(m.get(0) == 42); - } - - SECTION("dump") - { - m.recordsDump([](RecT, void *, int, const char *name, int value, RecData *) { printf("Fooo: %s: %d\n", name, value); }, - nullptr); - - for (auto [name, metric] : m) { - std::cout << name << ": " << metric << "\n"; - } + REQUIRE(m[0].load() == 42); } } From a6c547e269c4de8fc0d071163872e443eb3e2a1d Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 13:50:01 -0600 Subject: [PATCH 07/13] Fixes install CMake targets --- src/api/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index b0f0bbc5d23..d8a695176bd 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -16,6 +16,10 @@ ####################### add_library(tsapi SHARED Metrics.cc) +add_library(ts::tsapi ALIAS tsapi) + +install(TARGETS tsapi) + add_executable(test_Metrics test_Metrics.cc From 09aad38aae5e1e50d1d9248095f9321e686089c5 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 14:45:11 -0600 Subject: [PATCH 08/13] Fix the expensive checks --- proxy/http/remap/Makefile.am | 1 + src/api/Makefile.am | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/proxy/http/remap/Makefile.am b/proxy/http/remap/Makefile.am index 0c020a7e371..ad5aa7b8d07 100644 --- a/proxy/http/remap/Makefile.am +++ b/proxy/http/remap/Makefile.am @@ -68,6 +68,7 @@ libhttp_remap_a_SOURCES = \ COMMON_PLUGINDSO_LDADDS = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ diff --git a/src/api/Makefile.am b/src/api/Makefile.am index 21f96d04317..4e8d1daf55f 100644 --- a/src/api/Makefile.am +++ b/src/api/Makefile.am @@ -32,7 +32,7 @@ AM_CPPFLAGS += \ libtsapi_la_LDFLAGS = @AM_LDFLAGS@ -no-undefined -version-info @TS_LIBTOOL_VERSION@ @SWOC_LDFLAGS@ libtsapi_la_LIBADD = \ - $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/tscore/libtscore.la \ @SWOC_LIBS@ @@ -44,7 +44,9 @@ test_Metrics_SOURCES = test_Metrics.cc test_Metrics_CPPFLAGS = $(AM_CPPFLAGS)\ -I$(abs_top_srcdir)/lib/catch2 -test_Metrics_LDADD = libtsapi.la +test_Metrics_LDADD = \ + $(top_builddir)/src/tscore/libtscore.la \ + libtsapi.la clang-tidy-local: $(DIST_SOURCES) From 7094c7b77bc4217eac670154ea923ed7e81f961c Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 15:38:31 -0600 Subject: [PATCH 09/13] Fixes for H3 and HPACK --- proxy/http3/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/proxy/http3/Makefile.am b/proxy/http3/Makefile.am index 7abeebccf6a..34497dd1259 100644 --- a/proxy/http3/Makefile.am +++ b/proxy/http3/Makefile.am @@ -72,6 +72,7 @@ test_LDADD = \ $(top_builddir)/iocore/net/TLSKeyLogger.o \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/src/tscore/libtscore.a \ From c73bed81df9d027be1f71ee4a54d692af6027cdc Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 11 Jul 2023 17:45:01 -0600 Subject: [PATCH 10/13] Adds API metrics supports for the RecCore matchers --- include/api/Metrics.h | 12 ++++ iocore/net/Makefile.am | 17 ++---- mgmt/rpc/Makefile.am | 2 +- proxy/http/Makefile.am | 1 - proxy/http/remap/Makefile.am | 22 +------- proxy/http2/Makefile.am | 2 - .../logging/unit-tests/benchmark_LogObject.cc | 2 +- src/api/Makefile.am | 4 +- src/records/RecCore.cc | 56 ++++++++++++++----- src/traffic_logcat/Makefile.inc | 5 +- src/traffic_logstats/Makefile.inc | 13 +---- src/traffic_server/Makefile.inc | 2 - 12 files changed, 68 insertions(+), 70 deletions(-) diff --git a/include/api/Metrics.h b/include/api/Metrics.h index 17b1fd01fe5..6b79f43eb3a 100644 --- a/include/api/Metrics.h +++ b/include/api/Metrics.h @@ -194,6 +194,18 @@ class Metrics return iterator(*this, _makeId(blob, offset)); } + iterator + find(const std::string_view name) const + { + auto id = lookup(name); + + if (id == NOT_FOUND) { + return end(); + } else { + return iterator(*this, id); + } + } + private: static constexpr std::tuple _splitID(IdType value) diff --git a/iocore/net/Makefile.am b/iocore/net/Makefile.am index 9ffdcd9a583..b4c0c3895ea 100644 --- a/iocore/net/Makefile.am +++ b/iocore/net/Makefile.am @@ -51,17 +51,13 @@ test_certlookup_SOURCES = \ SSLCertLookup.cc test_certlookup_LDADD = \ - @OPENSSL_LIBS@ \ -<<<<<<< HEAD - $(top_builddir)/src/tscore/libtscore.a $(top_builddir)/src/tscpp/util/libtscpputil.la \ -======= - $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ ->>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/proxy/ParentSelectionStrategy.o \ @YAMLCPP_LIBS@ \ @SWOC_LIBS@ \ + @OPENSSL_LIBS@ \ @LIBPCRE@ \ @LIBCAP@ @@ -88,11 +84,10 @@ test_UDPNet_LDADD = \ libinknet.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ - $(top_builddir)/src/api/libtsapi.la \ - $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/proxy/hdrs/libhdrs.a \ - $(top_builddir)/src/tscore/libtscore.a + $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/proxy/ParentSelectionStrategy.o \ @HWLOC_LIBS@ @OPENSSL_LIBS@ @LIBPCRE@ @YAMLCPP_LIBS@ @SWOC_LIBS@ @LIBPCRE@ @LIBCAP@ if ENABLE_QUIC @@ -132,12 +127,8 @@ test_libinknet_LDADD = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/proxy/hdrs/libhdrs.a \ -<<<<<<< HEAD $(top_builddir)/src/tscore/libtscore.a \ -======= - $(top_builddir)/src/tscore/libtscore.la \ $(top_builddir)/src/api/libtsapi.la \ ->>>>>>> b6a133f27 (Fixes make check) $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/proxy/ParentSelectionStrategy.o \ @HWLOC_LIBS@ @OPENSSL_LIBS@ @LIBPCRE@ @YAMLCPP_LIBS@ @SWOC_LIBS@ @LIBCAP@ diff --git a/mgmt/rpc/Makefile.am b/mgmt/rpc/Makefile.am index 682c5708bae..7fe8c015d2a 100644 --- a/mgmt/rpc/Makefile.am +++ b/mgmt/rpc/Makefile.am @@ -103,7 +103,7 @@ test_jsonrpcserver_SOURCES = \ test_jsonrpcserver_LDADD = \ libjsonrpc_protocol.la \ libjsonrpc_server.la \ - $(top_builddir)/src/api/libtsapi.la \ + $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/api/libtsapi.la \ diff --git a/proxy/http/Makefile.am b/proxy/http/Makefile.am index 5f1debf3662..1184ff21be5 100644 --- a/proxy/http/Makefile.am +++ b/proxy/http/Makefile.am @@ -107,7 +107,6 @@ test_proxy_http_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/proxy/logging/liblogging.a \ $(top_builddir)/src/records/librecords_p.a \ - $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ diff --git a/proxy/http/remap/Makefile.am b/proxy/http/remap/Makefile.am index ad5aa7b8d07..2a57bb43c2f 100644 --- a/proxy/http/remap/Makefile.am +++ b/proxy/http/remap/Makefile.am @@ -139,11 +139,6 @@ test_NextHopStrategyFactory_LDADD = \ $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ - $(top_builddir)/proxy/hdrs/libhdrs.a \ - $(top_builddir)/iocore/eventsystem/libinkevent.a \ - $(top_builddir)/src/records/librecords_p.a \ - $(top_builddir)/src/api/libtsapi.la \ - $(top_builddir)/proxy/logging/liblogging.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/proxy/logging/liblogging.a \ @@ -175,14 +170,6 @@ test_NextHopRoundRobin_CPPFLAGS = \ @YAMLCPP_INCLUDES@ test_NextHopRoundRobin_LDADD = \ -<<<<<<< HEAD -======= - $(top_builddir)/src/tscore/libtscore.la \ -<<<<<<< HEAD - $(top_builddir)/src/api/libtsapi.la \ ->>>>>>> b6a133f27 (Fixes make check) -======= ->>>>>>> b2c0a316d (More Makefile fixes) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ @@ -218,14 +205,6 @@ test_NextHopConsistentHash_CPPFLAGS = \ @YAMLCPP_INCLUDES@ test_NextHopConsistentHash_LDADD = \ -<<<<<<< HEAD -======= - $(top_builddir)/src/tscore/libtscore.la \ -<<<<<<< HEAD - $(top_builddir)/src/api/libtsapi.la \ ->>>>>>> b6a133f27 (Fixes make check) -======= ->>>>>>> b2c0a316d (More Makefile fixes) $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ @@ -272,6 +251,7 @@ pkglib_LTLIBRARIES = \ unit-tests/plugin_missing_init.la \ unit-tests/plugin_missing_newinstance.la \ unit-tests/plugin_testing_calls.la + unit_tests_plugin_v1_la_SOURCES = unit-tests/plugin_misc_cb.cc unit_tests_plugin_v1_la_LDFLAGS = $(DSO_LDFLAGS) unit_tests_plugin_v1_la_CPPFLAGS = -DPLUGINDSOVER=1 $(AM_CPPFLAGS) diff --git a/proxy/http2/Makefile.am b/proxy/http2/Makefile.am index fd042f12db8..6d385fd82f6 100644 --- a/proxy/http2/Makefile.am +++ b/proxy/http2/Makefile.am @@ -130,8 +130,6 @@ test_HPACK_LDADD = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ - $(top_builddir)/src/tscpp/util/libtscpputil.la \ - $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/api/libtsapi.la \ @SWOC_LIBS@ @HWLOC_LIBS@ @LIBPCRE@ @OPENSSL_LIBS@ @YAMLCPP_LIBS@ @LIBCAP@ diff --git a/proxy/logging/unit-tests/benchmark_LogObject.cc b/proxy/logging/unit-tests/benchmark_LogObject.cc index 3db7020a078..6735c1b2e2d 100644 --- a/proxy/logging/unit-tests/benchmark_LogObject.cc +++ b/proxy/logging/unit-tests/benchmark_LogObject.cc @@ -31,7 +31,7 @@ benchmark_LogObject_CPPFLAGS = \ $(AM_CPPFLAGS) \ -I$(abs_top_srcdir)/tests/include benchmark_LogObject_LDADD = \ - $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/proxy/logging/liblogging.a \ diff --git a/src/api/Makefile.am b/src/api/Makefile.am index 4e8d1daf55f..2aca36f8ff5 100644 --- a/src/api/Makefile.am +++ b/src/api/Makefile.am @@ -32,7 +32,7 @@ AM_CPPFLAGS += \ libtsapi_la_LDFLAGS = @AM_LDFLAGS@ -no-undefined -version-info @TS_LIBTOOL_VERSION@ @SWOC_LDFLAGS@ libtsapi_la_LIBADD = \ - $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/tscore/libtscore.a \ @SWOC_LIBS@ @@ -45,7 +45,7 @@ test_Metrics_CPPFLAGS = $(AM_CPPFLAGS)\ -I$(abs_top_srcdir)/lib/catch2 test_Metrics_LDADD = \ - $(top_builddir)/src/tscore/libtscore.la \ + $(top_builddir)/src/tscore/libtscore.a \ libtsapi.la diff --git a/src/records/RecCore.cc b/src/records/RecCore.cc index 1d50554c4da..54e0b93aa51 100644 --- a/src/records/RecCore.cc +++ b/src/records/RecCore.cc @@ -482,23 +482,38 @@ RecGetRecordBool(const char *name, RecBool *rec_bool, bool lock) RecErrT RecLookupRecord(const char *name, void (*callback)(const RecRecord *, void *), void *data, bool lock) { - RecErrT err = REC_ERR_FAIL; + RecErrT err = REC_ERR_FAIL; + ts::Metrics &api_metrics = ts::Metrics::getInstance(); + auto it = api_metrics.find(name); - if (lock) { - ink_rwlock_rdlock(&g_records_rwlock); - } + if (it != api_metrics.end()) { + RecRecord r; + auto &&[name, val] = *it; - if (auto it = g_records_ht.find(name); it != g_records_ht.end()) { - RecRecord *r = it->second; + r.rec_type = RECT_PLUGIN; + r.data_type = RECD_INT; + r.name = name.data(); + r.data.rec_int = val; - rec_mutex_acquire(&(r->lock)); - callback(r, data); + callback(&r, data); err = REC_ERR_OKAY; - rec_mutex_release(&(r->lock)); - } + } else { + if (lock) { + ink_rwlock_rdlock(&g_records_rwlock); + } - if (lock) { - ink_rwlock_unlock(&g_records_rwlock); + if (auto it = g_records_ht.find(name); it != g_records_ht.end()) { + RecRecord *r = it->second; + + rec_mutex_acquire(&(r->lock)); + callback(r, data); + err = REC_ERR_OKAY; + rec_mutex_release(&(r->lock)); + } + + if (lock) { + ink_rwlock_unlock(&g_records_rwlock); + } } return err; @@ -514,6 +529,21 @@ RecLookupMatchingRecords(unsigned rec_type, const char *match, void (*callback)( return REC_ERR_FAIL; } + if (rec_type & RECT_PLUGIN) { // ToDo: This should change if we use the new metrics for core metrics + RecRecord r; + + r.rec_type = RECT_PLUGIN; + r.data_type = RECD_INT; + + for (auto &&[name, val] : ts::Metrics::getInstance()) { + if (regex.match(name.data()) >= 0) { + r.name = name.data(); + r.data.rec_int = val; + callback(&r, data); + } + } + } + num_records = g_num_records; for (int i = 0; i < num_records; i++) { RecRecord *r = &(g_records[i]); @@ -1057,7 +1087,7 @@ RecDumpRecords(RecT rec_type, RecDumpEntryCb callback, void *edata) } } // Also dump the new ts::Metrics if asked for - if (rec_type & RECT_PLUGIN) { + if (rec_type & RECT_PLUGIN) { // ToDo: This should change if we use the new metrics for core metrics RecData datum; for (auto &&[name, val] : ts::Metrics::getInstance()) { diff --git a/src/traffic_logcat/Makefile.inc b/src/traffic_logcat/Makefile.inc index f1962011ca4..199c851b1f9 100644 --- a/src/traffic_logcat/Makefile.inc +++ b/src/traffic_logcat/Makefile.inc @@ -46,10 +46,7 @@ traffic_logcat_traffic_logcat_LDADD = \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ - $(top_builddir)/mgmt/utils/libutils_p.la \ - $(top_builddir)/src/api/libtsapi.la - -traffic_logcat_traffic_logcat_LDADD += \ + $(top_builddir)/src/api/libtsapi.la \ @SWOC_LIBS@ @HWLOC_LIBS@ \ @YAMLCPP_LIBS@ @LIBPCRE@ @OPENSSL_LIBS@ @LIBCAP@ \ @LIBPROFILER@ -lm diff --git a/src/traffic_logstats/Makefile.inc b/src/traffic_logstats/Makefile.inc index 2954189d6af..f446f49735d 100644 --- a/src/traffic_logstats/Makefile.inc +++ b/src/traffic_logstats/Makefile.inc @@ -50,19 +50,12 @@ traffic_logstats_traffic_logstats_LDADD = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ + @OPENSSL_LIBS@ \ @SWOC_LIBS@ \ @HWLOC_LIBS@ \ - @OPENSSL_LIBS@ \ + @LIBCAP@ \ @LIBPCRE@ \ @YAMLCPP_LIBS@ \ - @LIBCAP@ \ @LIBPROFILER@ -lm - $(top_builddir)/mgmt/utils/libutils_p.la \ - $(top_builddir)/src/api/libtsapi.la - -traffic_logstats_traffic_logstats_LDADD += \ - @SWOC_LIBS@ \ - @HWLOC_LIBS@ \ - @YAMLCPP_LIBS@ \ - @LIBPROFILER@ -lm diff --git a/src/traffic_server/Makefile.inc b/src/traffic_server/Makefile.inc index 52a4e14b3c7..4926ce79e68 100644 --- a/src/traffic_server/Makefile.inc +++ b/src/traffic_server/Makefile.inc @@ -78,8 +78,6 @@ traffic_server_traffic_server_LDADD = \ $(top_builddir)/iocore/cache/libinkcache.a \ $(top_builddir)/lib/fastlz/libfastlz.a \ $(top_builddir)/iocore/aio/libinkaio.a \ - $(top_builddir)/src/tscore/libtscore.a \ - $(top_builddir)/src/tscpp/util/libtscpputil.la \ $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/proxy/libproxy.a \ $(top_builddir)/iocore/net/libinknet.a \ From c951738ffecaf14aec5916418564d5fe8fe59451 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Mon, 17 Jul 2023 16:33:18 -0600 Subject: [PATCH 11/13] Trying to fix some build concerns --- proxy/http/remap/Makefile.am | 2 +- proxy/http/unit_tests/CMakeLists.txt | 1 + src/api/CMakeLists.txt | 3 +++ src/tests/CMakeLists.txt | 2 ++ src/traffic_crashlog/CMakeLists.txt | 1 + src/traffic_layout/CMakeLists.txt | 4 ++++ src/traffic_server/CMakeLists.txt | 1 + src/tscore/Makefile.am | 1 + 8 files changed, 14 insertions(+), 1 deletion(-) diff --git a/proxy/http/remap/Makefile.am b/proxy/http/remap/Makefile.am index 2a57bb43c2f..e61c0aeb4d5 100644 --- a/proxy/http/remap/Makefile.am +++ b/proxy/http/remap/Makefile.am @@ -135,10 +135,10 @@ test_NextHopStrategyFactory_CPPFLAGS = \ @YAMLCPP_INCLUDES@ test_NextHopStrategyFactory_LDADD = \ - $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/proxy/hdrs/libhdrs.a \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/iocore/utils/libinkutils.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/proxy/logging/liblogging.a \ diff --git a/proxy/http/unit_tests/CMakeLists.txt b/proxy/http/unit_tests/CMakeLists.txt index 64cc7d3d1bf..1f9ef16c43b 100644 --- a/proxy/http/unit_tests/CMakeLists.txt +++ b/proxy/http/unit_tests/CMakeLists.txt @@ -35,6 +35,7 @@ target_link_libraries(test_http PRIVATE catch2::catch2 ts::http + ts::tsapi ts::hdrs # transitive logging # transitive http_remap # transitive diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index d8a695176bd..57526a5e1bc 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -24,6 +24,9 @@ install(TARGETS tsapi) add_executable(test_Metrics test_Metrics.cc ) + +target_link_libraries(tsapi PUBLIC ts::tscore) + target_link_libraries(test_Metrics PRIVATE tsapi tscore) target_include_directories(test_Metrics PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR}) diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 3e59226c697..6ba08015e3a 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -46,7 +46,9 @@ link_libraries( inkcache fastlz aio + records tscore + tsapi tscpputil proxy inknet diff --git a/src/traffic_crashlog/CMakeLists.txt b/src/traffic_crashlog/CMakeLists.txt index 3f43c20ba66..13df48df1b0 100644 --- a/src/traffic_crashlog/CMakeLists.txt +++ b/src/traffic_crashlog/CMakeLists.txt @@ -22,6 +22,7 @@ target_link_libraries(traffic_crashlog ts::inkevent ts::records ts::tscore + ts::tsapi ) install(TARGETS traffic_crashlog) diff --git a/src/traffic_layout/CMakeLists.txt b/src/traffic_layout/CMakeLists.txt index e898d65cbab..7a02a6a5075 100644 --- a/src/traffic_layout/CMakeLists.txt +++ b/src/traffic_layout/CMakeLists.txt @@ -28,6 +28,10 @@ target_link_libraries(traffic_layout ts::records OpenSSL::Crypto yaml-cpp::yaml-cpp + ts::tscore + ts::tsapi + PCRE::PCRE + ${OPENSSL_LIBRARY} ) if(TS_USE_HWLOC) diff --git a/src/traffic_server/CMakeLists.txt b/src/traffic_server/CMakeLists.txt index 390c8edefd3..35325b90266 100644 --- a/src/traffic_server/CMakeLists.txt +++ b/src/traffic_server/CMakeLists.txt @@ -35,6 +35,7 @@ target_include_directories(traffic_server PRIVATE target_link_libraries(traffic_server PRIVATE ts::tscore + ts::tsapi ts::http ts::http_remap ts::http2 diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am index 8ab634398a0..1308d8e03d0 100644 --- a/src/tscore/Makefile.am +++ b/src/tscore/Makefile.am @@ -34,6 +34,7 @@ TESTS = $(check_PROGRAMS) noinst_LIBRARIES = libtscore.a AM_CPPFLAGS += \ + -fPIC -DPIC \ @SWOC_INCLUDES@ \ -I$(abs_top_srcdir)/include \ -I$(abs_top_srcdir)/lib \ From 18cc4f39865c1cfc96186629fa3d35f517a4dfc7 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Tue, 18 Jul 2023 17:18:28 -0600 Subject: [PATCH 12/13] Removes the -fPIE from hardening --- configure.ac | 4 ++-- proxy/hdrs/Makefile.am | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 73d8a2c587f..31dc4e697ef 100644 --- a/configure.ac +++ b/configure.ac @@ -1187,8 +1187,8 @@ AC_MSG_NOTICE([Build for host OS: $host_os, arch: $host_cpu, optimization: $host # Add hardening options to flags AS_IF([test "x${enable_hardening}" = "xyes"], [ TS_ADDTO(AM_CPPFLAGS, [-D_FORTIFY_SOURCE=2]) - TS_ADDTO(AM_CXXFLAGS, [-fPIE -fstack-protector]) - TS_ADDTO(AM_CFLAGS, [-fPIE -fstack-protector]) + TS_ADDTO(AM_CXXFLAGS, [-fstack-protector]) + TS_ADDTO(AM_CFLAGS, [-fstack-protector]) AS_CASE("$host_os_def", [linux], [TS_ADDTO(AM_LDFLAGS, [-pie -Wl,-z,relro -Wl,-z,now])] ) diff --git a/proxy/hdrs/Makefile.am b/proxy/hdrs/Makefile.am index 8b9cf9b9b2d..70b9c2e1183 100644 --- a/proxy/hdrs/Makefile.am +++ b/proxy/hdrs/Makefile.am @@ -89,6 +89,7 @@ test_proxy_hdrs_LDADD = \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/src/api/libtsapi.la \ @SWOC_LIBS@ @YAMLCPP_LIBS@ @HWLOC_LIBS@ @LIBPCRE@ @OPENSSL_LIBS@ @LIBCAP@ test_hdr_heap_CPPFLAGS = $(AM_CPPFLAGS) \ @@ -104,6 +105,7 @@ test_hdr_heap_LDADD = \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ + $(top_builddir)/src/api/libtsapi.la \ @SWOC_LIBS@ @HWLOC_LIBS@ \ @LIBPCRE@ @OPENSSL_LIBS@ @LIBCAP@ From a18b0f969e66fd2b9ac40616bb2b47bcb5b655c6 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Wed, 19 Jul 2023 16:02:05 -0600 Subject: [PATCH 13/13] Undo some of the fPIC stuff and deps --- configure.ac | 4 ++-- src/api/CMakeLists.txt | 2 -- src/api/Makefile.am | 3 +-- src/tscore/Makefile.am | 1 - tools/benchmark/Makefile.am | 1 + 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 31dc4e697ef..73d8a2c587f 100644 --- a/configure.ac +++ b/configure.ac @@ -1187,8 +1187,8 @@ AC_MSG_NOTICE([Build for host OS: $host_os, arch: $host_cpu, optimization: $host # Add hardening options to flags AS_IF([test "x${enable_hardening}" = "xyes"], [ TS_ADDTO(AM_CPPFLAGS, [-D_FORTIFY_SOURCE=2]) - TS_ADDTO(AM_CXXFLAGS, [-fstack-protector]) - TS_ADDTO(AM_CFLAGS, [-fstack-protector]) + TS_ADDTO(AM_CXXFLAGS, [-fPIE -fstack-protector]) + TS_ADDTO(AM_CFLAGS, [-fPIE -fstack-protector]) AS_CASE("$host_os_def", [linux], [TS_ADDTO(AM_LDFLAGS, [-pie -Wl,-z,relro -Wl,-z,now])] ) diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 57526a5e1bc..7d4cbe58eb9 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -25,8 +25,6 @@ add_executable(test_Metrics test_Metrics.cc ) -target_link_libraries(tsapi PUBLIC ts::tscore) - target_link_libraries(test_Metrics PRIVATE tsapi tscore) target_include_directories(test_Metrics PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR}) diff --git a/src/api/Makefile.am b/src/api/Makefile.am index 2aca36f8ff5..4c1326b6adf 100644 --- a/src/api/Makefile.am +++ b/src/api/Makefile.am @@ -29,10 +29,9 @@ AM_CPPFLAGS += \ @SWOC_INCLUDES@ \ $(TS_INCLUDES) -libtsapi_la_LDFLAGS = @AM_LDFLAGS@ -no-undefined -version-info @TS_LIBTOOL_VERSION@ @SWOC_LDFLAGS@ +libtsapi_la_LDFLAGS = @AM_LDFLAGS@ -version-info @TS_LIBTOOL_VERSION@ @SWOC_LDFLAGS@ libtsapi_la_LIBADD = \ - $(top_builddir)/src/tscore/libtscore.a \ @SWOC_LIBS@ diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am index 1308d8e03d0..8ab634398a0 100644 --- a/src/tscore/Makefile.am +++ b/src/tscore/Makefile.am @@ -34,7 +34,6 @@ TESTS = $(check_PROGRAMS) noinst_LIBRARIES = libtscore.a AM_CPPFLAGS += \ - -fPIC -DPIC \ @SWOC_INCLUDES@ \ -I$(abs_top_srcdir)/include \ -I$(abs_top_srcdir)/lib \ diff --git a/tools/benchmark/Makefile.am b/tools/benchmark/Makefile.am index 93417a0fff4..772fe19208f 100644 --- a/tools/benchmark/Makefile.am +++ b/tools/benchmark/Makefile.am @@ -49,6 +49,7 @@ benchmark_LD_ADD = \ $(top_builddir)/iocore/eventsystem/libinkevent.a \ $(top_builddir)/src/records/librecords_p.a \ $(top_builddir)/src/tscore/libtscore.a \ + $(top_builddir)/src/api/libtsapi.la \ $(top_builddir)/src/tscpp/util/libtscpputil.la \ @HWLOC_LIBS@ \ @LIBPCRE@ \