diff --git a/Dockerfile b/Dockerfile index 13a22f18f..8b09023c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -68,12 +68,12 @@ RUN mkdir /tmp/openssl && cd /tmp/openssl && \ cd ~ && rm -rf /tmp/openssl # curl -RUN git clone --depth=1 -b curl-7_69_1 https://github.com/curl/curl.git /tmp/curl && \ +RUN git clone --depth=1 -b curl-8_10_1 https://github.com/curl/curl.git /tmp/curl && \ cd /tmp/curl && \ ./buildconf && \ ./configure --disable-ldap --disable-shared --without-libssh2 \ --without-librtmp --without-libidn --enable-static \ - --without-libidn2 \ + --without-libidn2 --without-libpsl \ --with-pic --with-ssl=/usr/local/ssl/ && \ make -j && make install && \ cd ~ && rm -rf /tmp/curl diff --git a/Dockerfile.alpine b/Dockerfile.alpine index fd9aa5283..90fcd9dff 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -53,12 +53,12 @@ RUN mkdir /tmp/openssl && cd /tmp/openssl && \ cd ~ && rm -rf /tmp/openssl # curl -RUN git clone --depth=1 -b curl-7_69_1 https://github.com/curl/curl.git /tmp/curl && \ +RUN git clone --depth=1 -b curl-8_10_1 https://github.com/curl/curl.git /tmp/curl && \ cd /tmp/curl && \ ./buildconf && \ ./configure --disable-ldap --disable-shared --without-libssh2 \ --without-librtmp --without-libidn --enable-static \ - --without-libidn2 \ + --without-libidn2 --without-libpsl \ --with-pic --with-ssl=/usr/local/ssl/ && \ make -j && make install && \ cd ~ && rm -rf /tmp/curl diff --git a/src/throttler_api.cc b/src/throttler_api.cc index 0e0245588..80f70ce95 100644 --- a/src/throttler_api.cc +++ b/src/throttler_api.cc @@ -16,12 +16,17 @@ #include #include +#include #include #include #include +#include #include #include // NOLINT +#include +#include +#include #include #include #include @@ -36,6 +41,7 @@ #include "src/globals.h" #include "src/pem_roots.h" #include "src/string.h" +#include "src/throttler.h" #include "google/devtools/cloudprofiler/v2/profiler.grpc.pb.h" #include "google/protobuf/duration.pb.h" // NOLINT #include "google/rpc/error_details.pb.h" // NOLINT @@ -76,6 +82,7 @@ const char kServiceVersionLabel[] = "version"; // Range of random number const int64_t kRandomRange = 65536; +#ifdef STANDALONE_BUILD // Routes GRPC logging through cloud profiler logger. // Otherwise GRPC would log to stderr. void GRPCLog(gpr_log_func_args* args) { @@ -93,6 +100,7 @@ void GRPCLog(gpr_log_func_args* args) { << args->message; } } +#endif // STANDALONE_BUILD // Overrides the default SSL roots. Otherwise gRPC calls would fail if a SSL // roots file can't be found neither at a location specified by @@ -285,7 +293,9 @@ APIThrottler::APIThrottler( // GRPCLog is equivalent to what gRPC is doing internally, it would be safe to // delete this line and the entire GRPCLog function when you upgrade gRPC to // version 1.65 or later. +#ifdef STANDALONE_BUILD gpr_set_log_function(GRPCLog); +#endif // STANDALONE_BUILD // Create a random number generator. gen_ = std::default_random_engine(clock_->Now().tv_nsec / 1000); diff --git a/src/throttler_api.h b/src/throttler_api.h index 9083beb3f..dcf24befd 100644 --- a/src/throttler_api.h +++ b/src/throttler_api.h @@ -17,9 +17,13 @@ #ifndef CLOUD_PROFILER_AGENT_JAVA_THROTTLER_API_H_ #define CLOUD_PROFILER_AGENT_JAVA_THROTTLER_API_H_ +#include +#include #include #include +#include +#include #include #include // NOLINT #include diff --git a/third_party/perftools/profiles/proto/builder.cc b/third_party/perftools/profiles/proto/builder.cc index 5572f8e6f..a9c5084fb 100644 --- a/third_party/perftools/profiles/proto/builder.cc +++ b/third_party/perftools/profiles/proto/builder.cc @@ -71,7 +71,10 @@ int64_t Builder::StringId(const char *str) { if (str == nullptr || !str[0]) { return 0; } + return InternalStringId(str); +} +int64_t Builder::InternalStringId(const std::string &str) { const int64_t index = profile_->string_table_size(); const auto inserted = strings_.emplace(str, index); if (!inserted.second) { @@ -108,6 +111,22 @@ uint64_t Builder::FunctionId(const char *name, const char *system_name, return index; } +void Builder::SetDocURL(const std::string &url) { + const std::string kHttp = "http://"; + const std::string kHttps = "https://"; + + if (!url.empty() && url.compare(0, kHttp.size(), kHttp) != 0 && + url.compare(0, kHttps.size(), kHttps) != 0) { + if (error_.empty()) { + error_ = "setting invalid profile doc URL '"; + error_.append(url); + error_.append("'"); + } + return; + } + profile_->set_doc_url(InternalStringId(url)); +} + bool Builder::Emit(std::string *output) { *output = ""; if (!profile_ || !Finalize()) { @@ -265,6 +284,11 @@ bool Builder::CheckValid(const Profile &profile) { // - Creates missing locations for unsymbolized profiles. // - Associates locations to the corresponding mappings. bool Builder::Finalize() { + if (!error_.empty()) { + // We really should be returning an absl::Status instead of logging here. + LOG(ERROR) << error_; + return false; + } if (profile_->location_size() == 0) { IndexMap address_to_id; address_to_id.reserve(profile_->sample_size()); diff --git a/third_party/perftools/profiles/proto/builder.h b/third_party/perftools/profiles/proto/builder.h index 719617b16..73fae393f 100644 --- a/third_party/perftools/profiles/proto/builder.h +++ b/third_party/perftools/profiles/proto/builder.h @@ -87,6 +87,9 @@ class Builder { // Adds mappings for the currently running binary to the profile. void AddCurrentMappings(); + // Add documentation URL. + void SetDocURL(const std::string &url); + // Prepares the profile for encoding. Returns true on success. // If the profile has no locations, inserts location using the // location_ids from the samples as addresses. @@ -128,12 +131,17 @@ class Builder { Profile *mutable_profile() { return profile_.get(); } private: + int64_t InternalStringId(const std::string &str); + // Maps to deduplicate strings and functions. StringIndexMap strings_; FunctionIndexMap functions_; // Actual profile being updated. std::unique_ptr profile_; + + // Any error that may have been encountered while building the profile. + std::string error_; }; } // namespace profiles diff --git a/third_party/perftools/profiles/proto/profile.proto b/third_party/perftools/profiles/proto/profile.proto index c154c83e3..81050c26f 100644 --- a/third_party/perftools/profiles/proto/profile.proto +++ b/third_party/perftools/profiles/proto/profile.proto @@ -93,6 +93,12 @@ message Profile { // Index into the string table of the type of the preferred sample // value. If unset, clients should default to the last sample value. int64 default_sample_type = 14; + // Documentation link for this profile. The URL must be absolute, + // e.g., http://pprof.example.com/cpu-profile.html + // + // The URL may be missing if the profile was generated by older code or code + // that did not bother to supply a link. + int64 doc_url = 15; // Index into string table. } // ValueType describes the semantics and measurement units of a value.