Skip to content

Commit

Permalink
Merge branch 'master' into florian/use-github-actions-for-profiling-t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
realFlowControl committed Nov 8, 2024
2 parents ee6098d + 84f7fa8 commit 2b22309
Show file tree
Hide file tree
Showing 92 changed files with 849 additions and 225 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/prof_asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ on:
jobs:
prof-asan:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [8.3, 8.4]
container:
image: datadog/dd-trace-ci:php-8.3_bookworm-4
image: datadog/dd-trace-ci:php-${{matrix.php-version}}_bookworm-5
# https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#user
options: --user root --privileged

Expand All @@ -33,14 +36,15 @@ jobs:
run: |
set -eux
switch-php nts-asan
rm $(php-config --ini-dir)/sqlsrv.ini #sqlsrv leaks memory and triggers asan
cd profiling
export CARGO_TARGET_DIR=/tmp/build-cargo
export CC=clang-17
export CFLAGS='-fsanitize=address -fno-omit-frame-pointer'
export LDFLAGS='-fsanitize=address'
export LDFLAGS='-fsanitize=address -shared-libasan'
export RUSTC_LINKER=lld-17
triplet=$(uname -m)-unknown-linux-gnu
RUST_NIGHTLY_VERSION="-2024-02-27"
RUST_NIGHTLY_VERSION="-2024-11-04"
RUSTFLAGS='-Zsanitizer=address' cargo +nightly${RUST_NIGHTLY_VERSION} build -Zbuild-std --target $triplet --release
cp -v "$CARGO_TARGET_DIR/$triplet/release/libdatadog_php_profiling.so" "$(php-config --extension-dir)/datadog-profiling.so"
Expand Down
6 changes: 3 additions & 3 deletions .gitlab/ci-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ CentOS:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_TOKEN" $CI_REGISTRY
- docker buildx bake --no-cache --pull --push $PHP_VERSION

Alpine Compile Extension:
Alpine:
stage: ci-build
rules:
- when: manual
Expand All @@ -62,7 +62,7 @@ Alpine Compile Extension:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_TOKEN" $CI_REGISTRY
- docker buildx bake --no-cache --pull --push $PHP_VERSION

Ubuntu Bookworm:
Bookworm:
stage: ci-build
rules:
- when: manual
Expand Down Expand Up @@ -91,7 +91,7 @@ Ubuntu Bookworm:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_TOKEN" $CI_REGISTRY
- docker buildx bake --no-cache --pull --push $PHP_VERSION

Ubuntu Buster:
Buster:
stage: ci-build
rules:
- when: manual
Expand Down
2 changes: 1 addition & 1 deletion appsec/src/extension/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static zend_module_entry *_find_ddtrace_module()
void dd_trace_shutdown()
{
zend_module_entry *mod = _find_ddtrace_module();
if (mod) {
if (mod && _orig_ddtrace_shutdown) {
mod->request_shutdown_func = _orig_ddtrace_shutdown;
}
_orig_ddtrace_shutdown = NULL;
Expand Down
3 changes: 0 additions & 3 deletions appsec/src/helper/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
#include <spdlog/spdlog.h>
#include <stdexcept>
#include <string>
#include <thread>

#include "action.hpp"
#include "base64.h"
#include "client.hpp"
#include "compression.hpp"
#include "exception.hpp"
#include "network/broker.hpp"
#include "network/proto.hpp"
Expand Down
28 changes: 16 additions & 12 deletions appsec/src/helper/engine_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "utils.hpp"
#include <cstdint>
#include <msgpack.hpp>
#include <ostream>
#include <spdlog/spdlog.h>
#include <string>

namespace dds {
Expand Down Expand Up @@ -71,21 +71,25 @@ struct engine_settings {
schema_extraction.sample_rate ==
oth.schema_extraction.sample_rate;
}
};

} // namespace dds

friend auto &operator<<(std::ostream &os, const engine_settings &c)
template <> struct fmt::formatter<dds::engine_settings> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const dds::engine_settings &c, FormatContext &ctx) const
{
return os << "{rules_file=" << c.rules_file
<< ", waf_timeout_us=" << c.waf_timeout_us
<< ", trace_rate_limit=" << c.trace_rate_limit
<< ", obfuscator_key_regex=" << c.obfuscator_key_regex
<< ", obfuscator_value_regex=" << c.obfuscator_value_regex
<< ", schema_extraction.enabled="
<< c.schema_extraction.enabled
<< ", schema_extraction.sample_rate=" << std::fixed
<< c.schema_extraction.sample_rate << "}";
return format_to(ctx.out(),
"{{rules_file={}, waf_timeout_us={}, trace_rate_limit={}, "
"obfuscator_key_regex={}, obfuscator_value_regex={}, "
"schema_extraction.enabled={}, schema_extraction.sample_rate={}}}",
c.rules_file, c.waf_timeout_us, c.trace_rate_limit,
c.obfuscator_key_regex, c.obfuscator_value_regex,
c.schema_extraction.enabled, c.schema_extraction.sample_rate);
}
};
} // namespace dds

namespace std {
template <> struct hash<dds::engine_settings> {
Expand Down
6 changes: 4 additions & 2 deletions appsec/src/helper/json_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <rapidjson/error/en.h>
#include <rapidjson/prettywriter.h>
#include <string_view>
#include <type_traits>

using namespace std::literals;

Expand Down Expand Up @@ -176,8 +177,9 @@ json_helper::get_field_of_type(const rapidjson::Value &parent_field,
}

if (type != output_itr->value.GetType()) {
SPDLOG_DEBUG("Field {} is not of type {}. Instead {}", key, type,
output_itr->value.GetType());
SPDLOG_DEBUG("Field {} is not of type {}. Instead {}", key,
fmt::underlying(type),
fmt::underlying(output_itr->value.GetType()));
return std::nullopt;
}

Expand Down
14 changes: 9 additions & 5 deletions appsec/src/helper/remote_config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "../utils.hpp"
#include "product.hpp"
#include <spdlog/spdlog.h>
#include <string>
#include <string_view>
#include <vector>

extern "C" {
#include <sys/mman.h>
Expand Down Expand Up @@ -70,15 +70,19 @@ struct config {
{
return shm_path == b.shm_path && rc_path == b.rc_path;
}
};

} // namespace dds::remote_config

friend std::ostream &operator<<(std::ostream &os, const config &c)
template <> struct fmt::formatter<dds::remote_config::config> {
constexpr auto parse(format_parse_context &ctx) { return ctx.begin(); }

auto format(const dds::remote_config::config &c, format_context &ctx) const
{
return os << c.shm_path << ":" << c.rc_path;
return fmt::format_to(ctx.out(), "{}:{}", c.shm_path, c.rc_path);
}
};

} // namespace dds::remote_config

namespace std {
template <> struct hash<dds::remote_config::config> {
std::size_t operator()(const dds::remote_config::config &key) const
Expand Down
18 changes: 12 additions & 6 deletions appsec/src/helper/remote_config/product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
#pragma once

#include "../config.hpp"
#include "../utils.hpp"
#include <spdlog/spdlog.h>
#include <string_view>

namespace dds::remote_config {
Expand All @@ -19,11 +19,6 @@ class product {

bool operator==(const product &other) const { return name_ == other.name_; }

friend std::ostream &operator<<(std::ostream &os, const product &p)
{
return os << p.name_;
}

private:
std::string_view name_;
};
Expand Down Expand Up @@ -56,6 +51,17 @@ struct known_products {
};
} // namespace dds::remote_config

template <>
struct fmt::formatter<dds::remote_config::product>
: fmt::formatter<std::string_view> {

auto format(const dds::remote_config::product &p, format_context &ctx) const
{
auto name = p.name();
return formatter<std::string_view>::format(name, ctx);
}
};

namespace std {
template <> struct hash<dds::remote_config::product> {
std::size_t operator()(const dds::remote_config::product &product) const
Expand Down
15 changes: 13 additions & 2 deletions appsec/src/helper/remote_config/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#pragma once

#include "../utils.hpp"
#include <algorithm>
#include <cstdint>
#include <msgpack.hpp>
#include <ostream>
#include <spdlog/fmt/bundled/base.h>
#include <string>

namespace dds::remote_config {
Expand All @@ -32,8 +31,20 @@ struct settings {

MSGPACK_DEFINE_MAP(enabled, shmem_path);
};

} // namespace dds::remote_config

template <> struct fmt::formatter<dds::remote_config::settings> {
constexpr auto parse(fmt::format_parse_context &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const dds::remote_config::settings &s, FormatContext &ctx) const
{
return fmt::format_to(ctx.out(), "{{enabled={}, shmem_path={}}}",
s.enabled, s.shmem_path);
}
};

namespace std {
template <> struct hash<dds::remote_config::settings> {
std::size_t operator()(const dds::remote_config::settings &s) const noexcept
Expand Down
31 changes: 27 additions & 4 deletions appsec/src/helper/service_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,37 @@
#pragma once

#include <atomic>
#include <map>
#include <optional>
#include <spdlog/spdlog.h>
#include <unordered_map>

namespace dds {

enum class enable_asm_status : unsigned { NOT_SET = 0, ENABLED, DISABLED };
} // namespace dds

template <>
struct fmt::formatter<std::atomic<dds::enable_asm_status>>
: fmt::formatter<std::string_view> {
auto format(const std::atomic<dds::enable_asm_status> &status,
format_context &ctx) const
{
auto val = status.load();
std::string_view name{"UNKNOWN"};
switch (val) {
case dds::enable_asm_status::NOT_SET:
name = "NOT_SET";
break;
case dds::enable_asm_status::ENABLED:
name = "ENABLED";
break;
case dds::enable_asm_status::DISABLED:
name = "DISABLED";
break;
}

return fmt::formatter<std::string_view>::format(name, ctx);
}
};

namespace dds {

inline std::string_view to_string_view(enable_asm_status status)
{
Expand Down
3 changes: 2 additions & 1 deletion appsec/src/helper/subscriber/waf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ void instance::listener::call(dds::parameter_view &data, event &event)
parameter_to_json(parameter_view{res.events}),
res.total_runtime / millis);
SPDLOG_DEBUG("Waf response: code {} - actions {} - derivatives {}",
code, parameter_to_json(parameter_view{res.actions}),
fmt::underlying(code),
parameter_to_json(parameter_view{res.actions}),
parameter_to_json(parameter_view{res.derivatives}));

} else {
Expand Down
2 changes: 1 addition & 1 deletion appsec/third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ endif()
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG eb3220622e73a4889eee355ffa37972b3cac3df5)
GIT_TAG 5fd32e1a70871e2f6a52734e36bc33cb7ac022a5)
FetchContent_MakeAvailable(spdlog)
set_target_properties(spdlog PROPERTIES POSITION_INDEPENDENT_CODE 1)

Expand Down
38 changes: 18 additions & 20 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PHP_ARG_WITH(ddtrace-cargo, where cargo is located for rust code compilation,
[ --with-ddtrace-cargo Location to cargo binary for rust compilation], cargo, not found)

PHP_ARG_ENABLE(ddtrace-rust-debug, whether to compile rust in debug mode,
[ --enable-ddtrace-rust-debug Build rust code in debug mode (significantly slower)], [[$($GREP -q "ZEND_DEBUG 1" $("$PHP_CONFIG" --include-dir)/main/php_config.h && echo yes || echo no)]], [no])
[ --enable-ddtrace-rust-debug Build rust code in debug mode (significantly slower)], [[$( (if test x"$ext_shared" = x"yes"; then $GREP -q "ZEND_DEBUG 1" $("$PHP_CONFIG" --include-dir)/main/php_config.h; else test x"$PHP_DEBUG" = x"yes"; fi) && echo yes || echo no)]], [no])

PHP_ARG_ENABLE(ddtrace-rust-library-split, whether to not link the rust library against the extension at compile time,
[ --enable-ddtrace-rust-library-split Do not build nor link against the rust code], no, no)
Expand Down Expand Up @@ -78,25 +78,23 @@ if test "$PHP_DDTRACE" != "no"; then
CFLAGS="$CFLAGS -fms-extensions"
EXTRA_CFLAGS="$EXTRA_CFLAGS -fms-extensions"

AC_MSG_CHECKING([whether the compiler is LLVM])


AC_RUN_IFELSE([AC_LANG_SOURCE([[int main(void) {
#ifdef __clang__
return 0;
#else
return 1;
#endif
}]])],[llvm=yes],[llvm=no],[llvm=yes])

if test "$llvm" = "yes"; then
AC_MSG_RESULT([yes])
CFLAGS="$CFLAGS -Wno-microsoft-anon-tag"
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wno-microsoft-anon-tag"
LDFLAGS="$LDFLAGS -Wl,--undefined-version"
else
AC_MSG_RESULT([no])
fi
rm="rm -f"
lt_simple_link_test_code='int main(void){return(0);}'
AC_MSG_CHECKING([whether --undefined-version is a valid linker argument])
AC_LIBTOOL_LINKER_OPTION([whether --undefined-version is a valid linker argument],
lt_cv_ddtrace_undefined_version,
[-Wl,--undefined-version],
[LDFLAGS="$LDFLAGS -Wl,--undefined-version"])

lt_simple_compile_test_code="int some_variable = 0;"
Xsed="$SED -e 1s/^X//"
AC_LIBTOOL_COMPILER_OPTION([whether -Wno-microsoft-anon-tag is a valid compiler argument],
lt_cv_ddtrace_no_microsoft_anon_tag,
[-Wno-microsoft-anon-tag], [],
[
CFLAGS="$CFLAGS -Wno-microsoft-anon-tag"
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wno-microsoft-anon-tag"
])

DD_TRACE_VENDOR_SOURCES="\
ext/vendor/mpack/mpack.c \
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ services:
'8.4-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.4_buster' }
'php-master-buster': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-master_buster' }
# --- Bookworm ---
'8.2-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_bookworm-3' }
'8.3-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_bookworm-3' }
'8.2-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.2_bookworm-5' }
'8.3-bookworm': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-8.3_bookworm-5' }
# --- CentOS 6 ---
'7.0-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.0_centos-7' }
'7.1-centos7': { <<: *linux_php_service, image: 'datadog/dd-trace-ci:php-7.1_centos-7' }
Expand Down
4 changes: 2 additions & 2 deletions dockerfiles/ci/alpine_compile_extension/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ services:
x-bake: *bake
args:
php_version: 8.4.0
php_url: https://downloads.php.net/~saki/php-8.4.0RC1.tar.gz
php_sha: ff924ce24493cd546c7227c2cedf75c32d23815b0a6e5c1658d9b005837631ff
php_url: https://downloads.php.net/~calvinb/php-8.4.0RC4.tar.gz
php_sha: 3964fee49465e6fcae77ad030ae31aa720ade0a51c53df6e255e36eb867fd4b2
php_api: 20240924
volumes:
- ../../:/app
Loading

0 comments on commit 2b22309

Please sign in to comment.