diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ebde1e88c1dfd..084f39125f3c1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -165,6 +165,7 @@ /cmd/agent/dist/conf.d/jetson.d/ @DataDog/agent-devx-infra /cmd/agent/dist/conf.d/oracle.d/ @DataDog/database-monitoring /cmd/agent/dist/conf.d/oracle-dbm.d/ @DataDog/database-monitoring +/cmd/agent/dist/conf.d/network_path.d/ @DataDog/Networks @DataDog/network-device-monitoring /cmd/agent/dist/conf.d/sbom.d/ @DataDog/container-integrations /cmd/agent/dist/conf.d/snmp.d/ @DataDog/network-device-monitoring /cmd/agent/dist/conf.d/win32_event_log.d/ @DataDog/windows-agent @@ -207,6 +208,7 @@ /Dockerfiles/agent/entrypoint.d.windows/ @DataDog/container-integrations @DataDog/windows-agent /Dockerfiles/agent/entrypoint.ps1 @DataDog/container-integrations @DataDog/windows-agent /Dockerfiles/agent/windows/ @DataDog/container-integrations @DataDog/windows-agent +/Dockerfiles/agent-ot/Dockerfile.byoc @DataDog/opentelemetry /docs/ @DataDog/documentation @DataDog/agent-devx-loops /docs/dev/checks/ @DataDog/documentation @DataDog/agent-metrics-logs diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml index 097e3b138c288..8bb8e201c603a 100644 --- a/.github/dependabot.yaml +++ b/.github/dependabot.yaml @@ -7,7 +7,6 @@ updates: - dependencies-go - team/triage - changelog/no-changelog - milestone: 22 ignore: # These dependencies are replaced in the main go.mod file. # They are ignored since bumping them would have no effect on the build. @@ -45,7 +44,6 @@ updates: - dependencies-go - team/agent-apm - changelog/no-changelog - milestone: 22 ignore: # Ignore internal modules - dependency-name: github.com/DataDog/datadog-agent/* @@ -61,7 +59,6 @@ updates: - dependencies-go - team/agent-shared-components - changelog/no-changelog - milestone: 22 ignore: # Ignore internal modules - dependency-name: github.com/DataDog/datadog-agent/* @@ -77,7 +74,6 @@ updates: - dependencies-go - team/agent-apm - changelog/no-changelog - milestone: 22 ignore: # Ignore internal modules - dependency-name: github.com/DataDog/datadog-agent/* @@ -93,7 +89,6 @@ updates: - dependencies-go - team/agent-security - changelog/no-changelog - milestone: 22 ignore: # Ignore internal modules - dependency-name: github.com/DataDog/datadog-agent/* @@ -113,7 +108,6 @@ updates: - team/agent-delivery - changelog/no-changelog - qa/no-code-change - milestone: 22 schedule: interval: monthly open-pull-requests-limit: 100 @@ -124,7 +118,6 @@ updates: - dependencies-go - team/network-device-monitoring - changelog/no-changelog - milestone: 22 ignore: # Ignore internal modules - dependency-name: github.com/DataDog/datadog-agent/* @@ -140,7 +133,6 @@ updates: - changelog/no-changelog - qa/no-code-change - dev/testing - milestone: 22 ignore: # Ignore test-infra-definitions because bumping the GO package inside `go.mod` # requires to also bump `TEST_INFRA_DEFINITIONS_BUILDIMAGES` inside `.gitlab/common/test_infra_version.yml` @@ -162,7 +154,6 @@ updates: - changelog/no-changelog - qa/no-code-change - dev/testing - milestone: 22 schedule: interval: weekly open-pull-requests-limit: 100 @@ -175,7 +166,6 @@ updates: - changelog/no-changelog - qa/no-code-change - dev/tooling - milestone: 22 schedule: interval: monthly open-pull-requests-limit: 100 @@ -187,7 +177,6 @@ updates: - changelog/no-changelog - qa/no-code-change - dev/testing - milestone: 22 schedule: interval: weekly open-pull-requests-limit: 100 @@ -200,7 +189,6 @@ updates: - changelog/no-changelog - qa/no-code-change - dev/tooling - milestone: 22 schedule: interval: weekly open-pull-requests-limit: 100 diff --git a/.github/workflows/create_rc_pr.yml b/.github/workflows/create_rc_pr.yml index d77d9ed21ddd5..e2ca17cb6bfd0 100644 --- a/.github/workflows/create_rc_pr.yml +++ b/.github/workflows/create_rc_pr.yml @@ -48,6 +48,9 @@ jobs: - name: Check for changes since last RC id: check_for_changes + env: + ATLASSIAN_USERNAME: ${{ secrets.ATLASSIAN_USERNAME }} + ATLASSIAN_PASSWORD: ${{ secrets.ATLASSIAN_PASSWORD }} run: | echo "CHANGES=$(inv -e release.check-for-changes -r ${{ env.RELEASE_BRANCH }} ${{ env.WARNING }})" >> $GITHUB_OUTPUT diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 60eb001485a82..ce9c408facdf0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -219,6 +219,9 @@ variables: GITLAB_FULL_API_TOKEN_SSM_NAME: ci.datadog-agent.gitlab_full_api_token # ci-cd INSTALL_SCRIPT_API_KEY_SSM_NAME: ci.agent-linux-install-script.datadog_api_key_2 # agent-delivery JIRA_READ_API_TOKEN_SSM_NAME: ci.datadog-agent.jira_read_api_token # agent-devx-infra + AGENT_GITHUB_APP_ID_SSM_NAME: ci.datadog-agent.platform-github-app-id # agent-devx-infra + AGENT_GITHUB_INSTALLATION_ID_SSM_NAME: ci.datadog-agent.platform-github-app-installation-id # agent-devx-infra + AGENT_GITHUB_KEY_SSM_NAME: ci.datadog-agent.platform-github-app-key # agent-devx-infra MACOS_GITHUB_APP_ID_SSM_NAME: ci.datadog-agent.macos_github_app_id # agent-devx-infra MACOS_GITHUB_INSTALLATION_ID_SSM_NAME: ci.datadog-agent.macos_github_installation_id # agent-devx-infra MACOS_GITHUB_KEY_SSM_NAME: ci.datadog-agent.macos_github_key_b64 # agent-devx-infra @@ -359,14 +362,12 @@ variables: .if_mergequeue: &if_mergequeue if: $CI_COMMIT_BRANCH =~ /^mq-working-branch-/ -.fakeintake_changes: &fakeintake_changes - changes: - paths: - - "test/fakeintake/**/*" - - .gitlab/binary_build/fakeintake.yml - - .gitlab/container_build/fakeintake.yml - - .gitlab/dev_container_deploy/fakeintake.yml - compare_to: main # TODO: use a variable, when this is supported https://gitlab.com/gitlab-org/gitlab/-/issues/369916 +.fakeintake_paths: &fakeintake_paths + paths: + - "test/fakeintake/**/*" + - .gitlab/binary_build/fakeintake.yml + - .gitlab/container_build/fakeintake.yml + - .gitlab/dev_container_deploy/fakeintake.yml # # Workflow rules @@ -790,7 +791,9 @@ workflow: .on_e2e_or_fakeintake_changes_or_manual: - !reference [.on_e2e_main_release_or_rc] - - <<: *fakeintake_changes + - changes: + <<: *fakeintake_paths + compare_to: main # TODO: use a variable, when this is supported https://gitlab.com/gitlab-org/gitlab/-/issues/369916 variables: FAKEINTAKE_IMAGE_OVERRIDE: "public.ecr.aws/datadog/fakeintake:v$CI_COMMIT_SHORT_SHA" when: on_success @@ -1051,10 +1054,13 @@ workflow: compare_to: main # TODO: use a variable, when this is supported https://gitlab.com/gitlab-org/gitlab/-/issues/369916 .on_fakeintake_changes: - - <<: *fakeintake_changes + - changes: + <<: *fakeintake_paths + compare_to: main # TODO: use a variable, when this is supported https://gitlab.com/gitlab-org/gitlab/-/issues/369916 .on_fakeintake_changes_on_main: - - <<: *fakeintake_changes + - changes: + <<: *fakeintake_paths <<: *if_main_branch .fast_on_dev_branch_only: diff --git a/.gitlab/.pre/test_gitlab_configuration.yml b/.gitlab/.pre/test_gitlab_configuration.yml index ae551bbd6d764..77ecf1083cdab 100644 --- a/.gitlab/.pre/test_gitlab_configuration.yml +++ b/.gitlab/.pre/test_gitlab_configuration.yml @@ -7,5 +7,19 @@ test_gitlab_configuration: script: - source /root/.bashrc - export GITLAB_TOKEN=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh $GITLAB_FULL_API_TOKEN_SSM_NAME) - - inv linter.gitlab-ci - - inv linter.gitlab-change-paths + - inv -e linter.gitlab-ci + - inv -e linter.job-change-path + - inv -e linter.gitlab-change-paths + +test_gitlab_compare_to: + stage: .pre + image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent-buildimages/deb_x64$DATADOG_AGENT_BUILDIMAGES_SUFFIX:$DATADOG_AGENT_BUILDIMAGES + tags: ["arch:amd64"] + rules: + - !reference [.on_gitlab_changes] + script: + - source /root/.bashrc + - export GITLAB_TOKEN=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh $GITLAB_FULL_API_TOKEN_SSM_NAME) + - !reference [.setup_agent_github_app] + - pip install -r tasks/requirements.txt + - inv pipeline.compare-to-itself diff --git a/.gitlab/common/shared.yml b/.gitlab/common/shared.yml index 76130b9bf033a..1df106e9b4c08 100644 --- a/.gitlab/common/shared.yml +++ b/.gitlab/common/shared.yml @@ -41,6 +41,12 @@ echo "Using GitHub App instance 2" fi +.setup_agent_github_app: + - export GITHUB_KEY_B64=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh $AGENT_GITHUB_KEY_SSM_NAME) + - export GITHUB_APP_ID=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh $AGENT_GITHUB_APP_ID_SSM_NAME) + - export GITHUB_INSTALLATION_ID=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh $AGENT_GITHUB_INSTALLATION_ID_SSM_NAME) + - echo "Using agent GitHub App" + # Install `dd-pkg` and lint packages produced by Omnibus, supports only deb and rpm packages .lint_linux_packages: - curl -sSL "https://dd-package-tools.s3.amazonaws.com/dd-pkg/${DD_PKG_VERSION}/dd-pkg_Linux_${DD_PKG_ARCH}.tar.gz" | tar -xz -C /usr/local/bin dd-pkg diff --git a/.gitlab/container_build/fakeintake.yml b/.gitlab/container_build/fakeintake.yml index 5ded5652f7c25..2d88bc7776ca5 100644 --- a/.gitlab/container_build/fakeintake.yml +++ b/.gitlab/container_build/fakeintake.yml @@ -4,6 +4,7 @@ docker_build_fakeintake: rules: - !reference [.except_mergequeue] - !reference [.on_fakeintake_changes] + - !reference [.on_fakeintake_changes_on_main] needs: [] image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docker:20.10-py3 tags: ["arch:amd64"] diff --git a/.gitlab/deploy_packages/oci.yml b/.gitlab/deploy_packages/oci.yml index cdd42e7c9dddc..52bf505f028b5 100644 --- a/.gitlab/deploy_packages/oci.yml +++ b/.gitlab/deploy_packages/oci.yml @@ -21,6 +21,9 @@ include: - export VERSION=$(inv agent.version --url-safe)-1 - git config --global credential.helper '!f() { echo username=x-access-token; echo "password=$GH_TOKEN"; };f' - ${CI_PROJECT_DIR}/tools/ci/retry.sh git clone -v --depth=1 https://github.com/DataDog/datadog-packages /tmp/datadog-packages + - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/".insteadOf "https://github.com/DataDog/" + - export GOPROXY="binaries.ddbuild.io,proxy.golang.org,direct" + - export GONOSUMDB="github.com/DataDog,go.ddbuild.io" - cd /tmp/datadog-packages/cmd/datadog-package - go build . - ./datadog-package push registry.ddbuild.io/ci/remote-updates/${OCI_PRODUCT}:${VERSION} ${OMNIBUS_PACKAGE_DIR}/${OCI_PRODUCT}-${VERSION}.oci.tar diff --git a/.gitlab/dev_container_deploy/fakeintake.yml b/.gitlab/dev_container_deploy/fakeintake.yml index 326def46873f9..6466b4c0e2445 100644 --- a/.gitlab/dev_container_deploy/fakeintake.yml +++ b/.gitlab/dev_container_deploy/fakeintake.yml @@ -14,17 +14,17 @@ publish_fakeintake: IMG_REGISTRIES: public IMG_SIGNING: "false" -publish_fakeintake_latest: - extends: .docker_publish_job_definition - stage: dev_container_deploy - rules: - - !reference [.except_mergequeue] - - !reference [.on_fakeintake_changes_on_main] - needs: - - job: docker_build_fakeintake - optional: false - variables: - IMG_SOURCES: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent/fakeintake:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA} - IMG_DESTINATIONS: fakeintake:latest - IMG_REGISTRIES: public - IMG_SIGNING: "false" +# publish_fakeintake_latest: +# extends: .docker_publish_job_definition +# stage: dev_container_deploy +# rules: +# - !reference [.except_mergequeue] +# - !reference [.on_fakeintake_changes_on_main] +# needs: +# - job: docker_build_fakeintake +# optional: false +# variables: +# IMG_SOURCES: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/datadog-agent/fakeintake:v${CI_PIPELINE_ID}-${CI_COMMIT_SHORT_SHA} +# IMG_DESTINATIONS: fakeintake:latest +# IMG_REGISTRIES: public +# IMG_SIGNING: "false" diff --git a/.gitlab/e2e/e2e.yml b/.gitlab/e2e/e2e.yml index 700ae6f22e12b..86e78004459a6 100644 --- a/.gitlab/e2e/e2e.yml +++ b/.gitlab/e2e/e2e.yml @@ -165,7 +165,9 @@ new-e2e-containers: TEAM: container-integrations parallel: matrix: - - EXTRA_PARAMS: "--run TestKindSuite -c ddinfra:kubernetesVersion=1.19" + # Temporarily disable old version of Kubernetes + # On this version, the reported kubernetes CPU usage appears to be significantly off + # - EXTRA_PARAMS: "--run TestKindSuite -c ddinfra:kubernetesVersion=1.19" - EXTRA_PARAMS: "--run TestKindSuite -c ddinfra:kubernetesVersion=1.22" - EXTRA_PARAMS: "--run TestKindSuite -c ddinfra:kubernetesVersion=1.27" - EXTRA_PARAMS: "--run TestKindSuite -c ddinfra:kubernetesVersion=1.29" diff --git a/.gitlab/kitchen_testing/new-e2e_testing/ubuntu.yml b/.gitlab/kitchen_testing/new-e2e_testing/ubuntu.yml index 0d929298c96a8..0a7b3bd7c149a 100644 --- a/.gitlab/kitchen_testing/new-e2e_testing/ubuntu.yml +++ b/.gitlab/kitchen_testing/new-e2e_testing/ubuntu.yml @@ -18,9 +18,9 @@ .new-e2e_ubuntu_a6_x86_64: variables: E2E_ARCH: x86_64 - E2E_OSVERS: "ubuntu-14-04,ubuntu-16-04,ubuntu-18-04,ubuntu-20-04,ubuntu-22-04" + E2E_OSVERS: "ubuntu-14-04,ubuntu-16-04,ubuntu-18-04,ubuntu-20-04,ubuntu-22-04,ubuntu-24-04" E2E_CWS_SUPPORTED_OSVERS: "ubuntu-18-04,ubuntu-20-04,ubuntu-22-04" - E2E_BRANCH_OSVERS: "ubuntu-22-04" + E2E_BRANCH_OSVERS: "ubuntu-24-04" needs: - !reference [.needs_new_e2e_template] - deploy_deb_testing-a6_x64 @@ -28,7 +28,7 @@ .new-e2e_ubuntu_a6_arm64: variables: E2E_ARCH: arm64 - E2E_OSVERS: "ubuntu-18-04,ubuntu-20-04" + E2E_OSVERS: "ubuntu-18-04,ubuntu-20-04,ubuntu-24-04" E2E_CWS_SUPPORTED_OSVERS: "ubuntu-18-04,ubuntu-20-04" E2E_BRANCH_OSVERS: "ubuntu-20-04" needs: @@ -38,9 +38,9 @@ .new-e2e_ubuntu_a7_x86_64: variables: E2E_ARCH: x86_64 - E2E_OSVERS: "ubuntu-14-04,ubuntu-16-04,ubuntu-18-04,ubuntu-20-04,ubuntu-22-04" + E2E_OSVERS: "ubuntu-14-04,ubuntu-16-04,ubuntu-18-04,ubuntu-20-04,ubuntu-22-04,ubuntu-24-04" E2E_CWS_SUPPORTED_OSVERS: "ubuntu-18-04,ubuntu-20-04,ubuntu-22-04" - E2E_BRANCH_OSVERS: "ubuntu-22-04" + E2E_BRANCH_OSVERS: "ubuntu-24-04" needs: - !reference [.needs_new_e2e_template] - deploy_deb_testing-a7_x64 @@ -48,7 +48,7 @@ .new-e2e_ubuntu_a7_arm64: variables: E2E_ARCH: arm64 - E2E_OSVERS: "ubuntu-18-04,ubuntu-20-04" + E2E_OSVERS: "ubuntu-18-04,ubuntu-20-04,ubuntu-24-04" E2E_CWS_SUPPORTED_OSVERS: "ubuntu-18-04,ubuntu-20-04" E2E_BRANCH_OSVERS: "ubuntu-20-04" needs: diff --git a/.gitlab/package_build/installer.yml b/.gitlab/package_build/installer.yml index 41a1e0f19f818..ac335677c8bad 100644 --- a/.gitlab/package_build/installer.yml +++ b/.gitlab/package_build/installer.yml @@ -100,6 +100,9 @@ datadog-agent-oci-arm64-a7: - !reference [.upload_sbom_artifacts] variables: AGENT_MAJOR_VERSION: 7 + KUBERNETES_CPU_REQUEST: 8 + KUBERNETES_MEMORY_REQUEST: "16Gi" + KUBERNETES_MEMORY_LIMIT: "16Gi" artifacts: expire_in: 2 weeks paths: diff --git a/.gitlab/packaging/oci.yml b/.gitlab/packaging/oci.yml index 988d56e385203..6457ec8f30bbe 100644 --- a/.gitlab/packaging/oci.yml +++ b/.gitlab/packaging/oci.yml @@ -24,8 +24,11 @@ - git config --global credential.helper '!f() { echo username=x-access-token; echo "password=$GH_TOKEN"; };f' - cd /tmp/ - ${CI_PROJECT_DIR}/tools/ci/retry.sh git clone --depth=1 https://github.com/DataDog/datadog-packages + - git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/".insteadOf "https://github.com/DataDog/" + - export GOPROXY="binaries.ddbuild.io,proxy.golang.org,direct" + - export GONOSUMDB="github.com/DataDog,go.ddbuild.io" - cd datadog-packages/cmd/datadog-package - - go build . + - ${CI_PROJECT_DIR}/tools/ci/retry.sh go build . - OUTPUT_DIR="/tmp/oci_output" - mkdir -p ${OUTPUT_DIR} - ls $OMNIBUS_PACKAGE_DIR diff --git a/.gitlab/post_rc_build/post_rc_tasks.yml b/.gitlab/post_rc_build/post_rc_tasks.yml index fc46b3920f39f..00efc95005fa5 100644 --- a/.gitlab/post_rc_build/post_rc_tasks.yml +++ b/.gitlab/post_rc_build/post_rc_tasks.yml @@ -15,4 +15,6 @@ update_rc_build_links: - export ATLASSIAN_PASSWORD=$($CI_PROJECT_DIR/tools/ci/aws_ssm_get_wrapper.sh $JIRA_READ_API_TOKEN_SSM_NAME) - export ATLASSIAN_USERNAME=robot-jira-agentplatform@datadoghq.com - python3 -m pip install -r tasks/requirements_release_tasks.txt - - inv -e release.update-build-links ${CI_COMMIT_REF_NAME} + - PATCH=$(echo "$CI_COMMIT_REF_NAME" | cut -d'.' -f3 | cut -c1) + - if [[ "$PATCH" == "0" ]]; then PATCH_OPTION=""; else PATCH_OPTION="-p"; fi + - inv -e release.update-build-links ${CI_COMMIT_REF_NAME} ${PATCH_OPTION} diff --git a/.golangci.yml b/.golangci.yml index 0698f46496433..06ce90022502a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -99,7 +99,7 @@ linters-settings: errcheck: # Disable warnings for `fmt`, `log` and `seelog` packages. Also ignore `Write` functions from `net/http` package. # Disable warnings for select Windows functions - ignore: fmt:.*,github.com/DataDog/datadog-agent/pkg/util/log:.*,github.com/DataDog/datadog-agent/comp/core/log:.*,github.com/cihub/seelog:.*,net/http:Write,github.com/DataDog/datadog-agent/pkg/trace/metrics:.*,github.com/DataDog/datadog-agent/pkg/collector/corechecks:Warnf?,golang.org/x/sys/windows:(CloseHandle|FreeLibrary|FreeSid|RegCloseKey|SetEvent|LocalFree),syscall:CloseHandle,golang.org/x/sys/windows/svc/mgr:Disconnect,golang.org/x/sys/windows/svc/debug:(Close|Error|Info|Warning),github.com/lxn/walk:Dispose,github.com/DataDog/datadog-agent/comp/core/flare/types:(AddFile.*|CopyDir.*|CopyFile.*),github.com/DataDog/datadog-agent/comp/core/flare/builder:(AddFile.*|CopyDir.*|CopyFile.*),golang.org/x/sys/windows/registry:Close + ignore: fmt:.*,github.com/DataDog/datadog-agent/pkg/util/log:.*,github.com/DataDog/datadog-agent/comp/core/log/def:.*,github.com/DataDog/datadog-agent/comp/core/log/mock:.*,github.com/cihub/seelog:.*,net/http:Write,github.com/DataDog/datadog-agent/pkg/trace/metrics:.*,github.com/DataDog/datadog-agent/pkg/collector/corechecks:Warnf?,golang.org/x/sys/windows:(CloseHandle|FreeLibrary|FreeSid|RegCloseKey|SetEvent|LocalFree),syscall:CloseHandle,golang.org/x/sys/windows/svc/mgr:Disconnect,golang.org/x/sys/windows/svc/debug:(Close|Error|Info|Warning),github.com/lxn/walk:Dispose,github.com/DataDog/datadog-agent/comp/core/flare/types:(AddFile.*|CopyDir.*|CopyFile.*),github.com/DataDog/datadog-agent/comp/core/flare/builder:(AddFile.*|CopyDir.*|CopyFile.*),golang.org/x/sys/windows/registry:Close staticcheck: checks: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", # These ones are disabled by default on staticcheck diff --git a/.vscode/launch.json.template b/.vscode/launch.json.template index 42e5a3b9dead3..93973304ce6be 100644 --- a/.vscode/launch.json.template +++ b/.vscode/launch.json.template @@ -35,5 +35,20 @@ "mode": "test", "program": "${fileDirname}" }, + { + "name": "Remote Debug Tasks", + "type": "debugpy", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "." + } + ] + }, ] -} \ No newline at end of file +} diff --git a/.vscode/settings.json.template b/.vscode/settings.json.template index e3c5aefcf62e9..795843112176d 100644 --- a/.vscode/settings.json.template +++ b/.vscode/settings.json.template @@ -26,5 +26,14 @@ "SC2059", "SC2028" ], - "shellcheck.run": "onSave" + "shellcheck.run": "onSave", + "python.testing.unittestArgs": [ + "-v", + "-s", + "./tasks", + "-p", + "*_tests.py" + ], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true }} diff --git a/Dockerfiles/agent-ot/Dockerfile.byoc b/Dockerfiles/agent-ot/Dockerfile.byoc new file mode 100644 index 0000000000000..04132bd129dfd --- /dev/null +++ b/Dockerfiles/agent-ot/Dockerfile.byoc @@ -0,0 +1,84 @@ +ARG AGENT_VERSION=nightly-ot-beta-main-jmx +# Use the Ubuntu Slim AMD64 base image +FROM ubuntu:24.04 AS builder + +# Set environment variables +ARG AGENT_VERSION +ENV DEBIAN_FRONTEND=noninteractive + +# Set the working directory +WORKDIR /workspace + +# Update and install necessary packages +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + curl \ + ca-certificates \ + software-properties-common \ + build-essential \ + git \ + python3 \ + python3-pip \ + python3-venv \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# TEMP: Use github source code +RUN git clone https://github.com/DataDog/datadog-agent.git datadog-agent-${AGENT_VERSION} + +# Once we have stable releases, we can use the following code to download the source code +# TODO: use released agent version once we have an agent release with the otel binary +# Download and unpack source code +#RUN curl -L https://github.com/DataDog/datadog-agent/archive/refs/tags/${AGENT_VERSION}.tar.gz -o datadog-agent-${AGENT_VERSION}.tar.gz && \ +# tar -xzvf datadog-agent-${AGENT_VERSION}.tar.gz && \ +# rm datadog-agent-${AGENT_VERSION}.tar.gz + + +# Set the working directory to the source code +WORKDIR /workspace/datadog-agent-${AGENT_VERSION} + +# Install Go based on architecture +RUN GO_VERSION=$(cat .go-version) && \ + ARCH=$(dpkg --print-architecture) && \ + if [ "$ARCH" = "amd64" ]; then \ + GO_ARCH="linux-amd64"; \ + elif [ "$ARCH" = "arm64" ]; then \ + GO_ARCH="linux-arm64"; \ + else \ + echo "Unsupported architecture: $ARCH" && exit 1; \ + fi && \ + curl -OL https://golang.org/dl/go${GO_VERSION}.$GO_ARCH.tar.gz && \ + tar -C /usr/local -xzf go${GO_VERSION}.$GO_ARCH.tar.gz && \ + rm go${GO_VERSION}.$GO_ARCH.tar.gz + +# Set up Go environment +ENV PATH="/usr/local/go/bin:${PATH}" +RUN mkdir /go +ENV GOPATH=/go + +# Verify installations +RUN go version && \ + python3 --version && \ + curl --version + +# Create and activate virtual environment, then install requirements +RUN python3 -m venv venv && \ + . venv/bin/activate && \ + pip install --upgrade pip && \ + pip install -r tasks/requirements.txt + +# Copy the manifest file +COPY manifest.yaml /workspace/datadog-agent-${AGENT_VERSION}/comp/otelcol/collector-contrib/impl/manifest.yaml + +# Generate the files +RUN . venv/bin/activate && invoke collector.generate + +# Build the OTel agent +RUN . venv/bin/activate && invoke otel-agent.build + +# Use the final Datadog agent image +FROM datadog/agent-dev:${AGENT_VERSION} +ARG AGENT_VERSION +# Copy the built OTel agent from the builder stage +COPY --from=builder /workspace/datadog-agent-${AGENT_VERSION}/bin/otel-agent/otel-agent /opt/datadog-agent/embedded/bin/otel-agent + diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index af396e7168562..58bdcb49aa538 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -2769,6 +2769,7 @@ core,google.golang.org/grpc/balancer/base,Apache-2.0,Copyright 2014 gRPC authors core,google.golang.org/grpc/balancer/grpclb,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/balancer/grpclb/grpc_lb_v1,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/balancer/grpclb/state,Apache-2.0,Copyright 2014 gRPC authors. +core,google.golang.org/grpc/balancer/pickfirst,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/balancer/roundrobin,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/binarylog/grpc_binarylog_v1,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/channelz,Apache-2.0,Copyright 2014 gRPC authors. @@ -2803,7 +2804,6 @@ core,google.golang.org/grpc/internal/credentials,Apache-2.0,Copyright 2014 gRPC core,google.golang.org/grpc/internal/envconfig,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/internal/googlecloud,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/internal/grpclog,Apache-2.0,Copyright 2014 gRPC authors. -core,google.golang.org/grpc/internal/grpcrand,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/internal/grpcsync,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/internal/grpcutil,Apache-2.0,Copyright 2014 gRPC authors. core,google.golang.org/grpc/internal/idle,Apache-2.0,Copyright 2014 gRPC authors. diff --git a/cmd/agent/command/command.go b/cmd/agent/command/command.go index 485e4f4f78005..21ed10e442354 100644 --- a/cmd/agent/command/command.go +++ b/cmd/agent/command/command.go @@ -15,7 +15,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ) const ( @@ -56,7 +56,7 @@ type SubcommandFactory func(globalParams *GlobalParams) []*cobra.Command func GetDefaultCoreBundleParams(globalParams *GlobalParams) core.BundleParams { return core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), - LogParams: logimpl.ForOneShot(LoggerName, "off", true)} + LogParams: log.ForOneShot(LoggerName, "off", true)} } // MakeCommand makes the top-level Cobra command for this app. diff --git a/cmd/agent/dist/conf.d/network_path.d/conf.yaml.example b/cmd/agent/dist/conf.d/network_path.d/conf.yaml.example new file mode 100644 index 0000000000000..6a1a287f9d267 --- /dev/null +++ b/cmd/agent/dist/conf.d/network_path.d/conf.yaml.example @@ -0,0 +1,56 @@ +init_config: + ## @param min_collection_interval - number - optional - default: 60 + ## Specifies how frequently we should probe the endpoint. + ## Min collection interval is defined in seconds. + # + # min_collection_interval: 60 + +# Network Path integration is used to monitor individual endpoints. +# Supported platforms are Linux and Windows. macOS is not supported yet. +instances: + - ## @param hostname - string - required + ## Hostname or IP of the target endpoint to monitor via Network Path. + # + hostname: + + ## @param port - integer - optional + ## Port of the target endpoint to monitor via Network Path. + ## If port is not set, a random port will be used. + # + # port: + + ## @param protocol - string - optional - default: UDP + ## Protocol used to monitor an endpoint via Network Path. + ## Available protocols: UDP, TCP + # + # protocol: + + ## @param max_ttl - integer - optional - default: 30 + ## Specifies the maximum number of hops (max time-to-live value) traceroute will probe. + # + # max_ttl: + + ## @param min_collection_interval - number - optional - default: 60 + ## Specifies how frequently we should probe the endpoint. + ## Min collection interval is defined in seconds. + # + # min_collection_interval: 60 + + ## @param source_service - string - optional + ## Source service name. + # + # source_service: + + ## @param destination_service - string - optional + ## Destination service name. + # + # destination_service: + + ## @param tags - list of strings - optional + ## A list of tags to attach to every metric and service check emitted by this instance. + ## + ## Learn more about tagging at https://docs.datadoghq.com/tagging + # + # tags: + # - : + # - : diff --git a/cmd/agent/subcommands/configcheck/command.go b/cmd/agent/subcommands/configcheck/command.go index d5056b2e74cf9..db5c8a3e12e4a 100644 --- a/cmd/agent/subcommands/configcheck/command.go +++ b/cmd/agent/subcommands/configcheck/command.go @@ -19,8 +19,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" apiutil "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/flare" @@ -51,7 +50,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(cliParams.ExtraConfFilePath)), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot("CORE", "off", true)}), + LogParams: log.ForOneShot("CORE", "off", true)}), core.Bundle(), ) }, diff --git a/cmd/agent/subcommands/diagnose/command.go b/cmd/agent/subcommands/diagnose/command.go index 5fcee1711a3be..23e3a8abf3481 100644 --- a/cmd/agent/subcommands/diagnose/command.go +++ b/cmd/agent/subcommands/diagnose/command.go @@ -21,8 +21,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/autodiscoveryimpl" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" @@ -88,7 +87,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), - LogParams: logimpl.ForOneShot("CORE", "off", true), + LogParams: log.ForOneShot("CORE", "off", true), }), core.Bundle(), // workloadmeta setup diff --git a/cmd/agent/subcommands/dogstatsd/command.go b/cmd/agent/subcommands/dogstatsd/command.go index bbd6501170420..d364d819b39d8 100644 --- a/cmd/agent/subcommands/dogstatsd/command.go +++ b/cmd/agent/subcommands/dogstatsd/command.go @@ -22,8 +22,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" cconfig "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -53,7 +52,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(&topFlags), fx.Supply(core.BundleParams{ ConfigParams: cconfig.NewAgentParams(globalParams.ConfFilePath, cconfig.WithExtraConfFiles(globalParams.ExtraConfFilePath)), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, @@ -71,7 +70,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { return fxutil.OneShot(dumpContexts, fx.Supply(core.BundleParams{ ConfigParams: cconfig.NewAgentParams(globalParams.ConfFilePath, cconfig.WithExtraConfFiles(globalParams.ExtraConfFilePath)), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/cmd/agent/subcommands/dogstatsdcapture/command.go b/cmd/agent/subcommands/dogstatsdcapture/command.go index 16f095df9d346..d6de4a8f533d5 100644 --- a/cmd/agent/subcommands/dogstatsdcapture/command.go +++ b/cmd/agent/subcommands/dogstatsdcapture/command.go @@ -18,7 +18,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/security" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/core" diff --git a/cmd/agent/subcommands/dogstatsdreplay/command.go b/cmd/agent/subcommands/dogstatsdreplay/command.go index 7f8bab3b7a46a..a9cc58161a6db 100644 --- a/cmd/agent/subcommands/dogstatsdreplay/command.go +++ b/cmd/agent/subcommands/dogstatsdreplay/command.go @@ -23,7 +23,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" replay "github.com/DataDog/datadog-agent/comp/dogstatsd/replay/impl" "github.com/DataDog/datadog-agent/pkg/api/security" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" diff --git a/cmd/agent/subcommands/dogstatsdstats/command.go b/cmd/agent/subcommands/dogstatsdstats/command.go index 58415338fdbb6..80b786a3a64c4 100644 --- a/cmd/agent/subcommands/dogstatsdstats/command.go +++ b/cmd/agent/subcommands/dogstatsdstats/command.go @@ -17,7 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug/serverdebugimpl" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" diff --git a/cmd/agent/subcommands/flare/command.go b/cmd/agent/subcommands/flare/command.go index df8cb545be1a8..603e6daddac46 100644 --- a/cmd/agent/subcommands/flare/command.go +++ b/cmd/agent/subcommands/flare/command.go @@ -33,8 +33,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare" "github.com/DataDog/datadog-agent/comp/core/flare/helpers" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" @@ -105,7 +104,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { ConfigParams: config, SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.SysProbeConfFilePath)), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", false), + LogParams: log.ForOneShot(command.LoggerName, "off", false), }), fx.Supply(flare.NewLocalParams( commonpath.GetDistPath(), diff --git a/cmd/agent/subcommands/hostname/command.go b/cmd/agent/subcommands/hostname/command.go index 417e1f78e9094..6861f8589c498 100644 --- a/cmd/agent/subcommands/hostname/command.go +++ b/cmd/agent/subcommands/hostname/command.go @@ -16,8 +16,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/hostname" ) @@ -41,7 +40,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", false)}), // never output anything but hostname + LogParams: log.ForOneShot(command.LoggerName, "off", false)}), // never output anything but hostname core.Bundle(), ) }, diff --git a/cmd/agent/subcommands/integrations/command.go b/cmd/agent/subcommands/integrations/command.go index 84640011f6227..eb296b467f7cd 100644 --- a/cmd/agent/subcommands/integrations/command.go +++ b/cmd/agent/subcommands/integrations/command.go @@ -26,8 +26,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/util/executable" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -114,7 +113,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithConfigMissingOK(true), config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true), + LogParams: log.ForOneShot(command.LoggerName, "off", true), }), core.Bundle(), ) diff --git a/cmd/agent/subcommands/jmx/command.go b/cmd/agent/subcommands/jmx/command.go index 8e86f8f8ad486..5231c6064e7da 100644 --- a/cmd/agent/subcommands/jmx/command.go +++ b/cmd/agent/subcommands/jmx/command.go @@ -39,7 +39,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery/autodiscoveryimpl" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/settings/settingsimpl" @@ -118,7 +118,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { params := core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, cliParams.jmxLogLevel, false)} + LogParams: log.ForOneShot(command.LoggerName, cliParams.jmxLogLevel, false)} if cliParams.logFile != "" { params.LogParams.LogToFile(cliParams.logFile) } diff --git a/cmd/agent/subcommands/launchgui/command.go b/cmd/agent/subcommands/launchgui/command.go index 6eb7def5d0c94..56dc9bbc60b84 100644 --- a/cmd/agent/subcommands/launchgui/command.go +++ b/cmd/agent/subcommands/launchgui/command.go @@ -15,7 +15,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" apiutil "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/cmd/agent/subcommands/processchecks/command.go b/cmd/agent/subcommands/processchecks/command.go index f2d926c00802d..c0512ca1738e6 100644 --- a/cmd/agent/subcommands/processchecks/command.go +++ b/cmd/agent/subcommands/processchecks/command.go @@ -12,12 +12,12 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" processCommand "github.com/DataDog/datadog-agent/cmd/process-agent/command" "github.com/DataDog/datadog-agent/cmd/process-agent/subcommands/check" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ) // Commands returns a slice of subcommands for the 'agent' command. func Commands(globalParams *command.GlobalParams) []*cobra.Command { - processCommand.OneShotLogParams = logimpl.ForOneShot(string(command.LoggerName), "info", true) + processCommand.OneShotLogParams = log.ForOneShot(string(command.LoggerName), "info", true) checkAllowlist := []string{"process", "rtprocess", "container", "rtcontainer", "process_discovery"} cmd := check.MakeCommand(func() *processCommand.GlobalParams { return &processCommand.GlobalParams{ diff --git a/cmd/agent/subcommands/run/command.go b/cmd/agent/subcommands/run/command.go index 2bdf13cff407d..9f46e9d2fd8e8 100644 --- a/cmd/agent/subcommands/run/command.go +++ b/cmd/agent/subcommands/run/command.go @@ -56,8 +56,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/flare" "github.com/DataDog/datadog-agent/comp/core/gui" "github.com/DataDog/datadog-agent/comp/core/gui/guiimpl" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/pid" "github.com/DataDog/datadog-agent/comp/core/pid/pidimpl" "github.com/DataDog/datadog-agent/comp/process" @@ -182,7 +181,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(cliParams.ExtraConfFilePath)), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.SysProbeConfFilePath)), - LogParams: logimpl.ForDaemon(command.LoggerName, "log_file", path.DefaultLogFile), + LogParams: log.ForDaemon(command.LoggerName, "log_file", path.DefaultLogFile), }), fx.Supply(pidimpl.NewParams(cliParams.pidfilePath)), getSharedFxOption(), diff --git a/cmd/agent/subcommands/run/command_windows.go b/cmd/agent/subcommands/run/command_windows.go index 138e63e3c0749..c22ee79332ce1 100644 --- a/cmd/agent/subcommands/run/command_windows.go +++ b/cmd/agent/subcommands/run/command_windows.go @@ -48,8 +48,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare" "github.com/DataDog/datadog-agent/comp/core/gui" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/status" @@ -187,7 +186,7 @@ func StartAgentWithDefaults(ctxChan <-chan context.Context) (<-chan error, error ConfigParams: config.NewAgentParams(""), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(), - LogParams: logimpl.ForDaemon(command.LoggerName, "log_file", path.DefaultLogFile), + LogParams: log.ForDaemon(command.LoggerName, "log_file", path.DefaultLogFile), }), getSharedFxOption(), getPlatformModules(), diff --git a/cmd/agent/subcommands/secret/command.go b/cmd/agent/subcommands/secret/command.go index 2787da7f999dc..62f1381200b67 100644 --- a/cmd/agent/subcommands/secret/command.go +++ b/cmd/agent/subcommands/secret/command.go @@ -15,7 +15,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" apiutil "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/cmd/agent/subcommands/snmp/command.go b/cmd/agent/subcommands/snmp/command.go index 459b14a97ee7d..80d2b4cd0ef42 100644 --- a/cmd/agent/subcommands/snmp/command.go +++ b/cmd/agent/subcommands/snmp/command.go @@ -27,8 +27,7 @@ import ( "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/forwarder" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" @@ -141,7 +140,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) if err != nil { @@ -188,7 +187,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), aggregator.Bundle(), forwarder.Bundle(), diff --git a/cmd/agent/subcommands/status/command.go b/cmd/agent/subcommands/status/command.go index 599d18601e09e..8548f87731dbe 100644 --- a/cmd/agent/subcommands/status/command.go +++ b/cmd/agent/subcommands/status/command.go @@ -19,8 +19,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" apiutil "github.com/DataDog/datadog-agent/pkg/api/util" @@ -70,7 +69,7 @@ The --list flag can be used to list all available status sections.`, fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithExtraConfFiles(globalParams.ExtraConfFilePath)), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.SysProbeConfFilePath)), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/cmd/agent/subcommands/stop/command.go b/cmd/agent/subcommands/stop/command.go index d0eb84d9fbaf4..e1a1c79f717b1 100644 --- a/cmd/agent/subcommands/stop/command.go +++ b/cmd/agent/subcommands/stop/command.go @@ -18,7 +18,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/cmd/agent/subcommands/streamep/command.go b/cmd/agent/subcommands/streamep/command.go index 8ed6a6c2bc471..a4bc2f6e3cfd8 100644 --- a/cmd/agent/subcommands/streamep/command.go +++ b/cmd/agent/subcommands/streamep/command.go @@ -18,7 +18,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/logs/diagnostic" diff --git a/cmd/agent/subcommands/streamlogs/command.go b/cmd/agent/subcommands/streamlogs/command.go index 3966755c6d093..14a8b57feb629 100644 --- a/cmd/agent/subcommands/streamlogs/command.go +++ b/cmd/agent/subcommands/streamlogs/command.go @@ -21,7 +21,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/logs/diagnostic" diff --git a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go index b6420ff4beeb0..d1443b6e60137 100644 --- a/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go +++ b/cmd/cluster-agent-cloudfoundry/subcommands/run/command.go @@ -35,8 +35,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" healthprobe "github.com/DataDog/datadog-agent/comp/core/healthprobe/def" healthprobefx "github.com/DataDog/datadog-agent/comp/core/healthprobe/fx" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/settings/settingsimpl" @@ -81,7 +80,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForDaemon(command.LoggerName, "log_file", path.DefaultDCALogFile), + LogParams: log.ForDaemon(command.LoggerName, "log_file", path.DefaultDCALogFile), }), core.Bundle(), forwarder.Bundle(), diff --git a/cmd/cluster-agent/subcommands/compliance/command.go b/cmd/cluster-agent/subcommands/compliance/command.go index facc46171e684..240a0563149d9 100644 --- a/cmd/cluster-agent/subcommands/compliance/command.go +++ b/cmd/cluster-agent/subcommands/compliance/command.go @@ -15,7 +15,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/subcommands/check" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ) // Commands returns a slice of subcommands for the 'cluster-agent' command. @@ -29,7 +29,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { bundleParams := core.BundleParams{ ConfigParams: config.NewClusterAgentParams(""), - LogParams: logimpl.ForOneShot(command.LoggerName, command.DefaultLogLevel, true), + LogParams: log.ForOneShot(command.LoggerName, command.DefaultLogLevel, true), } complianceCmd.AddCommand(check.ClusterAgentCommands(bundleParams)...) diff --git a/cmd/cluster-agent/subcommands/diagnose/command.go b/cmd/cluster-agent/subcommands/diagnose/command.go index 4defa2b272d92..d03b3cbe77326 100644 --- a/cmd/cluster-agent/subcommands/diagnose/command.go +++ b/cmd/cluster-agent/subcommands/diagnose/command.go @@ -16,7 +16,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/cluster-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/diagnose" @@ -34,7 +34,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true), // no need to show regular logs + LogParams: log.ForOneShot(command.LoggerName, "off", true), // no need to show regular logs }), core.Bundle(), compressionimpl.Module(), diff --git a/cmd/cluster-agent/subcommands/metamap/command.go b/cmd/cluster-agent/subcommands/metamap/command.go index c9d0f1223763a..7fb679872d4c7 100644 --- a/cmd/cluster-agent/subcommands/metamap/command.go +++ b/cmd/cluster-agent/subcommands/metamap/command.go @@ -17,8 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/cluster-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -48,7 +47,7 @@ as well as which services are serving the pods. Or the deployment name for the p fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, command.DefaultLogLevel, true), + LogParams: log.ForOneShot(command.LoggerName, command.DefaultLogLevel, true), }), core.Bundle(), ) diff --git a/cmd/cluster-agent/subcommands/start/command.go b/cmd/cluster-agent/subcommands/start/command.go index 142f6e340072f..d72b7fa968c75 100644 --- a/cmd/cluster-agent/subcommands/start/command.go +++ b/cmd/cluster-agent/subcommands/start/command.go @@ -40,8 +40,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" healthprobe "github.com/DataDog/datadog-agent/comp/core/healthprobe/def" healthprobefx "github.com/DataDog/datadog-agent/comp/core/healthprobe/fx" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/settings/settingsimpl" @@ -130,7 +129,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForDaemon(command.LoggerName, "log_file", path.DefaultDCALogFile), + LogParams: log.ForDaemon(command.LoggerName, "log_file", path.DefaultDCALogFile), }), core.Bundle(), forwarder.Bundle(), diff --git a/cmd/cluster-agent/subcommands/status/command.go b/cmd/cluster-agent/subcommands/status/command.go index 9c5081785ef46..4078077306ec0 100644 --- a/cmd/cluster-agent/subcommands/status/command.go +++ b/cmd/cluster-agent/subcommands/status/command.go @@ -21,8 +21,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/cluster-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -48,7 +47,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, command.DefaultLogLevel, true), + LogParams: log.ForOneShot(command.LoggerName, command.DefaultLogLevel, true), }), core.Bundle(), ) diff --git a/cmd/dogstatsd/main_windows.go b/cmd/dogstatsd/main_windows.go index 489350dfdb232..9c01ecc933530 100644 --- a/cmd/dogstatsd/main_windows.go +++ b/cmd/dogstatsd/main_windows.go @@ -15,7 +15,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/dogstatsd/subcommands/start" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" dogstatsdServer "github.com/DataDog/datadog-agent/comp/dogstatsd/server" "github.com/DataDog/datadog-agent/pkg/util/flavor" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" diff --git a/cmd/dogstatsd/subcommands/start/command.go b/cmd/dogstatsd/subcommands/start/command.go index 663593dda4073..caa220e25e6dc 100644 --- a/cmd/dogstatsd/subcommands/start/command.go +++ b/cmd/dogstatsd/subcommands/start/command.go @@ -25,8 +25,8 @@ import ( healthprobe "github.com/DataDog/datadog-agent/comp/core/healthprobe/def" healthprobefx "github.com/DataDog/datadog-agent/comp/core/healthprobe/fx" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log" - logComponent "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logfx "github.com/DataDog/datadog-agent/comp/core/log/fx" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" @@ -123,9 +123,9 @@ func RunDogstatsdFct(cliParams *CLIParams, defaultConfPath string, defaultLogFil }), fx.Supply(secrets.NewEnabledParams()), telemetryimpl.Module(), - fx.Supply(logComponent.ForDaemon(string(loggerName), "log_file", params.DefaultLogFile)), + fx.Supply(log.ForDaemon(string(loggerName), "log_file", params.DefaultLogFile)), config.Module(), - logComponent.Module(), + logfx.Module(), fx.Supply(dogstatsdServer.Params{ Serverless: false, }), diff --git a/cmd/installer/subcommands/daemon/api.go b/cmd/installer/subcommands/daemon/api.go index c4100be76e7b6..7d65c1710038a 100644 --- a/cmd/installer/subcommands/daemon/api.go +++ b/cmd/installer/subcommands/daemon/api.go @@ -12,7 +12,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/installer/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/comp/updater/localapiclient" @@ -100,7 +100,7 @@ func experimentFxWrapper(f interface{}, params *cliParams) error { ConfigParams: config.NewAgentParams(params.ConfFilePath), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(), - LogParams: logimpl.ForOneShot("INSTALLER", "off", true), + LogParams: log.ForOneShot("INSTALLER", "off", true), }), core.Bundle(), fx.Supply(params), diff --git a/cmd/installer/subcommands/daemon/run.go b/cmd/installer/subcommands/daemon/run.go index 186faf0c3aa53..f9b0b0f93c1d7 100644 --- a/cmd/installer/subcommands/daemon/run.go +++ b/cmd/installer/subcommands/daemon/run.go @@ -7,13 +7,14 @@ package daemon import ( "context" + "github.com/spf13/cobra" "go.uber.org/fx" "github.com/DataDog/datadog-agent/cmd/installer/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/pid/pidimpl" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" @@ -47,7 +48,7 @@ func getCommonFxOption(global *command.GlobalParams) fx.Option { ConfigParams: config.NewAgentParams(global.ConfFilePath), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(), - LogParams: logimpl.ForDaemon("INSTALLER", "installer.log_file", pkgconfig.DefaultUpdaterLogFile), + LogParams: log.ForDaemon("INSTALLER", "installer.log_file", pkgconfig.DefaultUpdaterLogFile), }), core.Bundle(), fx.Supply(&rcservice.Params{ diff --git a/cmd/installer/subcommands/daemon/status.go b/cmd/installer/subcommands/daemon/status.go index 74816a8e1a4e7..a8254455716aa 100644 --- a/cmd/installer/subcommands/daemon/status.go +++ b/cmd/installer/subcommands/daemon/status.go @@ -14,7 +14,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/installer/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/comp/updater/localapiclient" @@ -44,7 +44,7 @@ func statusFxWrapper(global *command.GlobalParams) error { ConfigParams: config.NewAgentParams(global.ConfFilePath), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(), - LogParams: logimpl.ForOneShot("INSTALLER", "off", true), + LogParams: log.ForOneShot("INSTALLER", "off", true), }), core.Bundle(), localapiclientimpl.Module(), diff --git a/cmd/installer/subcommands/installer/command.go b/cmd/installer/subcommands/installer/command.go index a84d0809c83eb..32ba5484edd54 100644 --- a/cmd/installer/subcommands/installer/command.go +++ b/cmd/installer/subcommands/installer/command.go @@ -78,6 +78,7 @@ func newCmd(operation string) *cmd { env := env.FromEnv() t := newTelemetry(env) span, ctx := newSpan(operation) + setInstallerUmask(span) return &cmd{ t: t, ctx: ctx, diff --git a/cmd/installer/subcommands/installer/umask_nix.go b/cmd/installer/subcommands/installer/umask_nix.go new file mode 100644 index 0000000000000..b4062c09a4f77 --- /dev/null +++ b/cmd/installer/subcommands/installer/umask_nix.go @@ -0,0 +1,20 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build !windows + +package installer + +import ( + "syscall" + + "gopkg.in/DataDog/dd-trace-go.v1/ddtrace" +) + +// setInstallerUmask sets umask 0 to override any inherited umask +func setInstallerUmask(span ddtrace.Span) { + oldmask := syscall.Umask(0) + span.SetTag("inherited_umask", oldmask) +} diff --git a/comp/core/log/component_mock.go b/cmd/installer/subcommands/installer/umask_windows.go similarity index 59% rename from comp/core/log/component_mock.go rename to cmd/installer/subcommands/installer/umask_windows.go index afdf54ce4e470..3d308c67cc318 100644 --- a/comp/core/log/component_mock.go +++ b/cmd/installer/subcommands/installer/umask_windows.go @@ -3,13 +3,13 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -//go:build test +//go:build windows -package log +package installer -// Mock is the mocked component type. -type Mock interface { - Component +import ( + "gopkg.in/DataDog/dd-trace-go.v1/ddtrace" +) - // no further methods are defined. -} +// setInstallerUmask no-op on Windows +func setInstallerUmask(_ ddtrace.Span) {} diff --git a/cmd/otel-agent/subcommands/run/command.go b/cmd/otel-agent/subcommands/run/command.go index 58202841af672..1c330439acf77 100644 --- a/cmd/otel-agent/subcommands/run/command.go +++ b/cmd/otel-agent/subcommands/run/command.go @@ -20,9 +20,8 @@ import ( coreconfig "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface" "github.com/DataDog/datadog-agent/comp/core/hostname/remotehostnameimpl" - corelog "github.com/DataDog/datadog-agent/comp/core/log" - corelogimpl "github.com/DataDog/datadog-agent/comp/core/log/logimpl" - "github.com/DataDog/datadog-agent/comp/core/log/tracelogimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logtracefx "github.com/DataDog/datadog-agent/comp/core/log/fx-trace" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/tagger" @@ -56,7 +55,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/trace/telemetry" "github.com/DataDog/datadog-agent/pkg/util/fxutil" - "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/optional" "go.uber.org/fx" @@ -96,7 +94,7 @@ func (o *orchestratorinterfaceimpl) Reset() { func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams, opts ...fx.Option) error { err := fxutil.Run( forwarder.Bundle(), - tracelogimpl.Module(), // cannot have corelogimpl and tracelogimpl at the same time + logtracefx.Module(), inventoryagentimpl.Module(), workloadmetafx.Module(), fx.Supply(metricsclient.NewStatsdClientWrapper(&ddgostatsd.NoOpClient{})), @@ -132,8 +130,8 @@ func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams, remotehostnameimpl.Module(), fx.Supply(optional.NewNoneOption[secrets.Component]()), - fx.Provide(func(c coreconfig.Component) corelogimpl.Params { - return corelogimpl.ForDaemon(params.LoggerName, "log_file", pkgconfigsetup.DefaultOTelAgentLogFile) + fx.Provide(func(c coreconfig.Component) log.Params { + return log.ForDaemon(params.LoggerName, "log_file", pkgconfigsetup.DefaultOTelAgentLogFile) }), logsagentpipelineimpl.Module(), // We create strategy.ZlibStrategy directly to avoid build tags @@ -146,12 +144,12 @@ func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams, fx.Provide(func(s *serializer.Serializer) serializer.MetricSerializer { return s }), - fx.Provide(func(h serializerexporter.SourceProviderFunc) (string, error) { + fx.Provide(func(h serializerexporter.SourceProviderFunc, l log.Component) (string, error) { hn, err := h(context.Background()) if err != nil { return "", err } - log.Info("Using ", "hostname", hn) + l.Info("Using ", "hostname", hn) return hn, nil }), @@ -189,6 +187,6 @@ func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams, return nil } -func newForwarderParams(config coreconfig.Component, log corelog.Component) defaultforwarder.Params { - return defaultforwarder.NewParams(config, log) +func newForwarderParams(config coreconfig.Component, l log.Component) defaultforwarder.Params { + return defaultforwarder.NewParams(config, l) } diff --git a/cmd/process-agent/api/server.go b/cmd/process-agent/api/server.go index 9ddf88d97ddb8..4c599ed6a2b0b 100644 --- a/cmd/process-agent/api/server.go +++ b/cmd/process-agent/api/server.go @@ -12,7 +12,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/status" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" diff --git a/cmd/process-agent/command/command.go b/cmd/process-agent/command/command.go index 2ed2b0c3fcafe..e931ba00151b2 100644 --- a/cmd/process-agent/command/command.go +++ b/cmd/process-agent/command/command.go @@ -15,8 +15,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/process-agent/flags" "github.com/DataDog/datadog-agent/comp/core" configComponent "github.com/DataDog/datadog-agent/comp/core/config" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" - logComponentimpl "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/pkg/config" @@ -27,10 +26,10 @@ import ( const LoggerName config.LoggerName = "PROCESS" // DaemonLogParams are the log params should be given to the `core.BundleParams` for when the process agent is running as a daemon -var DaemonLogParams = logComponentimpl.ForDaemon(string(LoggerName), "process_config.log_file", config.DefaultProcessAgentLogFile) +var DaemonLogParams = log.ForDaemon(string(LoggerName), "process_config.log_file", config.DefaultProcessAgentLogFile) // OneShotLogParams are the log params that are given to commands -var OneShotLogParams = logComponentimpl.ForOneShot(string(LoggerName), "info", true) +var OneShotLogParams = log.ForOneShot(string(LoggerName), "info", true) // GlobalParams contains the values of agent-global Cobra flags. // @@ -122,7 +121,7 @@ func MakeCommand(subcommandFactories []SubcommandFactory, winParams bool, rootCm } // SetHostMountEnv sets HOST_PROC and HOST_SYS mounts if applicable in containerized environments -func SetHostMountEnv(logger logComponent.Component) { +func SetHostMountEnv(logger log.Component) { // Set default values for proc/sys paths if unset. // Generally only applicable for container-only cases like Fargate. // This is primarily used by gopsutil to correlate cpu metrics with host processes diff --git a/cmd/process-agent/command/main_common.go b/cmd/process-agent/command/main_common.go index b4ad016778cfb..1af3a676f263a 100644 --- a/cmd/process-agent/command/main_common.go +++ b/cmd/process-agent/command/main_common.go @@ -21,7 +21,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/configsync" "github.com/DataDog/datadog-agent/comp/core/configsync/configsyncimpl" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + logcomp "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/pid" "github.com/DataDog/datadog-agent/comp/core/pid/pidimpl" "github.com/DataDog/datadog-agent/comp/core/secrets" @@ -96,7 +96,7 @@ func runApp(ctx context.Context, globalParams *GlobalParams) error { var appInitDeps struct { fx.In - Logger logComponent.Component + Logger logcomp.Component Checks []types.CheckComponent `group:"check"` Syscfg sysprobeconfig.Component @@ -196,6 +196,9 @@ func runApp(ctx context.Context, globalParams *GlobalParams) error { // Allows for debug logging of fx components if the `TRACE_FX` environment variable is set fxutil.FxLoggingOption(), + // Inject the Lifecycle adapter for non fx-aware components. + fxutil.FxLifecycleAdapter(), + // Set the pid file path fx.Supply(pidimpl.NewParams(globalParams.PidFilePath)), @@ -306,7 +309,7 @@ type miscDeps struct { Syscfg sysprobeconfig.Component HostInfo hostinfo.Component WorkloadMeta workloadmeta.Component - Logger logComponent.Component + Logger logcomp.Component } // initMisc initializes modules that cannot, or have not yet been componetized. diff --git a/cmd/process-agent/subcommands/check/check.go b/cmd/process-agent/subcommands/check/check.go index 7acb6854e2dcf..80a846fd6404c 100644 --- a/cmd/process-agent/subcommands/check/check.go +++ b/cmd/process-agent/subcommands/check/check.go @@ -24,8 +24,7 @@ import ( sysconfig "github.com/DataDog/datadog-agent/cmd/system-probe/config" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" @@ -113,7 +112,7 @@ func MakeCommand(globalParamsGetter func() *command.GlobalParams, name string, a // Disable logging if `--json` is specified. This way the check command will output proper json. if cliParams.checkOutputJSON { - bundleParams.LogParams = logimpl.ForOneShot(string(command.LoggerName), "off", true) + bundleParams.LogParams = log.ForOneShot(string(command.LoggerName), "off", true) } return fxutil.OneShot(RunCheckCmd, diff --git a/cmd/process-agent/subcommands/events/events.go b/cmd/process-agent/subcommands/events/events.go index 216d4d7a5f078..8b9bbddf9eb5c 100644 --- a/cmd/process-agent/subcommands/events/events.go +++ b/cmd/process-agent/subcommands/events/events.go @@ -21,7 +21,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/process-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/process" "github.com/DataDog/datadog-agent/pkg/process/checks" diff --git a/cmd/process-agent/subcommands/status/status.go b/cmd/process-agent/subcommands/status/status.go index 0060c3fdf83bf..207506612455d 100644 --- a/cmd/process-agent/subcommands/status/status.go +++ b/cmd/process-agent/subcommands/status/status.go @@ -18,7 +18,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/process-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" compStatus "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/process" apiutil "github.com/DataDog/datadog-agent/pkg/api/util" diff --git a/cmd/process-agent/subcommands/taggerlist/tagger_list.go b/cmd/process-agent/subcommands/taggerlist/tagger_list.go index 9ce8fc1623266..4f48106d723c7 100644 --- a/cmd/process-agent/subcommands/taggerlist/tagger_list.go +++ b/cmd/process-agent/subcommands/taggerlist/tagger_list.go @@ -16,7 +16,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/process-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl/api" ddconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/cmd/process-agent/subcommands/workloadlist/command.go b/cmd/process-agent/subcommands/workloadlist/command.go index faf0436571405..b443660cc25d3 100644 --- a/cmd/process-agent/subcommands/workloadlist/command.go +++ b/cmd/process-agent/subcommands/workloadlist/command.go @@ -17,7 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/process-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/api/util" ddconfig "github.com/DataDog/datadog-agent/pkg/config" diff --git a/cmd/security-agent/main_windows.go b/cmd/security-agent/main_windows.go index 44c471d67eb2a..918ad97119cc5 100644 --- a/cmd/security-agent/main_windows.go +++ b/cmd/security-agent/main_windows.go @@ -29,8 +29,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/configsync" "github.com/DataDog/datadog-agent/comp/core/configsync/configsyncimpl" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/settings/settingsimpl" @@ -109,7 +108,7 @@ func (s *service) Run(svcctx context.Context) error { ConfigParams: config.NewSecurityAgentParams(defaultSecurityAgentConfigFilePaths), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(defaultSysProbeConfPath)), - LogParams: logimpl.ForDaemon(command.LoggerName, "security_agent.log_file", setup.DefaultSecurityAgentLogFile), + LogParams: log.ForDaemon(command.LoggerName, "security_agent.log_file", setup.DefaultSecurityAgentLogFile), }), core.Bundle(), dogstatsd.ClientBundle, diff --git a/cmd/security-agent/subcommands/check/command.go b/cmd/security-agent/subcommands/check/command.go index 5fdddcd8fc169..7173c533ea0bf 100644 --- a/cmd/security-agent/subcommands/check/command.go +++ b/cmd/security-agent/subcommands/check/command.go @@ -26,8 +26,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/comp/dogstatsd" @@ -63,7 +62,7 @@ func SecurityAgentCommands(globalParams *command.GlobalParams) []*cobra.Command ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.SysProbeConfFilePath)), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true), + LogParams: log.ForOneShot(command.LoggerName, "info", true), } }) } @@ -87,7 +86,7 @@ func commandsWrapped(bundleParamsFactory func() core.BundleParams) []*cobra.Comm bundleParams := bundleParamsFactory() if checkArgs.verbose { - bundleParams.LogParams = logimpl.ForOneShot(bundleParams.LogParams.LoggerName(), "trace", true) + bundleParams.LogParams = log.ForOneShot(bundleParams.LogParams.LoggerName(), "trace", true) } return fxutil.OneShot(RunCheck, diff --git a/cmd/security-agent/subcommands/compliance/command.go b/cmd/security-agent/subcommands/compliance/command.go index 314eabbcde85c..251a56c525094 100644 --- a/cmd/security-agent/subcommands/compliance/command.go +++ b/cmd/security-agent/subcommands/compliance/command.go @@ -22,8 +22,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/subcommands/check" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/compliance" "github.com/DataDog/datadog-agent/pkg/compliance/aptconfig" @@ -80,7 +79,7 @@ func complianceLoadCommand(globalParams *command.GlobalParams) *cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true), + LogParams: log.ForOneShot(command.LoggerName, "info", true), }), core.Bundle(), ) @@ -158,7 +157,7 @@ func complianceEventCommand(globalParams *command.GlobalParams) *cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true), + LogParams: log.ForOneShot(command.LoggerName, "info", true), }), core.Bundle(), ) diff --git a/cmd/security-agent/subcommands/compliance/compliance.go b/cmd/security-agent/subcommands/compliance/compliance.go index 46a0f0e9cfff4..f37f90613d3c4 100644 --- a/cmd/security-agent/subcommands/compliance/compliance.go +++ b/cmd/security-agent/subcommands/compliance/compliance.go @@ -14,7 +14,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/comp/dogstatsd/constants" diff --git a/cmd/security-agent/subcommands/config/config.go b/cmd/security-agent/subcommands/config/config.go index 889c7592e17ac..6297a15892d81 100644 --- a/cmd/security-agent/subcommands/config/config.go +++ b/cmd/security-agent/subcommands/config/config.go @@ -17,8 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -60,7 +59,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, @@ -78,7 +77,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, @@ -98,7 +97,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, @@ -118,7 +117,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, @@ -138,7 +137,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/flare/command.go b/cmd/security-agent/subcommands/flare/command.go index c756b6026e164..b3bedf1cfda68 100644 --- a/cmd/security-agent/subcommands/flare/command.go +++ b/cmd/security-agent/subcommands/flare/command.go @@ -18,8 +18,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare/helpers" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/flare" @@ -56,7 +55,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths, config.WithIgnoreErrors(true)), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/runtime/activity_dump.go b/cmd/security-agent/subcommands/runtime/activity_dump.go index 9ebf4f235f554..3ec664f0c22ad 100644 --- a/cmd/security-agent/subcommands/runtime/activity_dump.go +++ b/cmd/security-agent/subcommands/runtime/activity_dump.go @@ -18,8 +18,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" secagent "github.com/DataDog/datadog-agent/pkg/security/agent" secconfig "github.com/DataDog/datadog-agent/pkg/security/config" @@ -68,7 +67,7 @@ func listCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -91,7 +90,7 @@ func stopCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -138,7 +137,7 @@ func generateEncodingCommands(globalParams *command.GlobalParams) []*cobra.Comma fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -205,7 +204,7 @@ func diffCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/runtime/command.go b/cmd/security-agent/subcommands/runtime/command.go index fd06c072d50c8..71d8219c28780 100644 --- a/cmd/security-agent/subcommands/runtime/command.go +++ b/cmd/security-agent/subcommands/runtime/command.go @@ -30,8 +30,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -100,7 +99,7 @@ func evalCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", false)}), + LogParams: log.ForOneShot(command.LoggerName, "off", false)}), core.Bundle(), ) }, @@ -133,7 +132,7 @@ func commonCheckPoliciesCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", false)}), + LogParams: log.ForOneShot(command.LoggerName, "off", false)}), core.Bundle(), ) }, @@ -157,7 +156,7 @@ func commonReloadPoliciesCommands(globalParams *command.GlobalParams) []*cobra.C fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -175,7 +174,7 @@ func selfTestCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -206,7 +205,7 @@ func downloadPolicyCommands(globalParams *command.GlobalParams) []*cobra.Command fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", false)}), + LogParams: log.ForOneShot(command.LoggerName, "off", false)}), core.Bundle(), ) }, @@ -241,7 +240,7 @@ func processCacheCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -279,7 +278,7 @@ func networkNamespaceCommands(globalParams *command.GlobalParams) []*cobra.Comma fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -306,7 +305,7 @@ func discardersCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/runtime/command_unsupported.go b/cmd/security-agent/subcommands/runtime/command_unsupported.go index 8d52b6b079477..83f7a48273788 100644 --- a/cmd/security-agent/subcommands/runtime/command_unsupported.go +++ b/cmd/security-agent/subcommands/runtime/command_unsupported.go @@ -15,7 +15,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" secagent "github.com/DataDog/datadog-agent/pkg/security/agent" "github.com/DataDog/datadog-agent/pkg/util/startstop" diff --git a/cmd/security-agent/subcommands/runtime/deprecated_commands.go b/cmd/security-agent/subcommands/runtime/deprecated_commands.go index bcd5df3709b0d..c2e733fdbc12f 100644 --- a/cmd/security-agent/subcommands/runtime/deprecated_commands.go +++ b/cmd/security-agent/subcommands/runtime/deprecated_commands.go @@ -14,7 +14,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -35,7 +35,7 @@ func checkPoliciesCommands(globalParams *command.GlobalParams) []*cobra.Command fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", false)}), + LogParams: log.ForOneShot(command.LoggerName, "off", false)}), core.Bundle(), ) }, @@ -57,7 +57,7 @@ func reloadPoliciesCommands(globalParams *command.GlobalParams) []*cobra.Command fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/runtime/security_profile.go b/cmd/security-agent/subcommands/runtime/security_profile.go index 92e055044bbc4..3884444f973e9 100644 --- a/cmd/security-agent/subcommands/runtime/security_profile.go +++ b/cmd/security-agent/subcommands/runtime/security_profile.go @@ -17,8 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" secagent "github.com/DataDog/datadog-agent/pkg/security/agent" "github.com/DataDog/datadog-agent/pkg/security/proto/api" @@ -63,7 +62,7 @@ func securityProfileShowCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -109,7 +108,7 @@ func listSecurityProfileCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, @@ -216,7 +215,7 @@ func saveSecurityProfileCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "info", true)}), + LogParams: log.ForOneShot(command.LoggerName, "info", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/start/command.go b/cmd/security-agent/subcommands/start/command.go index 44765f3d9cf2d..5e18c86b8f93a 100644 --- a/cmd/security-agent/subcommands/start/command.go +++ b/cmd/security-agent/subcommands/start/command.go @@ -34,8 +34,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/configsync" "github.com/DataDog/datadog-agent/comp/core/configsync/configsyncimpl" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/pid" "github.com/DataDog/datadog-agent/comp/core/pid/pidimpl" "github.com/DataDog/datadog-agent/comp/core/secrets" @@ -98,7 +97,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { ConfigParams: config.NewSecurityAgentParams(params.ConfigFilePaths), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.SysProbeConfFilePath)), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForDaemon(command.LoggerName, "security_agent.log_file", setup.DefaultSecurityAgentLogFile), + LogParams: log.ForDaemon(command.LoggerName, "security_agent.log_file", setup.DefaultSecurityAgentLogFile), }), core.Bundle(), dogstatsd.ClientBundle, diff --git a/cmd/security-agent/subcommands/status/command.go b/cmd/security-agent/subcommands/status/command.go index 7579d4acf1eba..69e8c0ecd8c97 100644 --- a/cmd/security-agent/subcommands/status/command.go +++ b/cmd/security-agent/subcommands/status/command.go @@ -19,8 +19,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -50,7 +49,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/version/command.go b/cmd/security-agent/subcommands/version/command.go index 8d1ba044a08b6..bf6bf45409e8f 100644 --- a/cmd/security-agent/subcommands/version/command.go +++ b/cmd/security-agent/subcommands/version/command.go @@ -16,8 +16,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -34,7 +33,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { return fxutil.OneShot(displayVersion, fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true)}), + LogParams: log.ForOneShot(command.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/cmd/security-agent/subcommands/workloadlist/command.go b/cmd/security-agent/subcommands/workloadlist/command.go index 0e4bbf41daef1..b83f8eedac308 100644 --- a/cmd/security-agent/subcommands/workloadlist/command.go +++ b/cmd/security-agent/subcommands/workloadlist/command.go @@ -17,8 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/security-agent/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" @@ -44,7 +43,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewSecurityAgentParams(globalParams.ConfigFilePaths), - LogParams: logimpl.ForOneShot(command.LoggerName, "off", true), + LogParams: log.ForOneShot(command.LoggerName, "off", true), }), core.Bundle(), ) diff --git a/cmd/serverless-init/main.go b/cmd/serverless-init/main.go index dec64407c09ec..b1d28cad4611f 100644 --- a/cmd/serverless-init/main.go +++ b/cmd/serverless-init/main.go @@ -22,7 +22,8 @@ import ( coreconfig "github.com/DataDog/datadog-agent/comp/core/config" healthprobeDef "github.com/DataDog/datadog-agent/comp/core/healthprobe/def" healthprobeFx "github.com/DataDog/datadog-agent/comp/core/healthprobe/fx" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logdef "github.com/DataDog/datadog-agent/comp/core/log/def" + logfx "github.com/DataDog/datadog-agent/comp/core/log/fx" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" "github.com/DataDog/datadog-agent/comp/core/tagger" @@ -82,8 +83,8 @@ func main() { fx.Supply(secrets.NewEnabledParams()), secretsimpl.Module(), fx.Provide(func(secrets secrets.Component) optional.Option[secrets.Component] { return optional.NewOption(secrets) }), - fx.Supply(logimpl.ForOneShot(modeConf.LoggerName, "off", true)), - logimpl.Module(), + fx.Supply(logdef.ForOneShot(modeConf.LoggerName, "off", true)), + logfx.Module(), nooptelemetry.Module(), ) @@ -163,6 +164,8 @@ func setupTraceAgent(tags map[string]string) trace.ServerlessTraceAgent { func setupMetricAgent(tags map[string]string) *metrics.ServerlessMetricAgent { pkgconfig.Datadog().Set("use_v2_api.series", false, model.SourceAgentRuntime) + pkgconfig.Datadog().Set("dogstatsd_socket", "", model.SourceAgentRuntime) + metricAgent := &metrics.ServerlessMetricAgent{ SketchesBucketOffset: time.Second * 0, } diff --git a/cmd/serverless-init/metric/metric_test.go b/cmd/serverless-init/metric/metric_test.go index 2654bef38855c..d842e3efbfd4b 100644 --- a/cmd/serverless-init/metric/metric_test.go +++ b/cmd/serverless-init/metric/metric_test.go @@ -10,11 +10,13 @@ import ( "time" "github.com/stretchr/testify/assert" + "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -63,5 +65,5 @@ func TestAddShutdownMetric(t *testing.T) { } func createDemultiplexer(t *testing.T) demultiplexer.FakeSamplerMock { - return fxutil.Test[demultiplexer.FakeSamplerMock](t, logimpl.MockModule(), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) + return fxutil.Test[demultiplexer.FakeSamplerMock](t, fx.Provide(func() log.Component { return logmock.New(t) }), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) } diff --git a/cmd/serverless/dependencies_linux_amd64.txt b/cmd/serverless/dependencies_linux_amd64.txt index 21d77c2b593f7..ca43a3dc3ec22 100644 --- a/cmd/serverless/dependencies_linux_amd64.txt +++ b/cmd/serverless/dependencies_linux_amd64.txt @@ -72,8 +72,8 @@ github.com/DataDog/datadog-agent/comp/core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface -github.com/DataDog/datadog-agent/comp/core/log -github.com/DataDog/datadog-agent/comp/core/log/logimpl +github.com/DataDog/datadog-agent/comp/core/log/def +github.com/DataDog/datadog-agent/comp/core/log/impl github.com/DataDog/datadog-agent/comp/core/secrets github.com/DataDog/datadog-agent/comp/core/status github.com/DataDog/datadog-agent/comp/core/tagger @@ -156,6 +156,7 @@ github.com/DataDog/datadog-agent/pkg/logs/client/http github.com/DataDog/datadog-agent/pkg/logs/client/tcp github.com/DataDog/datadog-agent/pkg/logs/diagnostic github.com/DataDog/datadog-agent/pkg/logs/internal/decoder +github.com/DataDog/datadog-agent/pkg/logs/internal/decoder/auto_multiline_detection github.com/DataDog/datadog-agent/pkg/logs/internal/framer github.com/DataDog/datadog-agent/pkg/logs/internal/parsers github.com/DataDog/datadog-agent/pkg/logs/internal/parsers/dockerfile @@ -825,6 +826,7 @@ google.golang.org/grpc/backoff google.golang.org/grpc/balancer google.golang.org/grpc/balancer/base google.golang.org/grpc/balancer/grpclb/state +google.golang.org/grpc/balancer/pickfirst google.golang.org/grpc/balancer/roundrobin google.golang.org/grpc/binarylog/grpc_binarylog_v1 google.golang.org/grpc/channelz @@ -847,7 +849,6 @@ google.golang.org/grpc/internal/channelz google.golang.org/grpc/internal/credentials google.golang.org/grpc/internal/envconfig google.golang.org/grpc/internal/grpclog -google.golang.org/grpc/internal/grpcrand google.golang.org/grpc/internal/grpcsync google.golang.org/grpc/internal/grpcutil google.golang.org/grpc/internal/idle @@ -1032,4 +1033,4 @@ vendor/golang.org/x/sys/cpu vendor/golang.org/x/text/secure/bidirule vendor/golang.org/x/text/transform vendor/golang.org/x/text/unicode/bidi -vendor/golang.org/x/text/unicode/norm +vendor/golang.org/x/text/unicode/norm \ No newline at end of file diff --git a/cmd/serverless/dependencies_linux_arm64.txt b/cmd/serverless/dependencies_linux_arm64.txt index 0cf2df1a6dc15..02aec5e28aa8d 100644 --- a/cmd/serverless/dependencies_linux_arm64.txt +++ b/cmd/serverless/dependencies_linux_arm64.txt @@ -72,8 +72,8 @@ github.com/DataDog/datadog-agent/comp/core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface -github.com/DataDog/datadog-agent/comp/core/log -github.com/DataDog/datadog-agent/comp/core/log/logimpl +github.com/DataDog/datadog-agent/comp/core/log/def +github.com/DataDog/datadog-agent/comp/core/log/impl github.com/DataDog/datadog-agent/comp/core/secrets github.com/DataDog/datadog-agent/comp/core/status github.com/DataDog/datadog-agent/comp/core/tagger @@ -156,6 +156,7 @@ github.com/DataDog/datadog-agent/pkg/logs/client/http github.com/DataDog/datadog-agent/pkg/logs/client/tcp github.com/DataDog/datadog-agent/pkg/logs/diagnostic github.com/DataDog/datadog-agent/pkg/logs/internal/decoder +github.com/DataDog/datadog-agent/pkg/logs/internal/decoder/auto_multiline_detection github.com/DataDog/datadog-agent/pkg/logs/internal/framer github.com/DataDog/datadog-agent/pkg/logs/internal/parsers github.com/DataDog/datadog-agent/pkg/logs/internal/parsers/dockerfile @@ -824,6 +825,7 @@ google.golang.org/grpc/backoff google.golang.org/grpc/balancer google.golang.org/grpc/balancer/base google.golang.org/grpc/balancer/grpclb/state +google.golang.org/grpc/balancer/pickfirst google.golang.org/grpc/balancer/roundrobin google.golang.org/grpc/binarylog/grpc_binarylog_v1 google.golang.org/grpc/channelz @@ -846,7 +848,6 @@ google.golang.org/grpc/internal/channelz google.golang.org/grpc/internal/credentials google.golang.org/grpc/internal/envconfig google.golang.org/grpc/internal/grpclog -google.golang.org/grpc/internal/grpcrand google.golang.org/grpc/internal/grpcsync google.golang.org/grpc/internal/grpcutil google.golang.org/grpc/internal/idle @@ -1030,4 +1031,4 @@ vendor/golang.org/x/net/idna vendor/golang.org/x/text/secure/bidirule vendor/golang.org/x/text/transform vendor/golang.org/x/text/unicode/bidi -vendor/golang.org/x/text/unicode/norm +vendor/golang.org/x/text/unicode/norm \ No newline at end of file diff --git a/cmd/serverless/main.go b/cmd/serverless/main.go index 5ee0a8ace9e46..ec123dd2fd3db 100644 --- a/cmd/serverless/main.go +++ b/cmd/serverless/main.go @@ -253,6 +253,9 @@ func setupLambdaAgentOverrides() { flavor.SetFlavor(flavor.ServerlessAgent) config.Datadog().Set("use_v2_api.series", false, model.SourceAgentRuntime) + // TODO(duncanista): figure out how this is used and if it's necessary for Serverless + config.Datadog().Set("dogstatsd_socket", "", model.SourceAgentRuntime) + // Disable remote configuration for now as it just spams the debug logs // and provides no value. os.Setenv("DD_REMOTE_CONFIGURATION_ENABLED", "false") diff --git a/cmd/system-probe/subcommands/config/command.go b/cmd/system-probe/subcommands/config/command.go index 4eefd3aefa65f..ba0bc4c81dc2b 100644 --- a/cmd/system-probe/subcommands/config/command.go +++ b/cmd/system-probe/subcommands/config/command.go @@ -16,7 +16,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/system-probe/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/pkg/api/util" @@ -49,7 +49,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath)), - LogParams: logimpl.ForOneShot("SYS-PROBE", "off", true), + LogParams: log.ForOneShot("SYS-PROBE", "off", true), }), // no need to provide sysprobe logger since ForOneShot ignores config values core.Bundle(), diff --git a/cmd/system-probe/subcommands/debug/command.go b/cmd/system-probe/subcommands/debug/command.go index 8b880914435bb..be595a9406a93 100644 --- a/cmd/system-probe/subcommands/debug/command.go +++ b/cmd/system-probe/subcommands/debug/command.go @@ -18,7 +18,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/system-probe/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/pkg/api/util" @@ -50,7 +50,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath)), - LogParams: logimpl.ForOneShot("SYS-PROBE", "off", false), + LogParams: log.ForOneShot("SYS-PROBE", "off", false), }), // no need to provide sysprobe logger since ForOneShot ignores config values core.Bundle(), diff --git a/cmd/system-probe/subcommands/modrestart/command.go b/cmd/system-probe/subcommands/modrestart/command.go index ba68f880a8353..b10d07211fbc3 100644 --- a/cmd/system-probe/subcommands/modrestart/command.go +++ b/cmd/system-probe/subcommands/modrestart/command.go @@ -17,7 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/system-probe/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -48,7 +48,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath)), - LogParams: logimpl.ForOneShot("SYS-PROBE", "off", false), + LogParams: log.ForOneShot("SYS-PROBE", "off", false), }), // no need to provide sysprobe logger since ForOneShot ignores config values core.Bundle(), diff --git a/cmd/system-probe/subcommands/run/command.go b/cmd/system-probe/subcommands/run/command.go index ee299baaa1c01..efae7d514adb2 100644 --- a/cmd/system-probe/subcommands/run/command.go +++ b/cmd/system-probe/subcommands/run/command.go @@ -33,8 +33,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" healthprobe "github.com/DataDog/datadog-agent/comp/core/healthprobe/def" healthprobefx "github.com/DataDog/datadog-agent/comp/core/healthprobe/fx" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + systemprobeloggerfx "github.com/DataDog/datadog-agent/comp/core/log/fx-systemprobe" "github.com/DataDog/datadog-agent/comp/core/pid" "github.com/DataDog/datadog-agent/comp/core/pid/pidimpl" "github.com/DataDog/datadog-agent/comp/core/secrets" @@ -88,7 +88,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { return fxutil.OneShot(run, fx.Supply(config.NewAgentParams("", config.WithConfigMissingOK(true))), fx.Supply(sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath))), - fx.Supply(logimpl.ForDaemon("SYS-PROBE", "log_file", common.DefaultLogFile)), + fx.Supply(log.ForDaemon("SYS-PROBE", "log_file", common.DefaultLogFile)), fx.Supply(rcclient.Params{AgentName: "system-probe", AgentVersion: version.AgentVersion}), fx.Supply(optional.NewNoneOption[secrets.Component]()), compstatsd.Module(), @@ -103,10 +103,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { } }), healthprobefx.Module(), - // use system-probe config instead of agent config for logging - fx.Provide(func(lc fx.Lifecycle, params logimpl.Params, sysprobeconfig sysprobeconfig.Component) (log.Component, error) { - return logimpl.NewLogger(lc, params, sysprobeconfig) - }), + systemprobeloggerfx.Module(), fx.Supply(optional.NewNoneOption[workloadmeta.Component]()), autoexitimpl.Module(), pidimpl.Module(), @@ -250,7 +247,7 @@ func runSystemProbe(ctxChan <-chan context.Context, errChan chan error) error { // no config file path specification in this situation fx.Supply(config.NewAgentParams("", config.WithConfigMissingOK(true))), fx.Supply(sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(""))), - fx.Supply(logimpl.ForDaemon("SYS-PROBE", "log_file", common.DefaultLogFile)), + fx.Supply(log.ForDaemon("SYS-PROBE", "log_file", common.DefaultLogFile)), fx.Supply(rcclient.Params{AgentName: "system-probe", AgentVersion: version.AgentVersion}), fx.Supply(optional.NewNoneOption[secrets.Component]()), rcclientimpl.Module(), @@ -266,10 +263,7 @@ func runSystemProbe(ctxChan <-chan context.Context, errChan chan error) error { }), healthprobefx.Module(), fx.Supply(optional.NewNoneOption[workloadmeta.Component]()), - // use system-probe config instead of agent config for logging - fx.Provide(func(lc fx.Lifecycle, params logimpl.Params, sysprobeconfig sysprobeconfig.Component) (log.Component, error) { - return logimpl.NewLogger(lc, params, sysprobeconfig) - }), + systemprobeloggerfx.Module(), fx.Provide(func(sysprobeconfig sysprobeconfig.Component) settings.Params { profilingGoRoutines := commonsettings.NewProfilingGoroutines() profilingGoRoutines.ConfigPrefix = configPrefix diff --git a/cmd/system-probe/subcommands/runtime/activity_dump.go b/cmd/system-probe/subcommands/runtime/activity_dump.go index 10775904642dc..7b285fb92a46c 100644 --- a/cmd/system-probe/subcommands/runtime/activity_dump.go +++ b/cmd/system-probe/subcommands/runtime/activity_dump.go @@ -18,8 +18,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/system-probe/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" secagent "github.com/DataDog/datadog-agent/pkg/security/agent" secconfig "github.com/DataDog/datadog-agent/pkg/security/config" @@ -67,7 +66,7 @@ func listCommands(_ *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -90,7 +89,7 @@ func stopCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -137,7 +136,7 @@ func generateEncodingCommands(globalParams *command.GlobalParams) []*cobra.Comma fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -198,7 +197,7 @@ func diffCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, diff --git a/cmd/system-probe/subcommands/runtime/command.go b/cmd/system-probe/subcommands/runtime/command.go index 8bbfe9f4b965f..2bc34ad324b59 100644 --- a/cmd/system-probe/subcommands/runtime/command.go +++ b/cmd/system-probe/subcommands/runtime/command.go @@ -28,8 +28,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/system-probe/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" secagent "github.com/DataDog/datadog-agent/pkg/security/agent" @@ -94,7 +93,7 @@ func evalCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -127,7 +126,7 @@ func commonCheckPoliciesCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -151,7 +150,7 @@ func commonReloadPoliciesCommands(_ *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -169,7 +168,7 @@ func selfTestCommands(_ *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -200,7 +199,7 @@ func downloadPolicyCommands(globalParams *command.GlobalParams) []*cobra.Command fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -235,7 +234,7 @@ func processCacheCommands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -273,7 +272,7 @@ func networkNamespaceCommands(globalParams *command.GlobalParams) []*cobra.Comma fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -300,7 +299,7 @@ func discardersCommands(_ *command.GlobalParams) []*cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, diff --git a/cmd/system-probe/subcommands/runtime/security_profile.go b/cmd/system-probe/subcommands/runtime/security_profile.go index d5e971332a4ff..2e06f5c7ccf2b 100644 --- a/cmd/system-probe/subcommands/runtime/security_profile.go +++ b/cmd/system-probe/subcommands/runtime/security_profile.go @@ -17,8 +17,7 @@ import ( "github.com/DataDog/datadog-agent/cmd/system-probe/command" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" secagent "github.com/DataDog/datadog-agent/pkg/security/agent" "github.com/DataDog/datadog-agent/pkg/security/proto/api" @@ -63,7 +62,7 @@ func securityProfileShowCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -109,7 +108,7 @@ func listSecurityProfileCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, @@ -216,7 +215,7 @@ func saveSecurityProfileCommands(globalParams *command.GlobalParams) []*cobra.Co fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams("", config.WithConfigMissingOK(true)), SecretParams: secrets.NewDisabledParams(), - LogParams: logimpl.ForOneShot("SYS-PROBE", "info", true)}), + LogParams: log.ForOneShot("SYS-PROBE", "info", true)}), core.Bundle(), ) }, diff --git a/cmd/systray/command/command.go b/cmd/systray/command/command.go index f16040b59c499..562b7bdeb43bd 100644 --- a/cmd/systray/command/command.go +++ b/cmd/systray/command/command.go @@ -26,7 +26,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/comp/metadata/inventoryagent/inventoryagentimpl" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" @@ -71,11 +71,11 @@ func MakeCommand() *cobra.Command { } // log params - var logParams logimpl.Params + var logParams log.Params if subsystem == "windows" { - logParams = logimpl.ForDaemon("TRAY", "system_tray.log_file", logFilePath) + logParams = log.ForDaemon("TRAY", "system_tray.log_file", logFilePath) } else if subsystem == "console" { - logParams = logimpl.ForOneShot("TRAY", "info", true) + logParams = log.ForOneShot("TRAY", "info", true) } // root command diff --git a/cmd/trace-agent/subcommands/run/command.go b/cmd/trace-agent/subcommands/run/command.go index c27cf28e9d75e..03e6ba7c8ea4e 100644 --- a/cmd/trace-agent/subcommands/run/command.go +++ b/cmd/trace-agent/subcommands/run/command.go @@ -21,8 +21,8 @@ import ( coreconfig "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/configsync" "github.com/DataDog/datadog-agent/comp/core/configsync/configsyncimpl" - corelogimpl "github.com/DataDog/datadog-agent/comp/core/log/logimpl" - "github.com/DataDog/datadog-agent/comp/core/log/tracelogimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logtracefx "github.com/DataDog/datadog-agent/comp/core/log/fx-trace" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" "github.com/DataDog/datadog-agent/comp/core/tagger" @@ -88,10 +88,10 @@ func runTraceAgentProcess(ctx context.Context, cliParams *Params, defaultConfPat fx.Supply(secrets.NewEnabledParams()), telemetryimpl.Module(), coreconfig.Module(), - fx.Provide(func() corelogimpl.Params { - return corelogimpl.ForDaemon("TRACE", "apm_config.log_file", config.DefaultLogFilePath) + fx.Provide(func() log.Params { + return log.ForDaemon("TRACE", "apm_config.log_file", config.DefaultLogFilePath) }), - tracelogimpl.Module(), + logtracefx.Module(), // setup workloadmeta collectors.GetCatalog(), fx.Supply(workloadmeta.Params{ diff --git a/comp/agent/autoexit/autoexitimpl/autoexit.go b/comp/agent/autoexit/autoexitimpl/autoexit.go index 9b6744c640f85..76bd7c10d1b94 100644 --- a/comp/agent/autoexit/autoexitimpl/autoexit.go +++ b/comp/agent/autoexit/autoexitimpl/autoexit.go @@ -11,7 +11,7 @@ import ( "github.com/DataDog/datadog-agent/comp/agent/autoexit" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" pkgcommon "github.com/DataDog/datadog-agent/pkg/util/common" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/comp/agent/autoexit/autoexitimpl/manager.go b/comp/agent/autoexit/autoexitimpl/manager.go index 3d14871fdbf0f..1ec75cfc7fbe5 100644 --- a/comp/agent/autoexit/autoexitimpl/manager.go +++ b/comp/agent/autoexit/autoexitimpl/manager.go @@ -13,7 +13,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/shirou/gopsutil/v3/process" ) diff --git a/comp/agent/autoexit/autoexitimpl/manager_test.go b/comp/agent/autoexit/autoexitimpl/manager_test.go index 164cde6a4692c..409f060bc278a 100644 --- a/comp/agent/autoexit/autoexitimpl/manager_test.go +++ b/comp/agent/autoexit/autoexitimpl/manager_test.go @@ -9,9 +9,8 @@ import ( "regexp" "testing" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" assert "github.com/stretchr/testify/require" ) @@ -35,7 +34,7 @@ func (f *processFixture) run(t *testing.T, logComp log.Component) { } func TestExitDetection(t *testing.T) { - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) tests := []processFixture{ { name: "existing process", diff --git a/comp/agent/expvarserver/expvarserverimpl/expvarserver.go b/comp/agent/expvarserver/expvarserverimpl/expvarserver.go index 557d7ba8ba736..c607dfa6ce828 100644 --- a/comp/agent/expvarserver/expvarserverimpl/expvarserver.go +++ b/comp/agent/expvarserver/expvarserverimpl/expvarserver.go @@ -16,7 +16,7 @@ import ( "github.com/DataDog/datadog-agent/comp/agent/expvarserver" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go index e0014f4baf46f..827b1c93f2293 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer.go @@ -13,7 +13,7 @@ import ( demultiplexerComp "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_fake_sampler_mock.go b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_fake_sampler_mock.go index c9490754f8ab7..95bd541f9470c 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_fake_sampler_mock.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_fake_sampler_mock.go @@ -15,7 +15,7 @@ import ( demultiplexerComp "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/serializer/compression" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go index af0e34affecfe..f7dc85d7beb18 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/demultiplexer_mock.go @@ -13,7 +13,7 @@ import ( demultiplexerComp "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/aggregator" diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/status.go b/comp/aggregator/demultiplexer/demultiplexerimpl/status.go index 521db8737eb80..8e73f097fc7e1 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/status.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/status.go @@ -14,7 +14,7 @@ import ( checkstats "github.com/DataDog/datadog-agent/pkg/collector/check/stats" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" ) diff --git a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go index cc5d47ded4858..a4a4f21b576bb 100644 --- a/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go +++ b/comp/aggregator/demultiplexer/demultiplexerimpl/test_agent_demultiplexer.go @@ -13,7 +13,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" diff --git a/comp/aggregator/demultiplexerendpoint/impl/endpoint.go b/comp/aggregator/demultiplexerendpoint/impl/endpoint.go index 6338c9c17881c..c600c0da9ad85 100644 --- a/comp/aggregator/demultiplexerendpoint/impl/endpoint.go +++ b/comp/aggregator/demultiplexerendpoint/impl/endpoint.go @@ -18,7 +18,7 @@ import ( demultiplexerComp "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" httputils "github.com/DataDog/datadog-agent/pkg/util/http" ) diff --git a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go index fa234dcb0199b..8e68564313db2 100644 --- a/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go +++ b/comp/aggregator/diagnosesendermanager/diagnosesendermanagerimpl/sendermanager.go @@ -14,7 +14,7 @@ import ( "github.com/DataDog/datadog-agent/comp/aggregator/diagnosesendermanager" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" diff --git a/comp/api/authtoken/createandfetchimpl/authtoken.go b/comp/api/authtoken/createandfetchimpl/authtoken.go index dfa3775ec3585..9afffdeff362d 100644 --- a/comp/api/authtoken/createandfetchimpl/authtoken.go +++ b/comp/api/authtoken/createandfetchimpl/authtoken.go @@ -12,7 +12,7 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/comp/api/authtoken/createandfetchimpl/authtoken_test.go b/comp/api/authtoken/createandfetchimpl/authtoken_test.go index f76e394ae8374..1eb9e11f6ba81 100644 --- a/comp/api/authtoken/createandfetchimpl/authtoken_test.go +++ b/comp/api/authtoken/createandfetchimpl/authtoken_test.go @@ -17,7 +17,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" ) func TestGet(t *testing.T) { @@ -30,7 +31,7 @@ func TestGet(t *testing.T) { comp, err := newAuthToken( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Replace(config.MockParams{Overrides: overrides}), ), diff --git a/comp/api/authtoken/fetchonlyimpl/authtoken.go b/comp/api/authtoken/fetchonlyimpl/authtoken.go index 0b5375e2ea419..ac07402b8c960 100644 --- a/comp/api/authtoken/fetchonlyimpl/authtoken.go +++ b/comp/api/authtoken/fetchonlyimpl/authtoken.go @@ -12,7 +12,7 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/comp/api/authtoken/fetchonlyimpl/authtoken_test.go b/comp/api/authtoken/fetchonlyimpl/authtoken_test.go index b398bf09a2c7c..4492ab4ff4105 100644 --- a/comp/api/authtoken/fetchonlyimpl/authtoken_test.go +++ b/comp/api/authtoken/fetchonlyimpl/authtoken_test.go @@ -16,7 +16,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" ) func TestGet(t *testing.T) { @@ -29,7 +30,7 @@ func TestGet(t *testing.T) { comp := newAuthToken( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Replace(config.MockParams{Overrides: overrides}), ), diff --git a/comp/checks/winregistry/impl/logging_registry_delegate.go b/comp/checks/winregistry/impl/logging_registry_delegate.go index 8eb02286a29a0..acc16c4ac06de 100644 --- a/comp/checks/winregistry/impl/logging_registry_delegate.go +++ b/comp/checks/winregistry/impl/logging_registry_delegate.go @@ -7,7 +7,7 @@ package winregistryimpl -import "github.com/DataDog/datadog-agent/comp/core/log" +import log "github.com/DataDog/datadog-agent/comp/core/log/def" type loggingRegistryDelegate struct { baseRegistryDelegate diff --git a/comp/checks/winregistry/impl/winregistryimpl.go b/comp/checks/winregistry/impl/winregistryimpl.go index 39c0093569c4d..7c583c22852cf 100644 --- a/comp/checks/winregistry/impl/winregistryimpl.go +++ b/comp/checks/winregistry/impl/winregistryimpl.go @@ -19,7 +19,7 @@ import ( "github.com/DataDog/datadog-agent/comp/checks/winregistry" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/logs/agent" logsConfig "github.com/DataDog/datadog-agent/comp/logs/agent/config" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" diff --git a/comp/collector/collector/collectorimpl/collector.go b/comp/collector/collector/collectorimpl/collector.go index 52b2736711a54..e265871190fef 100644 --- a/comp/collector/collector/collectorimpl/collector.go +++ b/comp/collector/collector/collectorimpl/collector.go @@ -20,7 +20,7 @@ import ( "github.com/DataDog/datadog-agent/comp/collector/collector" "github.com/DataDog/datadog-agent/comp/collector/collector/collectorimpl/internal/middleware" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" metadata "github.com/DataDog/datadog-agent/comp/metadata/runner/runnerimpl" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" diff --git a/comp/collector/collector/collectorimpl/collector_demux_test.go b/comp/collector/collector/collectorimpl/collector_demux_test.go index c211638c8a131..d7e3037cb1c75 100644 --- a/comp/collector/collector/collectorimpl/collector_demux_test.go +++ b/comp/collector/collector/collectorimpl/collector_demux_test.go @@ -19,7 +19,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" @@ -80,7 +81,7 @@ func (s *SenderManagerProxy) GetDefaultSender() (sender.Sender, error) { } func (suite *CollectorDemuxTestSuite) SetupTest() { - suite.demux = fxutil.Test[demultiplexer.FakeSamplerMock](suite.T(), logimpl.MockModule(), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) + suite.demux = fxutil.Test[demultiplexer.FakeSamplerMock](suite.T(), fx.Provide(func() log.Component { return logmock.New(suite.T()) }), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) suite.SenderManagerMock = NewSenderManagerMock(suite.demux) suite.c = newCollector(fxutil.Test[dependencies](suite.T(), core.MockBundle(), diff --git a/comp/core/agenttelemetry/impl/agenttelemetry.go b/comp/core/agenttelemetry/impl/agenttelemetry.go index 19553810f0249..a99850df53b23 100644 --- a/comp/core/agenttelemetry/impl/agenttelemetry.go +++ b/comp/core/agenttelemetry/impl/agenttelemetry.go @@ -25,7 +25,7 @@ import ( agenttelemetry "github.com/DataDog/datadog-agent/comp/core/agenttelemetry/def" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/core/telemetry" compdef "github.com/DataDog/datadog-agent/comp/def" diff --git a/comp/core/agenttelemetry/impl/agenttelemetry_test.go b/comp/core/agenttelemetry/impl/agenttelemetry_test.go index 72c6e33f068ee..8ed968cb10f91 100644 --- a/comp/core/agenttelemetry/impl/agenttelemetry_test.go +++ b/comp/core/agenttelemetry/impl/agenttelemetry_test.go @@ -26,8 +26,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/core/telemetry" "github.com/DataDog/datadog-agent/comp/core/telemetry/telemetryimpl" @@ -166,7 +165,7 @@ func getTestAtel(t *testing.T, cfg := fxutil.Test[config.Component](t, config.MockModule(), fx.Replace(config.MockParams{Overrides: confOverrides})) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) status := fxutil.Test[status.Component](t, func() fxutil.Module { return fxutil.Component( diff --git a/comp/core/agenttelemetry/impl/sender.go b/comp/core/agenttelemetry/impl/sender.go index dafe9d5173e84..6c3bf75c02f5e 100644 --- a/comp/core/agenttelemetry/impl/sender.go +++ b/comp/core/agenttelemetry/impl/sender.go @@ -24,7 +24,7 @@ import ( dto "github.com/prometheus/client_model/go" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" metadatautils "github.com/DataDog/datadog-agent/comp/metadata/host/hostimpl/utils" "github.com/DataDog/datadog-agent/pkg/config/utils" httputils "github.com/DataDog/datadog-agent/pkg/util/http" diff --git a/comp/core/autodiscovery/autodiscoveryimpl/autoconfig.go b/comp/core/autodiscovery/autodiscoveryimpl/autoconfig.go index 484775a20e83a..1389826e0089b 100644 --- a/comp/core/autodiscovery/autodiscoveryimpl/autoconfig.go +++ b/comp/core/autodiscovery/autodiscoveryimpl/autoconfig.go @@ -29,7 +29,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery/telemetry" configComponent "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - logComp "github.com/DataDog/datadog-agent/comp/core/log" + logComp "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/core/tagger" diff --git a/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_mock.go b/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_mock.go index 60027d058ea5f..055dfa8b56e70 100644 --- a/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_mock.go +++ b/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_mock.go @@ -16,7 +16,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/autodiscovery" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/scheduler" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" diff --git a/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_test.go b/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_test.go index 25f708b0a0505..4d12b9260e042 100644 --- a/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_test.go +++ b/comp/core/autodiscovery/autodiscoveryimpl/autoconfig_test.go @@ -26,7 +26,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery/providers" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/providers/names" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/scheduler" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" diff --git a/comp/core/autodiscovery/autodiscoveryimpl/stats.go b/comp/core/autodiscovery/autodiscoveryimpl/stats.go index b1c19c5907f15..d8b31175ece2c 100644 --- a/comp/core/autodiscovery/autodiscoveryimpl/stats.go +++ b/comp/core/autodiscovery/autodiscoveryimpl/stats.go @@ -8,6 +8,8 @@ package autodiscoveryimpl import ( "expvar" "sync" + + "github.com/mohae/deepcopy" ) var ( @@ -89,12 +91,7 @@ func (es *acErrorStats) getResolveWarnings() map[string][]string { es.m.RLock() defer es.m.RUnlock() - resolveCopy := make(map[string][]string) - for k, v := range es.resolve { - resolveCopy[k] = v - } - - return resolveCopy + return deepcopy.Copy(es.resolve).(map[string][]string) } // GetConfigErrors gets the config errors diff --git a/comp/core/autodiscovery/listeners/workloadmeta_test.go b/comp/core/autodiscovery/listeners/workloadmeta_test.go index 83fca437ef9a2..27835a50c039f 100644 --- a/comp/core/autodiscovery/listeners/workloadmeta_test.go +++ b/comp/core/autodiscovery/listeners/workloadmeta_test.go @@ -15,7 +15,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -89,8 +90,8 @@ func newTestWorkloadmetaListener(t *testing.T) *testWorkloadmetaListener { w := fxutil.Test[workloadmetamock.Mock](t, fx.Options( fx.Supply(config.Params{}), - fx.Supply(logimpl.Params{}), - logimpl.MockModule(), + fx.Supply(log.Params{}), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/comp/core/autodiscovery/providers/container_test.go b/comp/core/autodiscovery/providers/container_test.go index 6726849b12667..dbb0e08984041 100644 --- a/comp/core/autodiscovery/providers/container_test.go +++ b/comp/core/autodiscovery/providers/container_test.go @@ -15,7 +15,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -25,7 +26,7 @@ import ( func TestProcessEvents(t *testing.T) { store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), )) @@ -413,7 +414,7 @@ func TestGenerateConfig(t *testing.T) { store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Replace(config.MockParams{Overrides: overrides}), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), diff --git a/comp/core/bundle.go b/comp/core/bundle.go index 20be53a4b28f3..0e9062b216497 100644 --- a/comp/core/bundle.go +++ b/comp/core/bundle.go @@ -17,7 +17,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logfx "github.com/DataDog/datadog-agent/comp/core/log/fx" "github.com/DataDog/datadog-agent/comp/core/pid/pidimpl" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" @@ -35,8 +36,8 @@ func Bundle() fxutil.BundleOptions { // As `config.Module` expects `config.Params` as a parameter, it is require to define how to get `config.Params` from `BundleParams`. fx.Provide(func(params BundleParams) config.Params { return params.ConfigParams }), config.Module(), - fx.Provide(func(params BundleParams) logimpl.Params { return params.LogParams }), - logimpl.Module(), + fx.Provide(func(params BundleParams) log.Params { return params.LogParams }), + logfx.Module(), fx.Provide(func(params BundleParams) sysprobeconfigimpl.Params { return params.SysprobeConfigParams }), secretsimpl.Module(), fx.Provide(func(params BundleParams) secrets.Params { return params.SecretParams }), diff --git a/comp/core/bundle_mock.go b/comp/core/bundle_mock.go index d5ca8bbeb0f89..c16d5cce0714e 100644 --- a/comp/core/bundle_mock.go +++ b/comp/core/bundle_mock.go @@ -16,11 +16,14 @@ package core import ( + "testing" + "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/comp/core/telemetry/telemetryimpl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -45,7 +48,7 @@ func MakeMockBundle(logParams, logger fx.Option) fxutil.BundleOptions { // MockBundle defines the mock fx options for this bundle. func MockBundle() fxutil.BundleOptions { return MakeMockBundle( - fx.Supply(logimpl.Params{}), - logimpl.MockModule(), + fx.Supply(log.Params{}), + fx.Provide(func(t testing.TB) log.Component { return logmock.New(t) }), ) } diff --git a/comp/core/bundle_params.go b/comp/core/bundle_params.go index 57515af7f19de..84c1d6ac1c32c 100644 --- a/comp/core/bundle_params.go +++ b/comp/core/bundle_params.go @@ -7,7 +7,7 @@ package core import ( "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" ) @@ -32,7 +32,7 @@ type ConfigParams = config.Params type SecretParams = secrets.Params // LogParams defines the parameters of the log component -type LogParams = logimpl.Params +type LogParams = log.Params // SysprobeConfigParams defines the parameters of the system-probe config component type SysprobeConfigParams = sysprobeconfigimpl.Params diff --git a/comp/core/config/component.go b/comp/core/config/component.go index f4deeee1b004e..9cc7e99575587 100644 --- a/comp/core/config/component.go +++ b/comp/core/config/component.go @@ -24,9 +24,6 @@ import ( // team: agent-shared-components -// LogConfig reads the logger config -type LogConfig pkgconfigmodel.Reader - // Component is the component type. type Component interface { pkgconfigmodel.ReaderWriter diff --git a/comp/core/configsync/configsyncimpl/module.go b/comp/core/configsync/configsyncimpl/module.go index 3832cf0c5ce12..fdb13471bc498 100644 --- a/comp/core/configsync/configsyncimpl/module.go +++ b/comp/core/configsync/configsyncimpl/module.go @@ -19,7 +19,7 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/configsync" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" apiutil "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/optional" diff --git a/comp/core/flare/flare.go b/comp/core/flare/flare.go index a6434aef8b791..710c7b1887a6b 100644 --- a/comp/core/flare/flare.go +++ b/comp/core/flare/flare.go @@ -25,7 +25,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare/helpers" "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" rcclienttypes "github.com/DataDog/datadog-agent/comp/remote-config/rcclient/types" diff --git a/comp/core/flare/flare_test.go b/comp/core/flare/flare_test.go index 6a3fcbb95430d..bf04f22da6425 100644 --- a/comp/core/flare/flare_test.go +++ b/comp/core/flare/flare_test.go @@ -16,7 +16,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" nooptelemetry "github.com/DataDog/datadog-agent/comp/core/telemetry/noopsimpl" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" @@ -30,7 +31,7 @@ func TestFlareCreation(t *testing.T) { f := newFlare( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), secretsimpl.MockModule(), nooptelemetry.Module(), diff --git a/comp/core/flare/helpers/send_flare.go b/comp/core/flare/helpers/send_flare.go index 9cda957e867a2..d66f1583d5afc 100644 --- a/comp/core/flare/helpers/send_flare.go +++ b/comp/core/flare/helpers/send_flare.go @@ -111,7 +111,7 @@ func getFlareReader(multipartBoundary, archivePath, caseID, email, hostname stri return bodyReader } -func readAndPostFlareFile(archivePath, caseID, email, hostname, url string, source FlareSource, client *http.Client) (*http.Response, error) { +func readAndPostFlareFile(archivePath, caseID, email, hostname, url string, source FlareSource, client *http.Client, apiKey string) (*http.Response, error) { // Having resolved the POST URL, we do not expect to see further redirects, so do not // handle them. client.CheckRedirect = func(req *http.Request, via []*http.Request) error { @@ -122,6 +122,7 @@ func readAndPostFlareFile(archivePath, caseID, email, hostname, url string, sour if err != nil { return nil, err } + request.Header.Add("DD-API-KEY", apiKey) // We need to set the Content-Type header here, but we still haven't created the writer // to obtain it from. Here we create one which only purpose is to give us a proper @@ -192,11 +193,12 @@ func analyzeResponse(r *http.Response, apiKey string) (string, error) { // Resolve a flare URL to the URL at which a POST should be made. This uses a HEAD request // to follow any redirects, avoiding the problematic behavior of a POST that results in a // redirect (and often in an early termination of the connection). -func resolveFlarePOSTURL(url string, client *http.Client) (string, error) { +func resolveFlarePOSTURL(url string, client *http.Client, apiKey string) (string, error) { request, err := http.NewRequest("HEAD", url, nil) if err != nil { return "", err } + request.Header.Add("DD-API-KEY", apiKey) r, err := client.Do(request) if err != nil { @@ -214,12 +216,12 @@ func resolveFlarePOSTURL(url string, client *http.Client) (string, error) { return r.Request.URL.String(), nil } -func mkURL(baseURL string, caseID string, apiKey string) string { +func mkURL(baseURL string, caseID string) string { url := baseURL + datadogSupportURL if caseID != "" { url += "/" + caseID } - return url + "?api_key=" + apiKey + return url } // SendTo sends a flare file to the backend. This is part of the "helpers" package while all the code is moved to @@ -239,14 +241,14 @@ func SendTo(cfg pkgconfigmodel.Reader, archivePath, caseID, email, apiKey, url s Timeout: httpTimeout, } - url = mkURL(baseURL, caseID, apiKey) + url = mkURL(baseURL, caseID) - url, err = resolveFlarePOSTURL(url, client) + url, err = resolveFlarePOSTURL(url, client, apiKey) if err != nil { return "", err } - r, err := readAndPostFlareFile(archivePath, caseID, email, hostname, url, source, client) + r, err := readAndPostFlareFile(archivePath, caseID, email, hostname, url, source, client, apiKey) if err != nil { return "", err } diff --git a/comp/core/flare/helpers/send_flare_test.go b/comp/core/flare/helpers/send_flare_test.go index f78c55f4803bc..3706c2f64e99a 100644 --- a/comp/core/flare/helpers/send_flare_test.go +++ b/comp/core/flare/helpers/send_flare_test.go @@ -23,8 +23,8 @@ import ( ) func TestMkURL(t *testing.T) { - assert.Equal(t, "https://example.com/support/flare/999?api_key=123456", mkURL("https://example.com", "999", "123456")) - assert.Equal(t, "https://example.com/support/flare?api_key=123456", mkURL("https://example.com", "", "123456")) + assert.Equal(t, "https://example.com/support/flare/999", mkURL("https://example.com", "999")) + assert.Equal(t, "https://example.com/support/flare", mkURL("https://example.com", "")) } func TestFlareHasRightForm(t *testing.T) { @@ -47,8 +47,12 @@ func TestFlareHasRightForm(t *testing.T) { // * the original flare request URL, which redirects on HEAD to /post-target // * HEAD /post-target - responds with 200 OK // * POST /post-target - the final POST + if r.Header.Get("DD-API-KEY") != "abcdef" { + w.WriteHeader(403) + io.WriteString(w, "request missing DD-API-KEY header") + } - if r.Method == "HEAD" && r.RequestURI == "/support/flare/12345?api_key=abcdef" { + if r.Method == "HEAD" && r.RequestURI == "/support/flare/12345" { // redirect to /post-target. w.Header().Set("Location", "/post-target") w.WriteHeader(307) @@ -97,7 +101,7 @@ func TestFlareHasRightForm(t *testing.T) { if testCase.fail { assert.Error(t, err) expectedErrorMessage := "We couldn't reach the flare backend " + - scrubber.ScrubLine(mkURL(ddURL, caseID, apiKey)) + + scrubber.ScrubLine(mkURL(ddURL, caseID)) + " via redirects: 503 Service Unavailable" assert.Equal(t, expectedErrorMessage, err.Error()) } else { diff --git a/comp/core/gui/guiimpl/gui.go b/comp/core/gui/guiimpl/gui.go index 27b8f9aebb74c..8685d49a89630 100644 --- a/comp/core/gui/guiimpl/gui.go +++ b/comp/core/gui/guiimpl/gui.go @@ -32,7 +32,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare" guicomp "github.com/DataDog/datadog-agent/comp/core/gui" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/pkg/api/security" diff --git a/comp/core/healthprobe/impl/healthprobe.go b/comp/core/healthprobe/impl/healthprobe.go index c2a052156c190..87e75816de297 100644 --- a/comp/core/healthprobe/impl/healthprobe.go +++ b/comp/core/healthprobe/impl/healthprobe.go @@ -16,7 +16,7 @@ import ( "time" healthprobeComponent "github.com/DataDog/datadog-agent/comp/core/healthprobe/def" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" compdef "github.com/DataDog/datadog-agent/comp/def" "github.com/DataDog/datadog-agent/pkg/status/health" "github.com/gorilla/mux" diff --git a/comp/core/healthprobe/impl/healthprobe_test.go b/comp/core/healthprobe/impl/healthprobe_test.go index 2c347e0129352..5b08598ed6760 100644 --- a/comp/core/healthprobe/impl/healthprobe_test.go +++ b/comp/core/healthprobe/impl/healthprobe_test.go @@ -14,18 +14,16 @@ import ( "testing" healthprobeComponent "github.com/DataDog/datadog-agent/comp/core/healthprobe/def" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" compdef "github.com/DataDog/datadog-agent/comp/def" "github.com/DataDog/datadog-agent/pkg/status/health" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/stretchr/testify/assert" ) func TestServer(t *testing.T) { lc := compdef.NewTestLifecycle() - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) requires := Requires{ Lc: lc, @@ -49,7 +47,7 @@ func TestServer(t *testing.T) { func TestServerNoHealthPort(t *testing.T) { lc := compdef.NewTestLifecycle() - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) requires := Requires{ Lc: lc, @@ -67,7 +65,7 @@ func TestServerNoHealthPort(t *testing.T) { } func TestLiveHandler(t *testing.T) { - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) request := httptest.NewRequest(http.MethodGet, "/live", nil) responseRecorder := httptest.NewRecorder() @@ -80,7 +78,7 @@ func TestLiveHandler(t *testing.T) { } func TestLiveHandlerUnhealthy(t *testing.T) { - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) request := httptest.NewRequest(http.MethodGet, "/live", nil) responseRecorder := httptest.NewRecorder() @@ -98,7 +96,7 @@ func TestLiveHandlerUnhealthy(t *testing.T) { } func TestReadyHandler(t *testing.T) { - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) request := httptest.NewRequest(http.MethodGet, "/ready", nil) responseRecorder := httptest.NewRecorder() @@ -111,7 +109,7 @@ func TestReadyHandler(t *testing.T) { } func TestReadyHandlerUnhealthy(t *testing.T) { - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) request := httptest.NewRequest(http.MethodGet, "/ready", nil) responseRecorder := httptest.NewRecorder() @@ -129,7 +127,7 @@ func TestReadyHandlerUnhealthy(t *testing.T) { } func TestHealthHandlerFails(t *testing.T) { - logComponent := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComponent := logmock.New(t) request := httptest.NewRequest(http.MethodGet, "/live", nil) responseRecorder := httptest.NewRecorder() diff --git a/comp/core/log/component.go b/comp/core/log/def/component.go similarity index 100% rename from comp/core/log/component.go rename to comp/core/log/def/component.go diff --git a/comp/core/log/def/go.mod b/comp/core/log/def/go.mod new file mode 100644 index 0000000000000..5cf06483e59b5 --- /dev/null +++ b/comp/core/log/def/go.mod @@ -0,0 +1,11 @@ +module github.com/DataDog/datadog-agent/comp/core/log/def + +go 1.21.0 + +require github.com/stretchr/testify v1.9.0 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/comp/core/log/def/go.sum b/comp/core/log/def/go.sum new file mode 100644 index 0000000000000..60ce688a04104 --- /dev/null +++ b/comp/core/log/def/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/comp/core/log/logimpl/params.go b/comp/core/log/def/params.go similarity index 96% rename from comp/core/log/logimpl/params.go rename to comp/core/log/def/params.go index 090282cb25c5b..30ed78cee75e7 100644 --- a/comp/core/log/logimpl/params.go +++ b/comp/core/log/def/params.go @@ -3,12 +3,11 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -package logimpl +package log import ( + "os" "runtime" - - pkgconfigenv "github.com/DataDog/datadog-agent/pkg/config/env" ) // Params defines the parameters for this log component. @@ -62,7 +61,13 @@ func ForOneShot(loggerName, level string, overrideFromEnv bool) Params { params := Params{} params.loggerName = loggerName if overrideFromEnv { - params.logLevelFn = func(configGetter) string { return pkgconfigenv.GetEnvDefault("DD_LOG_LEVEL", level) } + params.logLevelFn = func(configGetter) string { + value, found := os.LookupEnv("DD_LOG_LEVEL") + if !found { + return level + } + return value + } } else { params.logLevelFn = func(configGetter) string { return level } } diff --git a/comp/core/log/logimpl/params_test.go b/comp/core/log/def/params_test.go similarity index 99% rename from comp/core/log/logimpl/params_test.go rename to comp/core/log/def/params_test.go index 94327274d0497..d93a5014e9801 100644 --- a/comp/core/log/logimpl/params_test.go +++ b/comp/core/log/def/params_test.go @@ -3,7 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -package logimpl +package log import ( "runtime" diff --git a/comp/core/log/fx-systemprobe/fx.go b/comp/core/log/fx-systemprobe/fx.go new file mode 100644 index 0000000000000..5f434be4374fb --- /dev/null +++ b/comp/core/log/fx-systemprobe/fx.go @@ -0,0 +1,21 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package fxlog defines the fx options for this component. +package fxlog + +import ( + logimpl "github.com/DataDog/datadog-agent/comp/core/log/impl-systemprobe" + "github.com/DataDog/datadog-agent/pkg/util/fxutil" +) + +// Module defines the fx options for this component +func Module() fxutil.Module { + return fxutil.Component( + fxutil.ProvideComponentConstructor( + logimpl.NewComponent, + ), + ) +} diff --git a/comp/core/log/fx-trace/fx.go b/comp/core/log/fx-trace/fx.go new file mode 100644 index 0000000000000..d870de6996d6b --- /dev/null +++ b/comp/core/log/fx-trace/fx.go @@ -0,0 +1,21 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package fxlog defines the fx options for this component. +package fxlog + +import ( + impltrace "github.com/DataDog/datadog-agent/comp/core/log/impl-trace" + "github.com/DataDog/datadog-agent/pkg/util/fxutil" +) + +// Module defines the fx options for this component +func Module() fxutil.Module { + return fxutil.Component( + fxutil.ProvideComponentConstructor( + impltrace.NewComponent, + ), + ) +} diff --git a/comp/core/log/tracelogimpl/module.go b/comp/core/log/fx/fx.go similarity index 59% rename from comp/core/log/tracelogimpl/module.go rename to comp/core/log/fx/fx.go index b1c99dffa8d97..0401af6a14526 100644 --- a/comp/core/log/tracelogimpl/module.go +++ b/comp/core/log/fx/fx.go @@ -3,18 +3,19 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -// Package tracelogimpl provides a component that implements the log.Component for the trace-agent logger -package tracelogimpl +// Package fxlog defines the fx options for this component. +package fxlog import ( - "go.uber.org/fx" - + logimpl "github.com/DataDog/datadog-agent/comp/core/log/impl" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) -// Module defines the fx options for the log component in its Trace variant. +// Module defines the fx options for this component func Module() fxutil.Module { return fxutil.Component( - fx.Provide(newTraceLogger), + fxutil.ProvideComponentConstructor( + logimpl.NewComponent, + ), ) } diff --git a/comp/core/log/impl-systemprobe/systemprobe_logger.go b/comp/core/log/impl-systemprobe/systemprobe_logger.go new file mode 100644 index 0000000000000..500aec039aec4 --- /dev/null +++ b/comp/core/log/impl-systemprobe/systemprobe_logger.go @@ -0,0 +1,58 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package systemprobeimpl implements a component to handle logging internal to the agent for system-probe. +package systemprobeimpl + +import ( + "context" + "errors" + + logdef "github.com/DataDog/datadog-agent/comp/core/log/def" + "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" + compdef "github.com/DataDog/datadog-agent/comp/def" + pkgconfiglogs "github.com/DataDog/datadog-agent/pkg/config/logs" + pkglog "github.com/DataDog/datadog-agent/pkg/util/log" +) + +// Requires declares the input types to the logger component constructor +type Requires struct { + Lc compdef.Lifecycle + Params logdef.Params + Config sysprobeconfig.Component +} + +// Provides defines the output of the log component +type Provides struct { + Comp logdef.Component +} + +// NewComponent creates a log.Component using the provided config +func NewComponent(deps Requires) (Provides, error) { + if !deps.Params.IsLogLevelFnSet() { + return Provides{}, errors.New("must call one of core.BundleParams.ForOneShot or ForDaemon") + } + + err := pkgconfiglogs.SetupLogger( + pkgconfiglogs.LoggerName(deps.Params.LoggerName()), + deps.Params.LogLevelFn(deps.Config), + deps.Params.LogFileFn(deps.Config), + deps.Params.LogSyslogURIFn(deps.Config), + deps.Params.LogSyslogRFCFn(deps.Config), + deps.Params.LogToConsoleFn(deps.Config), + deps.Params.LogFormatJSONFn(deps.Config), + deps.Config) + if err != nil { + return Provides{}, err + } + + l := pkglog.NewWrapper(2) + deps.Lc.Append(compdef.Hook{OnStop: func(context.Context) error { + l.Flush() + return nil + }}) + + return Provides{Comp: l}, nil +} diff --git a/comp/core/log/go.mod b/comp/core/log/impl-trace/go.mod similarity index 69% rename from comp/core/log/go.mod rename to comp/core/log/impl-trace/go.mod index e3cd453628d1f..78c6746f6801c 100644 --- a/comp/core/log/go.mod +++ b/comp/core/log/impl-trace/go.mod @@ -1,57 +1,63 @@ -module github.com/DataDog/datadog-agent/comp/core/log +module github.com/DataDog/datadog-agent/comp/core/log/impl-trace go 1.21.0 replace ( - github.com/DataDog/datadog-agent/cmd/agent/common/path => ../../../cmd/agent/common/path - github.com/DataDog/datadog-agent/comp/api/api/def => ../../api/api/def - github.com/DataDog/datadog-agent/comp/core/config => ../config - github.com/DataDog/datadog-agent/comp/core/flare/builder => ../flare/builder - github.com/DataDog/datadog-agent/comp/core/flare/types => ../flare/types - github.com/DataDog/datadog-agent/comp/core/secrets => ../secrets - github.com/DataDog/datadog-agent/comp/core/telemetry => ../telemetry/ - github.com/DataDog/datadog-agent/comp/def => ../../def/ - github.com/DataDog/datadog-agent/pkg/collector/check/defaults => ../../../pkg/collector/check/defaults - github.com/DataDog/datadog-agent/pkg/config/env => ../../../pkg/config/env - github.com/DataDog/datadog-agent/pkg/config/logs => ../../../pkg/config/logs - github.com/DataDog/datadog-agent/pkg/config/model => ../../../pkg/config/model - github.com/DataDog/datadog-agent/pkg/config/setup => ../../../pkg/config/setup - github.com/DataDog/datadog-agent/pkg/obfuscate => ../../../pkg/obfuscate - github.com/DataDog/datadog-agent/pkg/proto => ../../../pkg/proto - github.com/DataDog/datadog-agent/pkg/remoteconfig/state => ../../../pkg/remoteconfig/state - github.com/DataDog/datadog-agent/pkg/telemetry => ../../../pkg/telemetry - github.com/DataDog/datadog-agent/pkg/trace => ../../../pkg/trace - github.com/DataDog/datadog-agent/pkg/util/executable => ../../../pkg/util/executable - github.com/DataDog/datadog-agent/pkg/util/filesystem => ../../../pkg/util/filesystem/ - github.com/DataDog/datadog-agent/pkg/util/fxutil => ../../../pkg/util/fxutil - github.com/DataDog/datadog-agent/pkg/util/hostname/validate => ../../../pkg/util/hostname/validate - github.com/DataDog/datadog-agent/pkg/util/log => ../../../pkg/util/log - github.com/DataDog/datadog-agent/pkg/util/optional => ../../../pkg/util/optional - github.com/DataDog/datadog-agent/pkg/util/pointer => ../../../pkg/util/pointer - github.com/DataDog/datadog-agent/pkg/util/scrubber => ../../../pkg/util/scrubber/ - github.com/DataDog/datadog-agent/pkg/util/system => ../../../pkg/util/system - github.com/DataDog/datadog-agent/pkg/util/system/socket => ../../../pkg/util/system/socket - github.com/DataDog/datadog-agent/pkg/util/testutil => ../../../pkg/util/testutil - github.com/DataDog/datadog-agent/pkg/util/winutil => ../../../pkg/util/winutil + github.com/DataDog/datadog-agent/cmd/agent/common/path => ../../../../cmd/agent/common/path + github.com/DataDog/datadog-agent/comp/api/api/def => ../../../api/api/def + github.com/DataDog/datadog-agent/comp/core/config => ../../../../comp/core/config + github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../flare/builder + github.com/DataDog/datadog-agent/comp/core/flare/types => ../../flare/types + github.com/DataDog/datadog-agent/comp/core/log/def => ../../../../comp/core/log/def + github.com/DataDog/datadog-agent/comp/core/secrets => ../../secrets + github.com/DataDog/datadog-agent/comp/core/telemetry => ../../telemetry/ + github.com/DataDog/datadog-agent/comp/def => ../../../../comp/def + github.com/DataDog/datadog-agent/pkg/collector/check/defaults => ../../../../pkg/collector/check/defaults + github.com/DataDog/datadog-agent/pkg/config/env => ../../../../pkg/config/env + github.com/DataDog/datadog-agent/pkg/config/logs => ../../../../pkg/config/logs + github.com/DataDog/datadog-agent/pkg/config/mock => ../../../../pkg/config/mock + github.com/DataDog/datadog-agent/pkg/config/model => ../../../../pkg/config/model + github.com/DataDog/datadog-agent/pkg/config/setup => ../../../../pkg/config/setup + github.com/DataDog/datadog-agent/pkg/obfuscate => ../../../../pkg/obfuscate + github.com/DataDog/datadog-agent/pkg/proto => ../../../../pkg/proto + github.com/DataDog/datadog-agent/pkg/remoteconfig/state => ../../../../pkg/remoteconfig/state + github.com/DataDog/datadog-agent/pkg/telemetry => ../../../../pkg/telemetry + github.com/DataDog/datadog-agent/pkg/trace => ../../../../pkg/trace + github.com/DataDog/datadog-agent/pkg/util/executable => ../../../../pkg/util/executable + github.com/DataDog/datadog-agent/pkg/util/filesystem => ../../../../pkg/util/filesystem/ + github.com/DataDog/datadog-agent/pkg/util/fxutil => ../../../../pkg/util/fxutil + github.com/DataDog/datadog-agent/pkg/util/hostname/validate => ../../../../pkg/util/hostname/validate + github.com/DataDog/datadog-agent/pkg/util/log => ../../../../pkg/util/log + github.com/DataDog/datadog-agent/pkg/util/optional => ../../../../pkg/util/optional + github.com/DataDog/datadog-agent/pkg/util/pointer => ../../../../pkg/util/pointer + github.com/DataDog/datadog-agent/pkg/util/scrubber => ../../../../pkg/util/scrubber/ + github.com/DataDog/datadog-agent/pkg/util/system => ../../../../pkg/util/system + github.com/DataDog/datadog-agent/pkg/util/system/socket => ../../../../pkg/util/system/socket + github.com/DataDog/datadog-agent/pkg/util/testutil => ../../../../pkg/util/testutil + github.com/DataDog/datadog-agent/pkg/util/winutil => ../../../../pkg/util/winutil ) require ( github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.3 - github.com/DataDog/datadog-agent/pkg/config/env v0.56.0-rc.3 - github.com/DataDog/datadog-agent/pkg/config/logs v0.56.0-rc.3 + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/pkg/config/env v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/trace v0.56.0-rc.3 - github.com/DataDog/datadog-agent/pkg/util/fxutil v0.56.0-rc.3 + github.com/DataDog/datadog-agent/pkg/util/fxutil v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 - github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // v2.6 - github.com/stretchr/testify v1.9.0 - go.uber.org/fx v1.18.2 + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect; v2.6 + github.com/stretchr/testify v1.9.0 // indirect + go.uber.org/fx v1.18.2 // indirect +) + +require ( + github.com/DataDog/datadog-agent/comp/def v0.56.0-rc.3 + github.com/DataDog/datadog-agent/pkg/config/logs v0.0.0-00010101000000-000000000000 ) require ( github.com/DataDog/datadog-agent/comp/core/flare/builder v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/secrets v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/comp/def v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/collector/check/defaults v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/config/setup v0.56.0-rc.3 // indirect diff --git a/comp/core/log/go.sum b/comp/core/log/impl-trace/go.sum similarity index 100% rename from comp/core/log/go.sum rename to comp/core/log/impl-trace/go.sum diff --git a/comp/core/log/impl-trace/trace_logger.go b/comp/core/log/impl-trace/trace_logger.go new file mode 100644 index 0000000000000..7d124e1642e50 --- /dev/null +++ b/comp/core/log/impl-trace/trace_logger.go @@ -0,0 +1,64 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package traceimpl provides a component that implements the log.Component for the trace-agent logger +package traceimpl + +import ( + "context" + "errors" + "fmt" + + "github.com/DataDog/datadog-agent/comp/core/config" + logdef "github.com/DataDog/datadog-agent/comp/core/log/def" + compdef "github.com/DataDog/datadog-agent/comp/def" + pkgconfiglogs "github.com/DataDog/datadog-agent/pkg/config/logs" + tracelog "github.com/DataDog/datadog-agent/pkg/trace/log" + "github.com/DataDog/datadog-agent/pkg/trace/telemetry" + pkglog "github.com/DataDog/datadog-agent/pkg/util/log" +) + +// Requires declares the input types to the logger component constructor +type Requires struct { + Lc compdef.Lifecycle + Params logdef.Params + Config config.Component + TelemetryCollector telemetry.TelemetryCollector +} + +// Provides defines the output of the log component +type Provides struct { + Comp logdef.Component +} + +// NewComponent creates a pkglog.Component using the provided config +func NewComponent(deps Requires) (Provides, error) { + if !deps.Params.IsLogLevelFnSet() { + return Provides{}, errors.New("must call one of core.BundleParams.ForOneShot or ForDaemon") + } + + err := pkgconfiglogs.SetupLogger( + pkgconfiglogs.LoggerName(deps.Params.LoggerName()), + deps.Params.LogLevelFn(deps.Config), + deps.Params.LogFileFn(deps.Config), + deps.Params.LogSyslogURIFn(deps.Config), + deps.Params.LogSyslogRFCFn(deps.Config), + deps.Params.LogToConsoleFn(deps.Config), + deps.Params.LogFormatJSONFn(deps.Config), + deps.Config) + if err != nil { + deps.TelemetryCollector.SendStartupError(telemetry.CantCreateLogger, err) + return Provides{}, fmt.Errorf("Cannot create logger: %v", err) + } + + l := pkglog.NewWrapper(3) + tracelog.SetLogger(l) + deps.Lc.Append(compdef.Hook{OnStop: func(context.Context) error { + l.Flush() + return nil + }}) + + return Provides{Comp: l}, nil +} diff --git a/comp/core/log/impl/go.mod b/comp/core/log/impl/go.mod new file mode 100644 index 0000000000000..519aa3642602e --- /dev/null +++ b/comp/core/log/impl/go.mod @@ -0,0 +1,123 @@ +module github.com/DataDog/datadog-agent/comp/core/log/impl + +go 1.21.0 + +replace github.com/DataDog/datadog-agent/pkg/util/scrubber => ../../../../pkg/util/scrubber + +replace github.com/DataDog/datadog-agent/pkg/util/pointer => ../../../../pkg/util/pointer + +replace github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../../comp/core/flare/types + +replace github.com/DataDog/datadog-agent/pkg/util/optional => ../../../../pkg/util/optional + +replace github.com/DataDog/datadog-agent/pkg/util/system/socket => ../../../../pkg/util/system/socket + +replace github.com/DataDog/datadog-agent/pkg/util/filesystem => ../../../../pkg/util/filesystem + +replace github.com/DataDog/datadog-agent/comp/core/secrets => ../../../../comp/core/secrets + +replace github.com/DataDog/datadog-agent/pkg/collector/check/defaults => ../../../../pkg/collector/check/defaults + +replace github.com/DataDog/datadog-agent/pkg/util/system => ../../../../pkg/util/system + +replace github.com/DataDog/datadog-agent/pkg/util/hostname/validate => ../../../../pkg/util/hostname/validate + +replace github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../../comp/core/flare/builder + +replace github.com/DataDog/datadog-agent/pkg/config/logs => ../../../../pkg/config/logs + +replace github.com/DataDog/datadog-agent/pkg/config/env => ../../../../pkg/config/env + +replace github.com/DataDog/datadog-agent/pkg/util/winutil => ../../../../pkg/util/winutil + +replace github.com/DataDog/datadog-agent/pkg/config/setup => ../../../../pkg/config/setup + +replace github.com/DataDog/datadog-agent/comp/def => ../../../../comp/def + +replace github.com/DataDog/datadog-agent/comp/core/config => ../../../../comp/core/config + +replace github.com/DataDog/datadog-agent/comp/core/log/def => ../../../../comp/core/log/def + +replace github.com/DataDog/datadog-agent/pkg/util/log => ../../../../pkg/util/log + +replace github.com/DataDog/datadog-agent/pkg/config/model => ../../../../pkg/config/model + +replace github.com/DataDog/datadog-agent/pkg/util/fxutil => ../../../../pkg/util/fxutil + +replace github.com/DataDog/datadog-agent/pkg/util/executable => ../../../../pkg/util/executable + +replace github.com/DataDog/datadog-agent/cmd/agent/common/path => ../../../../cmd/agent/common/path + +replace github.com/DataDog/datadog-agent/comp/api/api/def => ../../../../comp/api/api/def + +replace github.com/DataDog/datadog-agent/comp/core/telemetry => ../../../../comp/core/telemetry + +replace github.com/DataDog/datadog-agent/pkg/util/testutil => ../../../../pkg/util/testutil + +require ( + github.com/DataDog/datadog-agent/comp/core/config v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/def v0.56.0-rc.3 + github.com/DataDog/datadog-agent/pkg/config/logs v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 +) + +require ( + github.com/DataDog/datadog-agent/comp/core/flare/builder v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/comp/core/secrets v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/collector/check/defaults v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/config/env v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/config/setup v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/executable v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/filesystem v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/fxutil v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/hostname/validate v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/optional v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/pointer v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/scrubber v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/system v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/system/socket v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/winutil v0.56.0-rc.3 // indirect + github.com/DataDog/viper v1.13.5 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/magiconair/properties v1.8.1 // indirect + github.com/mitchellh/mapstructure v1.1.2 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/pelletier/go-toml v1.2.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shirou/gopsutil/v3 v3.23.12 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/spf13/afero v1.1.2 // indirect + github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/cobra v1.7.0 // indirect + github.com/spf13/jwalterweatherman v1.0.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/testify v1.9.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + go.uber.org/atomic v1.11.0 // indirect + go.uber.org/dig v1.17.1 // indirect + go.uber.org/fx v1.18.2 // indirect + go.uber.org/multierr v1.10.0 // indirect + go.uber.org/zap v1.26.0 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/tools v0.18.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/comp/core/log/impl/go.sum b/comp/core/log/impl/go.sum new file mode 100644 index 0000000000000..6cc0ed82b720a --- /dev/null +++ b/comp/core/log/impl/go.sum @@ -0,0 +1,358 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/viper v1.13.5 h1:SZMcyMknYQN2jRY/40A16gUXexlNJOI8sDs1cWZnI64= +github.com/DataDog/viper v1.13.5/go.mod h1:wDdUVJ2SHaMaPrCZrlRCObwkubsX8j5sme3LaR/SGTc= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= +github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 h1:kHaBemcxl8o/pQ5VM1c8PVE1PubbNx3mjUr09OqWGCs= +github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/fd/NrVaLscBKmPigpZpn5YawRPw+e3Yo= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.13.0/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95 h1:S4qyfL2sEm5Budr4KVMyEniCy+PbS55651I/a+Kn/NQ= +github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95/go.mod h1:QiyDdbZLaJ/mZP4Zwc9g2QsfaEA4o7XvvgZegSci5/E= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= +github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= +github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= +github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= +github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI= +github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shirou/gopsutil/v3 v3.23.12 h1:z90NtUkp3bMtmICZKpC4+WaknU1eXtp5vtbQ11DgpE4= +github.com/shirou/gopsutil/v3 v3.23.12/go.mod h1:1FrWgea594Jp7qmjHUUPlJDTPgcsb9mGnXDxavtikzM= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= +go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= +go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= +go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI= +go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A= +go.opentelemetry.io/otel/sdk/metric v1.27.0 h1:5uGNOlpXi+Hbo/DRoI31BSb1v+OGcpv2NemcCrOL8gI= +go.opentelemetry.io/otel/sdk/metric v1.27.0/go.mod h1:we7jJVrYN2kh3mVBlswtPU22K0SA+769l93J6bsyvqw= +go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= +go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc= +go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE= +go.uber.org/fx v1.18.2 h1:bUNI6oShr+OVFQeU8cDNbnN7VFsu+SsjHzUF51V/GAU= +go.uber.org/fx v1.18.2/go.mod h1:g0V1KMQ66zIRk8bLu3Ea5Jt2w/cHlOIp4wdRsgh0JaY= +go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= +go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= +go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190529164535-6a60838ec259/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= +golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/comp/core/log/impl/logger.go b/comp/core/log/impl/logger.go new file mode 100644 index 0000000000000..99f76f6a95909 --- /dev/null +++ b/comp/core/log/impl/logger.go @@ -0,0 +1,74 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package logimpl implements a component to handle logging internal to the agent. +package logimpl + +import ( + "context" + "errors" + + "github.com/DataDog/datadog-agent/comp/core/config" + logdef "github.com/DataDog/datadog-agent/comp/core/log/def" + compdef "github.com/DataDog/datadog-agent/comp/def" + pkgconfiglogs "github.com/DataDog/datadog-agent/pkg/config/logs" + pkglog "github.com/DataDog/datadog-agent/pkg/util/log" +) + +// NewTemporaryLoggerWithoutInit returns a logger component instance. It assumes the logger has already been +// initialized beforehand. +// +// This function should be used when all these conditions are true: +// - You write or update code which uses a lot of logging. +// - You want the code to be components ready. +// - logger.Component cannot be injected. +// +// It should not be used when: +// - You add few logging functions. +// - When the instance of logger.Component is reachable in less than 5 stack frames. +// - It doesn't make the migration to log.Component easier. +func NewTemporaryLoggerWithoutInit() logdef.Component { + return pkglog.NewWrapper(2) +} + +// Requires declares the input types to the logger component constructor +type Requires struct { + Lc compdef.Lifecycle + Params logdef.Params + Config config.Component +} + +// Provides defines the output of the log component +type Provides struct { + Comp logdef.Component +} + +// NewComponent creates a log.Component using the provided config +func NewComponent(deps Requires) (Provides, error) { + if !deps.Params.IsLogLevelFnSet() { + return Provides{}, errors.New("must call one of core.BundleParams.ForOneShot or ForDaemon") + } + + err := pkgconfiglogs.SetupLogger( + pkgconfiglogs.LoggerName(deps.Params.LoggerName()), + deps.Params.LogLevelFn(deps.Config), + deps.Params.LogFileFn(deps.Config), + deps.Params.LogSyslogURIFn(deps.Config), + deps.Params.LogSyslogRFCFn(deps.Config), + deps.Params.LogToConsoleFn(deps.Config), + deps.Params.LogFormatJSONFn(deps.Config), + deps.Config) + if err != nil { + return Provides{}, err + } + + l := pkglog.NewWrapper(2) + deps.Lc.Append(compdef.Hook{OnStop: func(context.Context) error { + l.Flush() + return nil + }}) + + return Provides{Comp: l}, nil +} diff --git a/comp/core/log/logimpl/logger.go b/comp/core/log/logimpl/logger.go deleted file mode 100644 index 0844eb7b223f6..0000000000000 --- a/comp/core/log/logimpl/logger.go +++ /dev/null @@ -1,156 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2016-present Datadog, Inc. - -// Package logimpl implements a component to handle logging internal to the agent. -package logimpl - -import ( - "context" - "errors" - "fmt" - - "github.com/cihub/seelog" - "go.uber.org/fx" - - "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - pkgconfiglogs "github.com/DataDog/datadog-agent/pkg/config/logs" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" - pkglog "github.com/DataDog/datadog-agent/pkg/util/log" -) - -// Module defines the fx options for this component. -func Module() fxutil.Module { - return fxutil.Component( - fx.Provide(newAgentLogger), - ) -} - -// logger implements the component -type logger struct { - // this component is currently implementing a thin wrapper around - // pkg/util/log, and uses globals in that package. -} - -// NewTemporaryLoggerWithoutInit returns a logger component instance. It assumes the logger has already been -// initialized beforehand. -// -// This function should be used when all these conditions are true: -// - You write or update code which uses a lot of logging. -// - You want the code to be components ready. -// - logger.Component cannot be injected. -// -// It should not be used when: -// - You add few logging functions. -// - When the instance of logger.Component is reachable in less than 5 stack frames. -// - It doesn't make the migration to log.Component easier. -func NewTemporaryLoggerWithoutInit() log.Component { - return &logger{} -} - -func newAgentLogger(lc fx.Lifecycle, params Params, config config.Component) (log.Component, error) { - return NewLogger(lc, params, config) -} - -// NewLogger creates a log.Component using the provided config.LogConfig -func NewLogger(lc fx.Lifecycle, params Params, config config.LogConfig) (log.Component, error) { - if params.logLevelFn == nil { - return nil, errors.New("must call one of core.BundleParams.ForOneShot or ForDaemon") - } - - err := pkgconfiglogs.SetupLogger( - pkgconfiglogs.LoggerName(params.loggerName), - params.logLevelFn(config), - params.logFileFn(config), - params.logSyslogURIFn(config), - params.logSyslogRFCFn(config), - params.logToConsoleFn(config), - params.logFormatJSONFn(config), - config) - if err != nil { - return nil, err - } - - l := &logger{} - lc.Append(fx.Hook{OnStop: func(context.Context) error { - l.Flush() - return nil - }}) - - return l, nil -} - -// Until the log migration to component is done, we use *StackDepth to pkglog. The log component add 1 layer to the call -// stack and *StackDepth add another. -// -// We check the current log level to avoid calling Sprintf when it's not needed (Sprintf from Tracef uses a lot a CPU) - -// Trace implements Component#Trace. -func (*logger) Trace(v ...interface{}) { pkglog.TraceStackDepth(2, v...) } - -// Tracef implements Component#Tracef. -func (*logger) Tracef(format string, params ...interface{}) { - currentLevel, _ := pkglog.GetLogLevel() - if currentLevel <= seelog.TraceLvl { - pkglog.TraceStackDepth(2, fmt.Sprintf(format, params...)) - } -} - -// Debug implements Component#Debug. -func (*logger) Debug(v ...interface{}) { pkglog.DebugStackDepth(2, v...) } - -// Debugf implements Component#Debugf. -func (*logger) Debugf(format string, params ...interface{}) { - currentLevel, _ := pkglog.GetLogLevel() - if currentLevel <= seelog.DebugLvl { - pkglog.DebugStackDepth(2, fmt.Sprintf(format, params...)) - } -} - -// Info implements Component#Info. -func (*logger) Info(v ...interface{}) { pkglog.InfoStackDepth(2, v...) } - -// Infof implements Component#Infof. -func (*logger) Infof(format string, params ...interface{}) { - currentLevel, _ := pkglog.GetLogLevel() - if currentLevel <= seelog.InfoLvl { - pkglog.InfoStackDepth(2, fmt.Sprintf(format, params...)) - } -} - -// Warn implements Component#Warn. -func (*logger) Warn(v ...interface{}) error { return pkglog.WarnStackDepth(2, v...) } - -// Warnf implements Component#Warnf. -func (*logger) Warnf(format string, params ...interface{}) error { - // no need to check the current log level since Sprintf will be called in all case to generate the returned - // error - return pkglog.WarnStackDepth(2, fmt.Sprintf(format, params...)) -} - -// Error implements Component#Error. -func (*logger) Error(v ...interface{}) error { return pkglog.ErrorStackDepth(2, v...) } - -// Errorf implements Component#Errorf. -func (*logger) Errorf(format string, params ...interface{}) error { - // no need to check the current log level since Sprintf will be called in all case to generate the returned - // error - return pkglog.ErrorStackDepth(2, fmt.Sprintf(format, params...)) -} - -// Critical implements Component#Critical. -func (*logger) Critical(v ...interface{}) error { return pkglog.CriticalStackDepth(2, v...) } - -// Criticalf implements Component#Criticalf. -func (*logger) Criticalf(format string, params ...interface{}) error { - // no need to check the current log level since Sprintf will be called in all case to generate the returned - // error - return pkglog.CriticalStackDepth(2, fmt.Sprintf(format, params...)) -} - -// Flush implements Component#Flush. -func (*logger) Flush() { - pkglog.Flush() -} diff --git a/comp/core/log/logimpl/logger_test.go b/comp/core/log/logimpl/logger_test.go deleted file mode 100644 index 64ec417020862..0000000000000 --- a/comp/core/log/logimpl/logger_test.go +++ /dev/null @@ -1,25 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2016-present Datadog, Inc. - -package logimpl - -import ( - "testing" - - "go.uber.org/fx" - - "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" -) - -func TestLogging(t *testing.T) { - log := fxutil.Test[log.Component](t, fx.Options( - fx.Supply(ForOneShot("TEST", "debug", false)), - config.MockModule(), - Module(), - )) - log.Debugf("hello, world. %s", "hi") -} diff --git a/comp/core/log/logimpl/mock_test.go b/comp/core/log/logimpl/mock_test.go deleted file mode 100644 index 6213b9ff56f9e..0000000000000 --- a/comp/core/log/logimpl/mock_test.go +++ /dev/null @@ -1,25 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2016-present Datadog, Inc. - -package logimpl - -import ( - "testing" - - "go.uber.org/fx" - - "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" -) - -func TestMockLogging(t *testing.T) { - log := fxutil.Test[log.Component](t, fx.Options( - fx.Supply(Params{}), - config.MockModule(), - MockModule(), - )) - log.Debugf("hello, world. %s", "hi") -} diff --git a/comp/core/log/mock/go.mod b/comp/core/log/mock/go.mod new file mode 100644 index 0000000000000..6ee76d97d67b6 --- /dev/null +++ b/comp/core/log/mock/go.mod @@ -0,0 +1,54 @@ +module github.com/DataDog/datadog-agent/comp/core/log/mock + +go 1.21.0 + +replace ( + github.com/DataDog/datadog-agent/comp/core/config => ../../config + github.com/DataDog/datadog-agent/comp/core/log/def => ../def + github.com/DataDog/datadog-agent/comp/core/secrets => ../../secrets + github.com/DataDog/datadog-agent/comp/def => ../../../def/ + github.com/DataDog/datadog-agent/pkg/collector/check/defaults => ../../../../pkg/collector/check/defaults + github.com/DataDog/datadog-agent/pkg/config/env => ../../../../pkg/config/env + github.com/DataDog/datadog-agent/pkg/config/logs => ../../../../pkg/config/logs/ + github.com/DataDog/datadog-agent/pkg/config/model => ../../../../pkg/config/model + github.com/DataDog/datadog-agent/pkg/config/setup => ../../../../pkg/config/setup + github.com/DataDog/datadog-agent/pkg/util/executable => ../../../../pkg/util/executable + github.com/DataDog/datadog-agent/pkg/util/filesystem => ../../../../pkg/util/filesystem + github.com/DataDog/datadog-agent/pkg/util/fxutil => ../../../../pkg/util/fxutil + github.com/DataDog/datadog-agent/pkg/util/hostname/validate => ../../../../pkg/util/hostname/validate + github.com/DataDog/datadog-agent/pkg/util/log => ../../../../pkg/util/log + github.com/DataDog/datadog-agent/pkg/util/optional => ../../../../pkg/util/optional + github.com/DataDog/datadog-agent/pkg/util/pointer => ../../../../pkg/util/pointer + github.com/DataDog/datadog-agent/pkg/util/scrubber => ../../../../pkg/util/scrubber + github.com/DataDog/datadog-agent/pkg/util/system => ../../../../pkg/util/system + github.com/DataDog/datadog-agent/pkg/util/system/socket => ../../../../pkg/util/system/socket + github.com/DataDog/datadog-agent/pkg/util/winutil => ../../../../pkg/util/winutil +) + +require ( + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/pkg/config/logs v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 +) + +require ( + github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/util/scrubber v0.56.0-rc.3 // indirect + github.com/DataDog/viper v1.13.5 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/magiconair/properties v1.8.1 // indirect + github.com/mitchellh/mapstructure v1.1.2 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/pelletier/go-toml v1.2.0 // indirect + github.com/spf13/afero v1.1.2 // indirect + github.com/spf13/cast v1.5.1 // indirect + github.com/spf13/jwalterweatherman v1.0.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + go.uber.org/atomic v1.11.0 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/comp/core/log/mock/go.sum b/comp/core/log/mock/go.sum new file mode 100644 index 0000000000000..584c372a509b5 --- /dev/null +++ b/comp/core/log/mock/go.sum @@ -0,0 +1,264 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/viper v1.13.5 h1:SZMcyMknYQN2jRY/40A16gUXexlNJOI8sDs1cWZnI64= +github.com/DataDog/viper v1.13.5/go.mod h1:wDdUVJ2SHaMaPrCZrlRCObwkubsX8j5sme3LaR/SGTc= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 h1:kHaBemcxl8o/pQ5VM1c8PVE1PubbNx3mjUr09OqWGCs= +github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/fd/NrVaLscBKmPigpZpn5YawRPw+e3Yo= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.13.0/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ= +golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/comp/core/log/logimpl/mock.go b/comp/core/log/mock/mock.go similarity index 50% rename from comp/core/log/logimpl/mock.go rename to comp/core/log/mock/mock.go index 85232bd415ab9..27be38f5f447d 100644 --- a/comp/core/log/logimpl/mock.go +++ b/comp/core/log/mock/mock.go @@ -3,39 +3,22 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -//go:build test - -package logimpl +// Package mock offers a mock for the logger. +package mock import ( - "context" - "fmt" - "os" "strings" "testing" "github.com/cihub/seelog" - "go.uber.org/fx" - "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" + log "github.com/DataDog/datadog-agent/comp/core/log/def" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" -) -// MockModule defines the fx options for the mock component. -func MockModule() fxutil.Module { - return fxutil.Component( - fx.Provide(newMockLogger), - ) -} - -// TraceMockModule defines the fx options for the mock component in its Trace variant. -func TraceMockModule() fxutil.Module { - return fxutil.Component( - fx.Provide(newTraceMockLogger), - ) -} + // we need this import for the seelog custom 'ShortFilePath' custom formater. We should migrate them to + // pkg/util/log + _ "github.com/DataDog/datadog-agent/pkg/config/logs" +) // tbWriter is an implementation of io.Writer that sends lines to // testing.TB#Log. @@ -51,33 +34,23 @@ func (tbw *tbWriter) Write(p []byte) (n int, err error) { return len(p), nil } -func newMockLogger(t testing.TB, lc fx.Lifecycle) (log.Component, error) { +// New returns a new mock for the log Component +func New(t testing.TB) log.Component { // Build a logger that only logs to t.Log(..) iface, err := seelog.LoggerFromWriterWithMinLevelAndFormat(&tbWriter{t}, seelog.TraceLvl, "%Date(2006-01-02 15:04:05 MST) | %LEVEL | (%ShortFilePath:%Line in %FuncShort) | %ExtraTextContext%Msg%n") if err != nil { - return nil, err + t.Fatal(err.Error()) } - // flush the seelog logger when the test app stops - lc.Append(fx.Hook{OnStop: func(context.Context) error { + t.Cleanup(func() { // stop using the logger to avoid a race condition pkglog.ChangeLogLevel(seelog.Default, "debug") iface.Flush() - return nil - }}) + }) // install the logger into pkg/util/log pkglog.ChangeLogLevel(iface, "debug") - return &logger{}, nil -} - -func newTraceMockLogger(t testing.TB, lc fx.Lifecycle, params Params, cfg config.Component) (log.Component, error) { - // Make sure we are setting a default value on purpose. - logFilePath := params.logFileFn(cfg) - if logFilePath != os.Getenv("DDTEST_DEFAULT_LOG_FILE_PATH") { - return nil, fmt.Errorf("unexpected default log file path: %q", logFilePath) - } - return newMockLogger(t, lc) + return pkglog.NewWrapper(2) } diff --git a/comp/core/log/tracelogimpl/trace_logger.go b/comp/core/log/tracelogimpl/trace_logger.go deleted file mode 100644 index 3c0df72f5d050..0000000000000 --- a/comp/core/log/tracelogimpl/trace_logger.go +++ /dev/null @@ -1,123 +0,0 @@ -// Unless explicitly stated otherwise all files in this repository are licensed -// under the Apache License Version 2.0. -// This product includes software developed at Datadog (https://www.datadoghq.com/). -// Copyright 2016-present Datadog, Inc. - -// Package tracelogimpl provides a component that implements the log.Component for the trace-agent logger -package tracelogimpl - -import ( - "context" - "errors" - "fmt" - - "go.uber.org/fx" - - "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" - pkgconfiglogs "github.com/DataDog/datadog-agent/pkg/config/logs" - tracelog "github.com/DataDog/datadog-agent/pkg/trace/log" - "github.com/DataDog/datadog-agent/pkg/trace/telemetry" - pkglog "github.com/DataDog/datadog-agent/pkg/util/log" -) - -const stackDepth = 3 - -// tracelogger implements the component -type tracelogger struct { - // this component is currently implementing a thin wrapper around - // pkg/trace/log, and uses globals in that package. -} - -// Until the log migration to component is done, we use *StackDepth to log. The log component add 1 layer to the call -// stack and *StackDepth add another. -// -// We check the current log level to avoid calling Sprintf when it's not needed (Sprintf from Tracef uses a lot a CPU) - -// Trace implements Component#Trace. -func (*tracelogger) Trace(v ...interface{}) { pkglog.TraceStackDepth(stackDepth, v...) } - -// Tracef implements Component#Tracef. -func (*tracelogger) Tracef(format string, params ...interface{}) { - pkglog.TracefStackDepth(stackDepth, format, params...) -} - -// Debug implements Component#Debug. -func (*tracelogger) Debug(v ...interface{}) { pkglog.DebugStackDepth(stackDepth, v...) } - -// Debugf implements Component#Debugf. -func (*tracelogger) Debugf(format string, params ...interface{}) { - pkglog.DebugfStackDepth(stackDepth, format, params...) -} - -// Info implements Component#Info. -func (*tracelogger) Info(v ...interface{}) { pkglog.InfoStackDepth(stackDepth, v...) } - -// Infof implements Component#Infof. -func (*tracelogger) Infof(format string, params ...interface{}) { - pkglog.InfofStackDepth(stackDepth, format, params...) -} - -// Warn implements Component#Warn. -func (*tracelogger) Warn(v ...interface{}) error { return pkglog.WarnStackDepth(stackDepth, v...) } - -// Warnf implements Component#Warnf. -func (*tracelogger) Warnf(format string, params ...interface{}) error { - return pkglog.WarnfStackDepth(stackDepth, format, params...) -} - -// Error implements Component#Error. -func (*tracelogger) Error(v ...interface{}) error { return pkglog.ErrorStackDepth(stackDepth, v...) } - -// Errorf implements Component#Errorf. -func (*tracelogger) Errorf(format string, params ...interface{}) error { - return pkglog.ErrorfStackDepth(stackDepth, format, params...) -} - -// Critical implements Component#Critical. -func (*tracelogger) Critical(v ...interface{}) error { - return pkglog.CriticalStackDepth(stackDepth, v...) -} - -// Criticalf implements Component#Criticalf. -func (*tracelogger) Criticalf(format string, params ...interface{}) error { - return pkglog.CriticalfStackDepth(stackDepth, format, params...) -} - -// Flush implements Component#Flush. -func (*tracelogger) Flush() { pkglog.Flush() } - -func newTraceLogger(lc fx.Lifecycle, params logimpl.Params, config config.Component, telemetryCollector telemetry.TelemetryCollector) (log.Component, error) { - return NewTraceLogger(lc, params, config, telemetryCollector) -} - -// NewTraceLogger creates a pkglog.Component using the provided config.LogConfig -func NewTraceLogger(lc fx.Lifecycle, params logimpl.Params, config config.LogConfig, telemetryCollector telemetry.TelemetryCollector) (log.Component, error) { - if !params.IsLogLevelFnSet() { - return nil, errors.New("must call one of core.BundleParams.ForOneShot or ForDaemon") - } - - err := pkgconfiglogs.SetupLogger( - pkgconfiglogs.LoggerName(params.LoggerName()), - params.LogLevelFn(config), - params.LogFileFn(config), - params.LogSyslogURIFn(config), - params.LogSyslogRFCFn(config), - params.LogToConsoleFn(config), - params.LogFormatJSONFn(config), - config) - if err != nil { - telemetryCollector.SendStartupError(telemetry.CantCreateLogger, err) - return nil, fmt.Errorf("Cannot create logger: %v", err) - } - - l := &tracelogger{} - tracelog.SetLogger(l) - lc.Append(fx.Hook{OnStop: func(context.Context) error { - l.Flush() - return nil - }}) - - return l, nil -} diff --git a/comp/core/pid/pidimpl/pid.go b/comp/core/pid/pidimpl/pid.go index aa1311db68452..1fae757733d72 100644 --- a/comp/core/pid/pidimpl/pid.go +++ b/comp/core/pid/pidimpl/pid.go @@ -12,7 +12,7 @@ import ( "go.uber.org/fx" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/pid" "github.com/DataDog/datadog-agent/pkg/pidfile" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/comp/core/settings/settingsimpl/settingsimpl.go b/comp/core/settings/settingsimpl/settingsimpl.go index eb9cdd8cb318a..669e22149a379 100644 --- a/comp/core/settings/settingsimpl/settingsimpl.go +++ b/comp/core/settings/settingsimpl/settingsimpl.go @@ -19,7 +19,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/pkg/config/model" diff --git a/comp/core/settings/settingsimpl/settingsimpl_test.go b/comp/core/settings/settingsimpl/settingsimpl_test.go index 7da32b1c237b3..eef96790f920b 100644 --- a/comp/core/settings/settingsimpl/settingsimpl_test.go +++ b/comp/core/settings/settingsimpl/settingsimpl_test.go @@ -22,7 +22,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/pkg/config/model" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -308,7 +309,7 @@ func TestRuntimeSettings(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( settings.Params{ Config: fxutil.Test[config.Component](t, config.MockModule()), diff --git a/comp/core/status/statusimpl/go.mod b/comp/core/status/statusimpl/go.mod index ba69e146bfe20..49db7dc423c67 100644 --- a/comp/core/status/statusimpl/go.mod +++ b/comp/core/status/statusimpl/go.mod @@ -8,7 +8,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/config => ../../config github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../../comp/core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../../comp/core/flare/types - github.com/DataDog/datadog-agent/comp/core/log => ../../log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../secrets github.com/DataDog/datadog-agent/comp/core/status => ../. github.com/DataDog/datadog-agent/comp/core/telemetry => ../../telemetry @@ -39,7 +40,8 @@ require ( github.com/DataDog/datadog-agent/comp/api/api/def v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/core/log/mock v0.0.0-00010101000000-000000000000 github.com/DataDog/datadog-agent/comp/core/status v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/setup v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/util/flavor v0.56.0-rc.3 @@ -57,7 +59,7 @@ require ( github.com/DataDog/datadog-agent/comp/def v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/collector/check/defaults v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/config/env v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/pkg/config/logs v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/config/logs v0.0.0-00010101000000-000000000000 // indirect github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/util/executable v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/util/filesystem v0.56.0-rc.3 // indirect @@ -71,6 +73,7 @@ require ( github.com/DataDog/datadog-agent/pkg/util/winutil v0.56.0-rc.3 // indirect github.com/DataDog/viper v1.13.5 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/dustin/go-humanize v1.0.1 // indirect @@ -106,6 +109,7 @@ require ( go.uber.org/zap v1.27.0 // indirect golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect golang.org/x/sys v0.21.0 // indirect + google.golang.org/protobuf v1.34.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/comp/core/status/statusimpl/go.sum b/comp/core/status/statusimpl/go.sum index 800d9b30855f8..63fe25a1a9858 100644 --- a/comp/core/status/statusimpl/go.sum +++ b/comp/core/status/statusimpl/go.sum @@ -18,7 +18,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -337,8 +336,8 @@ google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ij google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= +google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/comp/core/status/statusimpl/status.go b/comp/core/status/statusimpl/status.go index 3150d4e56c332..5f7a783231ae9 100644 --- a/comp/core/status/statusimpl/status.go +++ b/comp/core/status/statusimpl/status.go @@ -27,7 +27,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/comp/core/status/statusimpl/status_api_endpoints_test.go b/comp/core/status/statusimpl/status_api_endpoints_test.go index 611d4621daf58..6243b2c9776b6 100644 --- a/comp/core/status/statusimpl/status_api_endpoints_test.go +++ b/comp/core/status/statusimpl/status_api_endpoints_test.go @@ -22,7 +22,8 @@ import ( "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/status" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -31,7 +32,7 @@ import ( func getTestComp(t *testing.T, withError bool) provides { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewHeaderInformationProvider(mockHeaderProvider{ diff --git a/comp/core/status/statusimpl/status_test.go b/comp/core/status/statusimpl/status_test.go index c81c3aae8c36a..3011e48e6a026 100644 --- a/comp/core/status/statusimpl/status_test.go +++ b/comp/core/status/statusimpl/status_test.go @@ -19,7 +19,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/status" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/util/flavor" @@ -153,7 +154,7 @@ func TestGetStatus(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewInformationProvider(mockProvider{ @@ -485,7 +486,7 @@ func TestGetStatusDoNotRenderHeaderIfNoProviders(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewInformationProvider(mockProvider{ @@ -550,7 +551,7 @@ func TestGetStatusWithErrors(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewInformationProvider(mockProvider{ @@ -644,7 +645,7 @@ Status render errors func TestGetStatusBySection(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewInformationProvider(mockProvider{ @@ -820,7 +821,7 @@ func TestGetStatusBySectionsWithErrors(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewInformationProvider(mockProvider{ @@ -963,7 +964,7 @@ func TestGetStatusByMultipleSections(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewInformationProvider(mockProvider{ @@ -1091,7 +1092,7 @@ func TestFlareProvider(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply(agentParams), )) @@ -1104,7 +1105,7 @@ func TestFlareProvider(t *testing.T) { func TestGetStatusBySectionIncorrect(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( agentParams, status.NewInformationProvider(mockProvider{ diff --git a/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go b/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go index fb0d6da857f60..1ad6899406acf 100644 --- a/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go +++ b/comp/core/tagger/taggerimpl/collectors/workloadmeta_test.go @@ -17,7 +17,8 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/tagger/taglist" "github.com/DataDog/datadog-agent/comp/core/tagger/types" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" @@ -65,7 +66,7 @@ func TestHandleKubePod(t *testing.T) { } store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), fx.Supply(context.Background()), @@ -870,7 +871,7 @@ func TestHandleKubePodWithoutPvcAsTags(t *testing.T) { } store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), fx.Supply(context.Background()), @@ -1013,7 +1014,7 @@ func TestHandleKubePodNoContainerName(t *testing.T) { } store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), fx.Supply(context.Background()), @@ -1136,7 +1137,7 @@ func TestHandleKubeMetadata(t *testing.T) { taggerEntityID := fmt.Sprintf("kubernetes_metadata://%s", kubeMetadataEntityID.ID) store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), fx.Supply(context.Background()), @@ -1239,7 +1240,7 @@ func TestHandleECSTask(t *testing.T) { taggerEntityID := fmt.Sprintf("container_id://%s", containerID) store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), @@ -2052,7 +2053,7 @@ func TestHandleDelete(t *testing.T) { containerTaggerEntityID := fmt.Sprintf("container_id://%s", containerID) store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), @@ -2128,7 +2129,7 @@ func TestHandlePodWithDeletedContainer(t *testing.T) { collectorCh := make(chan []*types.TagInfo, 10) fakeStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), diff --git a/comp/core/tagger/taggerimpl/local/tagger_test.go b/comp/core/tagger/taggerimpl/local/tagger_test.go index 2c611802b61e5..bdfb0e28bdca4 100644 --- a/comp/core/tagger/taggerimpl/local/tagger_test.go +++ b/comp/core/tagger/taggerimpl/local/tagger_test.go @@ -13,7 +13,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" taggerTelemetry "github.com/DataDog/datadog-agent/comp/core/tagger/telemetry" "github.com/DataDog/datadog-agent/comp/core/tagger/types" "github.com/DataDog/datadog-agent/comp/core/telemetry" @@ -29,8 +30,8 @@ func TestTagBuilder(t *testing.T) { store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( fx.Supply(config.Params{}), - fx.Supply(logimpl.Params{}), - logimpl.MockModule(), + fx.Supply(log.Params{}), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), diff --git a/comp/core/tagger/taggerimpl/tagger.go b/comp/core/tagger/taggerimpl/tagger.go index 712296203e095..35f314aee591e 100644 --- a/comp/core/tagger/taggerimpl/tagger.go +++ b/comp/core/tagger/taggerimpl/tagger.go @@ -19,7 +19,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" configComponent "github.com/DataDog/datadog-agent/comp/core/config" - logComp "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" taggerComp "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl/collectors" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl/local" @@ -40,7 +40,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/fxutil" httputils "github.com/DataDog/datadog-agent/pkg/util/http" "github.com/DataDog/datadog-agent/pkg/util/kubernetes/kubelet" - "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/optional" "go.uber.org/fx" @@ -68,7 +67,7 @@ type dependencies struct { Lc fx.Lifecycle Config configComponent.Component - Log logComp.Component + Log log.Component Wmeta workloadmeta.Component Params taggerComp.Params Telemetry coretelemetry.Component @@ -115,6 +114,16 @@ type TaggerClient struct { dogstatsdCardinality types.TagCardinality tlmUDPOriginDetectionError coretelemetry.Counter telemetryStore *telemetry.Store + + log log.Component +} + +func createTaggerClient(defaultTagger taggerComp.Component, captureTagger taggerComp.Component, l log.Component) *TaggerClient { + return &TaggerClient{ + defaultTagger: defaultTagger, + captureTagger: captureTagger, + log: l, + } } // newTaggerClient returns a Component based on provided params, once it is provided, @@ -130,41 +139,23 @@ func newTaggerClient(deps dependencies) provides { if err != nil { deps.Log.Errorf("unable to deps.Configure the remote tagger: %s", err) - taggerClient = &TaggerClient{ - defaultTagger: local.NewFakeTagger(telemetryStore), - captureTagger: nil, - } + taggerClient = createTaggerClient(local.NewFakeTagger(telemetryStore), nil, deps.Log) } else if options.Disabled { deps.Log.Errorf("remote tagger is disabled in clc runner.") - taggerClient = &TaggerClient{ - defaultTagger: local.NewFakeTagger(telemetryStore), - captureTagger: nil, - } + taggerClient = createTaggerClient(local.NewFakeTagger(telemetryStore), nil, deps.Log) } else { - taggerClient = &TaggerClient{ - defaultTagger: remote.NewTagger(options, telemetryStore), - captureTagger: nil, - } + taggerClient = createTaggerClient(remote.NewTagger(options, telemetryStore), nil, deps.Log) } case taggerComp.NodeRemoteTaggerAgent: options, _ := remote.NodeAgentOptions(deps.Config) - taggerClient = &TaggerClient{ - defaultTagger: remote.NewTagger(options, telemetryStore), - captureTagger: nil, - } + taggerClient = createTaggerClient(remote.NewTagger(options, telemetryStore), nil, deps.Log) case taggerComp.LocalTaggerAgent: - taggerClient = &TaggerClient{ - defaultTagger: local.NewTagger(deps.Wmeta, telemetryStore), - captureTagger: nil, - } + taggerClient = createTaggerClient(local.NewTagger(deps.Wmeta, telemetryStore), nil, deps.Log) case taggerComp.FakeTagger: // all binaries are expected to provide their own tagger at startup. we // provide a fake tagger for testing purposes, as calling the global // tagger without proper initialization is very common there. - taggerClient = &TaggerClient{ - defaultTagger: local.NewFakeTagger(telemetryStore), - captureTagger: nil, - } + taggerClient = createTaggerClient(local.NewFakeTagger(telemetryStore), nil, deps.Log) } if taggerClient != nil { @@ -223,7 +214,7 @@ func (t *TaggerClient) writeList(w http.ResponseWriter, _ *http.Request) { jsonTags, err := json.Marshal(response) if err != nil { - httputils.SetJSONError(w, log.Errorf("Unable to marshal tagger list response: %s", err), 500) + httputils.SetJSONError(w, t.log.Errorf("Unable to marshal tagger list response: %s", err), 500) return } w.Write(jsonTags) @@ -401,7 +392,7 @@ func (t *TaggerClient) ResetCaptureTagger() { // enrichment, the metric and its tags is sent to the context key generator, which // is taking care of deduping the tags while generating the context key. func (t *TaggerClient) EnrichTags(tb tagset.TagsAccumulator, originInfo taggertypes.OriginInfo) { - cardinality := taggerCardinality(originInfo.Cardinality, t.dogstatsdCardinality) + cardinality := taggerCardinality(originInfo.Cardinality, t.dogstatsdCardinality, t.log) productOrigin := originInfo.ProductOrigin // If origin_detection_unified is disabled, we use DogStatsD's Legacy Origin Detection. @@ -449,7 +440,7 @@ func (t *TaggerClient) EnrichTags(tb tagset.TagsAccumulator, originInfo taggerty if originInfo.FromUDS != packets.NoOrigin && (originInfo.FromTag == "" || !t.datadogConfig.dogstatsdEntityIDPrecedenceEnabled) { if err := t.AccumulateTagsFor(originInfo.FromUDS, cardinality, tb); err != nil { - log.Errorf(err.Error()) + t.log.Errorf(err.Error()) } } @@ -467,23 +458,23 @@ func (t *TaggerClient) EnrichTags(tb tagset.TagsAccumulator, originInfo taggerty if originFromClient != "" { if err := t.AccumulateTagsFor(originFromClient, cardinality, tb); err != nil { t.tlmUDPOriginDetectionError.Inc() - log.Tracef("Cannot get tags for entity %s: %s", originFromClient, err) + t.log.Tracef("Cannot get tags for entity %s: %s", originFromClient, err) } } default: // Tag using Local Data if originInfo.FromUDS != packets.NoOrigin { if err := t.AccumulateTagsFor(originInfo.FromUDS, cardinality, tb); err != nil { - log.Errorf(err.Error()) + t.log.Errorf(err.Error()) } } if err := t.AccumulateTagsFor(containers.BuildTaggerEntityName(originInfo.FromMsg), cardinality, tb); err != nil { - log.Tracef("Cannot get tags for entity %s: %s", originInfo.FromMsg, err) + t.log.Tracef("Cannot get tags for entity %s: %s", originInfo.FromMsg, err) } if err := t.AccumulateTagsFor(kubelet.KubePodTaggerEntityPrefix+originInfo.FromTag, cardinality, tb); err != nil { - log.Tracef("Cannot get tags for entity %s: %s", originInfo.FromTag, err) + t.log.Tracef("Cannot get tags for entity %s: %s", originInfo.FromTag, err) } // Tag using External Data. @@ -504,7 +495,7 @@ func (t *TaggerClient) EnrichTags(tb tagset.TagsAccumulator, originInfo taggerty case strings.HasPrefix(item, externalDataInitPrefix): parsedExternalData.init, initParsingError = strconv.ParseBool(item[len(externalDataInitPrefix):]) if initParsingError != nil { - log.Tracef("Cannot parse bool from %s: %s", item[len(externalDataInitPrefix):], initParsingError) + t.log.Tracef("Cannot parse bool from %s: %s", item[len(externalDataInitPrefix):], initParsingError) } case strings.HasPrefix(item, externalDataContainerNamePrefix): parsedExternalData.containerName = item[len(externalDataContainerNamePrefix):] @@ -516,27 +507,27 @@ func (t *TaggerClient) EnrichTags(tb tagset.TagsAccumulator, originInfo taggerty // Accumulate tags for pod UID if parsedExternalData.podUID != "" { if err := t.AccumulateTagsFor(kubelet.KubePodTaggerEntityPrefix+parsedExternalData.podUID, cardinality, tb); err != nil { - log.Tracef("Cannot get tags for entity %s: %s", originInfo.FromMsg, err) + t.log.Tracef("Cannot get tags for entity %s: %s", originInfo.FromMsg, err) } } // Generate container ID from External Data generatedContainerID, err := t.generateContainerIDFromExternalData(parsedExternalData, metrics.GetProvider(optional.NewOption(t.wmeta)).GetMetaCollector()) if err != nil { - log.Tracef("Failed to generate container ID from %s: %s", originInfo.ExternalData, err) + t.log.Tracef("Failed to generate container ID from %s: %s", originInfo.ExternalData, err) } // Accumulate tags for generated container ID if generatedContainerID != "" { if err := t.AccumulateTagsFor(containers.BuildTaggerEntityName(generatedContainerID), cardinality, tb); err != nil { - log.Tracef("Cannot get tags for entity %s: %s", generatedContainerID, err) + t.log.Tracef("Cannot get tags for entity %s: %s", generatedContainerID, err) } } } } if err := t.globalTagBuilder(cardinality, tb); err != nil { - log.Error(err.Error()) + t.log.Error(err.Error()) } } @@ -570,7 +561,7 @@ func (t *TaggerClient) parseEntityID(entityID string, metricsProvider provider.C time.Second, ) if err != nil { - log.Debugf("Error getting container ID for pod UID and container name: %s", err) + t.log.Debugf("Error getting container ID for pod UID and container name: %s", err) return entityID } return containers.BuildTaggerEntityName(cid) @@ -591,14 +582,15 @@ func (t *TaggerClient) DogstatsdCardinality() types.TagCardinality { // taggerCardinality converts tagger cardinality string to types.TagCardinality // It should be defaulted to DogstatsdCardinality if the string is empty or unknown func taggerCardinality(cardinality string, - defaultCardinality types.TagCardinality) types.TagCardinality { + defaultCardinality types.TagCardinality, + l log.Component) types.TagCardinality { if cardinality == "" { return defaultCardinality } taggerCardinality, err := types.StringToTagCardinality(cardinality) if err != nil { - log.Tracef("Couldn't convert cardinality tag: %v", err) + l.Tracef("Couldn't convert cardinality tag: %v", err) return defaultCardinality } @@ -620,7 +612,7 @@ type optionalTaggerDeps struct { Lc fx.Lifecycle Config configComponent.Component - Log logComp.Component + Log log.Component Wmeta optional.Option[workloadmeta.Component] Telemetry coretelemetry.Component } diff --git a/comp/core/tagger/taggerimpl/tagger_mock.go b/comp/core/tagger/taggerimpl/tagger_mock.go index 605f37d3cf81b..0ab0db74c98a9 100644 --- a/comp/core/tagger/taggerimpl/tagger_mock.go +++ b/comp/core/tagger/taggerimpl/tagger_mock.go @@ -16,7 +16,8 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl/local" @@ -63,8 +64,8 @@ func MockModule() fxutil.Module { return fxutil.Component( fx.Provide(NewMock), fx.Supply(config.Params{}), - fx.Supply(logimpl.Params{}), - logimpl.MockModule(), + fx.Supply(log.Params{}), + fx.Provide(func(t testing.TB) log.Component { return logmock.New(t) }), config.MockModule(), sysprobeconfigimpl.MockModule(), fx.Supply(tagger.NewFakeTaggerParams()), diff --git a/comp/core/tagger/taggerimpl/tagger_test.go b/comp/core/tagger/taggerimpl/tagger_test.go index 80ed6a8e295be..ce2260cd3d1d0 100644 --- a/comp/core/tagger/taggerimpl/tagger_test.go +++ b/comp/core/tagger/taggerimpl/tagger_test.go @@ -11,6 +11,7 @@ import ( "github.com/stretchr/testify/assert" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/types" configmock "github.com/DataDog/datadog-agent/pkg/config/mock" @@ -226,7 +227,7 @@ func TestParseEntityID(t *testing.T) { }, } { t.Run(tt.name, func(t *testing.T) { - fakeCl := TaggerClient{} + fakeCl := TaggerClient{log: logmock.New(t)} assert.Equal(t, tt.expected, fakeCl.parseEntityID(tt.entityID, tt.cidProvider)) }) } @@ -271,7 +272,8 @@ func TestTaggerCardinality(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.Equal(t, tt.want, taggerCardinality(tt.cardinality, tagger.DogstatsdCardinality())) + l := logmock.New(t) + assert.Equal(t, tt.want, taggerCardinality(tt.cardinality, tagger.DogstatsdCardinality(), l)) }) } } diff --git a/comp/core/workloadmeta/collectors/internal/containerd/container_builder_test.go b/comp/core/workloadmeta/collectors/internal/containerd/container_builder_test.go index 3ee08dcaea7ba..f305375990f4d 100644 --- a/comp/core/workloadmeta/collectors/internal/containerd/container_builder_test.go +++ b/comp/core/workloadmeta/collectors/internal/containerd/container_builder_test.go @@ -24,7 +24,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -241,7 +242,7 @@ func TestBuildWorkloadMetaContainer(t *testing.T) { // Create a workload meta global store containing image metadata workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/comp/core/workloadmeta/collectors/internal/containerd/event_builder_test.go b/comp/core/workloadmeta/collectors/internal/containerd/event_builder_test.go index 1ea4b3370b0cb..5e20df613ac61 100644 --- a/comp/core/workloadmeta/collectors/internal/containerd/event_builder_test.go +++ b/comp/core/workloadmeta/collectors/internal/containerd/event_builder_test.go @@ -25,7 +25,8 @@ import ( "google.golang.org/protobuf/proto" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -69,7 +70,7 @@ func TestBuildCollectorEvent(t *testing.T) { client := containerdClient(&container) workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/comp/core/workloadmeta/impl/dump_test.go b/comp/core/workloadmeta/impl/dump_test.go index 101d518a7c9bc..0324e6c3ec1c9 100644 --- a/comp/core/workloadmeta/impl/dump_test.go +++ b/comp/core/workloadmeta/impl/dump_test.go @@ -13,7 +13,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" wmdef "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -21,7 +22,7 @@ import ( func TestDump(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(wmdef.NewParams()), diff --git a/comp/core/workloadmeta/impl/store_example_test.go b/comp/core/workloadmeta/impl/store_example_test.go index 0d4ee3c763c58..3cfb586464d3a 100644 --- a/comp/core/workloadmeta/impl/store_example_test.go +++ b/comp/core/workloadmeta/impl/store_example_test.go @@ -12,7 +12,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" wmdef "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -20,7 +21,7 @@ import ( func TestExampleStoreSubscribe(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) diff --git a/comp/core/workloadmeta/impl/store_test.go b/comp/core/workloadmeta/impl/store_test.go index fb9963ebd9605..1ce54091f673f 100644 --- a/comp/core/workloadmeta/impl/store_test.go +++ b/comp/core/workloadmeta/impl/store_test.go @@ -16,7 +16,8 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors/util" wmdef "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/errors" @@ -37,7 +38,7 @@ func newWorkloadmetaObject(deps dependencies) *workloadmeta { func TestHandleEvents(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -660,7 +661,7 @@ func TestSubscribe(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -701,7 +702,7 @@ func TestSubscribe(t *testing.T) { func TestGetKubernetesDeployment(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -744,7 +745,7 @@ func TestGetKubernetesDeployment(t *testing.T) { func TestGetProcess(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -823,7 +824,7 @@ func TestListContainers(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -861,7 +862,7 @@ func TestListContainersWithFilter(t *testing.T) { } deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -920,7 +921,7 @@ func TestListProcesses(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -958,7 +959,7 @@ func TestListProcessesWithFilter(t *testing.T) { } deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1075,7 +1076,7 @@ func TestGetKubernetesPodByName(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1136,7 +1137,7 @@ func TestListImages(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1188,7 +1189,7 @@ func TestGetImage(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1266,7 +1267,7 @@ func TestListECSTasks(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1357,7 +1358,7 @@ func TestResetProcesses(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1403,7 +1404,7 @@ func TestResetProcesses(t *testing.T) { func TestGetKubernetesMetadata(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1446,7 +1447,7 @@ func TestGetKubernetesMetadata(t *testing.T) { func TestListKubernetesMetadata(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1657,7 +1658,7 @@ func TestReset(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1704,7 +1705,7 @@ func TestNoDataRace(t *testing.T) { // This test ensures that no race conditions are encountered when the "--race" flag is passed // to the test process and an entity is accessed in a different thread than the one handling events deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) @@ -1734,7 +1735,7 @@ func TestNoDataRace(t *testing.T) { func TestPushEvents(t *testing.T) { deps := fxutil.Test[dependencies](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(wmdef.NewParams()), )) diff --git a/comp/core/workloadmeta/impl/workloadmeta.go b/comp/core/workloadmeta/impl/workloadmeta.go index e9dc0462359d6..b26021d9ee4a5 100644 --- a/comp/core/workloadmeta/impl/workloadmeta.go +++ b/comp/core/workloadmeta/impl/workloadmeta.go @@ -17,7 +17,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" wmdef "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/util/common" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/comp/dogstatsd/server/server.go b/comp/dogstatsd/server/server.go index 6431e0f1b6335..b1f97ef2f34db 100644 --- a/comp/dogstatsd/server/server.go +++ b/comp/dogstatsd/server/server.go @@ -19,7 +19,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" configComponent "github.com/DataDog/datadog-agent/comp/core/config" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/telemetry" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/comp/dogstatsd/listeners" @@ -69,7 +69,7 @@ type dependencies struct { Demultiplexer aggregator.Demultiplexer - Log logComponent.Component + Log log.Component Config configComponent.Component Debug serverdebug.Component Replay replay.Component @@ -98,7 +98,7 @@ type cachedOriginCounter struct { // Server represent a Dogstatsd server type server struct { - log logComponent.Component + log log.Component config config.Reader // listeners are the instantiated socket listener (UDS or UDP or both) listeners []listeners.StatsdListener @@ -197,7 +197,7 @@ func newServer(deps dependencies) provides { } } -func newServerCompat(cfg config.Reader, log logComponent.Component, capture replay.Component, debug serverdebug.Component, serverless bool, demux aggregator.Demultiplexer, wmeta optional.Option[workloadmeta.Component], pidMap pidmap.Component, telemetrycomp telemetry.Component) *server { +func newServerCompat(cfg config.Reader, log log.Component, capture replay.Component, debug serverdebug.Component, serverless bool, demux aggregator.Demultiplexer, wmeta optional.Option[workloadmeta.Component], pidMap pidmap.Component, telemetrycomp telemetry.Component) *server { // This needs to be done after the configuration is loaded once.Do(func() { initTelemetry() }) var stats *util.Stats @@ -815,7 +815,7 @@ func (s *server) parseServiceCheckMessage(parser *parser, message []byte, origin return serviceCheck, nil } -func getBuckets(cfg config.Reader, logger logComponent.Component, option string) []float64 { +func getBuckets(cfg config.Reader, logger log.Component, option string) []float64 { if !cfg.IsSet(option) { return nil } diff --git a/comp/dogstatsd/server/server_test.go b/comp/dogstatsd/server/server_test.go index 0b4d461dfeaa8..8e92e19a34bb7 100644 --- a/comp/dogstatsd/server/server_test.go +++ b/comp/dogstatsd/server/server_test.go @@ -24,7 +24,7 @@ import ( "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" "github.com/DataDog/datadog-agent/comp/core" configComponent "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/telemetry" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" diff --git a/comp/dogstatsd/server/serverless.go b/comp/dogstatsd/server/serverless.go index cafbc2e007591..4995ade81b07e 100644 --- a/comp/dogstatsd/server/serverless.go +++ b/comp/dogstatsd/server/serverless.go @@ -9,7 +9,7 @@ package server import ( "context" - logComponentImpl "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logComponentImpl "github.com/DataDog/datadog-agent/comp/core/log/impl" telemetry "github.com/DataDog/datadog-agent/comp/core/telemetry/noopsimpl" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/comp/dogstatsd/pidmap/pidmapimpl" diff --git a/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go b/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go index 8e6b07abfeeb5..887a2dd517f73 100644 --- a/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go +++ b/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go @@ -22,8 +22,8 @@ import ( commonpath "github.com/DataDog/datadog-agent/cmd/agent/common/path" configComponent "github.com/DataDog/datadog-agent/comp/core/config" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" - logComponentImpl "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logComponentImpl "github.com/DataDog/datadog-agent/comp/core/log/impl" serverdebug "github.com/DataDog/datadog-agent/comp/dogstatsd/serverDebug" "github.com/DataDog/datadog-agent/pkg/aggregator/ckey" "github.com/DataDog/datadog-agent/pkg/config" @@ -41,7 +41,7 @@ func Module() fxutil.Module { type dependencies struct { fx.In - Log logComponent.Component + Log log.Component Config configComponent.Component } @@ -56,7 +56,7 @@ type metricStat struct { type serverDebugImpl struct { sync.Mutex - log logComponent.Component + log log.Component enabled *atomic.Bool Stats map[ckey.ContextKey]metricStat `json:"stats"` // counting number of metrics processed last X seconds @@ -82,9 +82,9 @@ func newServerDebug(deps dependencies) serverdebug.Component { return newServerDebugCompat(deps.Log, deps.Config) } -func newServerDebugCompat(log logComponent.Component, cfg config.Reader) serverdebug.Component { +func newServerDebugCompat(l log.Component, cfg config.Reader) serverdebug.Component { sd := &serverDebugImpl{ - log: log, + log: l, enabled: atomic.NewBool(false), Stats: make(map[ckey.ContextKey]metricStat), metricsCounts: metricsCountBuckets{ diff --git a/comp/forwarder/defaultforwarder/blocked_endpoints.go b/comp/forwarder/defaultforwarder/blocked_endpoints.go index 8976299980ad2..043d451c2777f 100644 --- a/comp/forwarder/defaultforwarder/blocked_endpoints.go +++ b/comp/forwarder/defaultforwarder/blocked_endpoints.go @@ -10,7 +10,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/util/backoff" ) diff --git a/comp/forwarder/defaultforwarder/blocked_endpoints_test.go b/comp/forwarder/defaultforwarder/blocked_endpoints_test.go index 8347be6141ae9..bf8c58dfc06f3 100644 --- a/comp/forwarder/defaultforwarder/blocked_endpoints_test.go +++ b/comp/forwarder/defaultforwarder/blocked_endpoints_test.go @@ -14,11 +14,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/util/backoff" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) func init() { @@ -27,7 +25,7 @@ func init() { func TestMinBackoffFactorValid(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) policy, ok := e.backoffPolicy.(*backoff.ExpBackoffPolicy) @@ -53,7 +51,7 @@ func TestMinBackoffFactorValid(t *testing.T) { func TestBaseBackoffTimeValid(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) policy, ok := e.backoffPolicy.(*backoff.ExpBackoffPolicy) @@ -80,7 +78,7 @@ func TestBaseBackoffTimeValid(t *testing.T) { func TestMaxBackoffTimeValid(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) policy, ok := e.backoffPolicy.(*backoff.ExpBackoffPolicy) @@ -107,7 +105,7 @@ func TestMaxBackoffTimeValid(t *testing.T) { func TestRecoveryIntervalValid(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) policy, ok := e.backoffPolicy.(*backoff.ExpBackoffPolicy) @@ -144,7 +142,7 @@ func TestRecoveryIntervalValid(t *testing.T) { // Test we increase delay on average func TestGetBackoffDurationIncrease(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) previousBackoffDuration := time.Duration(0) * time.Second backoffIncrease := 0 @@ -172,7 +170,7 @@ func TestGetBackoffDurationIncrease(t *testing.T) { func TestMaxGetBackoffDuration(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) backoffDuration := e.getBackoffDuration(100) @@ -184,7 +182,7 @@ func TestMaxGetBackoffDuration(t *testing.T) { func TestMaxErrors(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) previousBackoffDuration := time.Duration(0) * time.Second attempts := 0 @@ -210,7 +208,7 @@ func TestMaxErrors(t *testing.T) { func TestBlock(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) e.close("test") @@ -222,7 +220,7 @@ func TestBlock(t *testing.T) { func TestMaxBlock(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) e.close("test") e.errorPerEndpoint["test"].nbError = 1000000 @@ -243,7 +241,7 @@ func TestMaxBlock(t *testing.T) { func TestUnblock(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) e.close("test") @@ -263,7 +261,7 @@ func TestUnblock(t *testing.T) { func TestMaxUnblock(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) e.close("test") @@ -278,7 +276,7 @@ func TestMaxUnblock(t *testing.T) { func TestUnblockUnknown(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) e.recover("test") @@ -288,7 +286,7 @@ func TestUnblockUnknown(t *testing.T) { func TestIsBlock(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) assert.False(t, e.isBlock("test")) @@ -302,7 +300,7 @@ func TestIsBlock(t *testing.T) { func TestIsBlockTiming(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) // setting an old close @@ -316,7 +314,7 @@ func TestIsBlockTiming(t *testing.T) { func TestIsblockUnknown(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) e := newBlockedEndpoints(mockConfig, log) assert.False(t, e.isBlock("test")) diff --git a/comp/forwarder/defaultforwarder/default_forwarder.go b/comp/forwarder/defaultforwarder/default_forwarder.go index f0c2fe41eab59..16f658bf896b6 100644 --- a/comp/forwarder/defaultforwarder/default_forwarder.go +++ b/comp/forwarder/defaultforwarder/default_forwarder.go @@ -17,7 +17,7 @@ import ( "go.uber.org/atomic" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/endpoints" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/internal/retry" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" diff --git a/comp/forwarder/defaultforwarder/default_forwarder_test.go b/comp/forwarder/defaultforwarder/default_forwarder_test.go index 8bfedf6af2e3c..1f95cd572921f 100644 --- a/comp/forwarder/defaultforwarder/default_forwarder_test.go +++ b/comp/forwarder/defaultforwarder/default_forwarder_test.go @@ -10,8 +10,7 @@ import ( "testing" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/stretchr/testify/assert" @@ -33,7 +32,7 @@ func TestDefaultForwarderUpdateAPIKey(t *testing.T) { config.MockModule(), )) mockConfig.Set("api_key", "api_key1", pkgconfigmodel.SourceAgentRuntime) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) // starting API Keys, before the update keysPerDomains := map[string][]string{ diff --git a/comp/forwarder/defaultforwarder/domain_forwarder.go b/comp/forwarder/defaultforwarder/domain_forwarder.go index bfe20d5ce972d..3264cebc57c56 100644 --- a/comp/forwarder/defaultforwarder/domain_forwarder.go +++ b/comp/forwarder/defaultforwarder/domain_forwarder.go @@ -13,7 +13,7 @@ import ( "go.uber.org/atomic" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/internal/retry" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" ) diff --git a/comp/forwarder/defaultforwarder/domain_forwarder_test.go b/comp/forwarder/defaultforwarder/domain_forwarder_test.go index 8e3c19d2ed7e3..c37759f6f9ff7 100644 --- a/comp/forwarder/defaultforwarder/domain_forwarder_test.go +++ b/comp/forwarder/defaultforwarder/domain_forwarder_test.go @@ -16,17 +16,16 @@ import ( "github.com/stretchr/testify/require" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/internal/retry" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) func TestNewDomainForwarder(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 120*time.Second, false) assert.NotNil(t, forwarder) @@ -45,7 +44,7 @@ func TestNewDomainForwarder(t *testing.T) { func TestDomainForwarderStart(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) err := forwarder.Start() @@ -66,7 +65,7 @@ func TestDomainForwarderStart(t *testing.T) { func TestDomainForwarderInit(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) forwarder.init() assert.Len(t, forwarder.workers, 0) @@ -75,7 +74,7 @@ func TestDomainForwarderInit(t *testing.T) { func TestDomainForwarderStop(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) forwarder.Stop(false) // this should be a noop forwarder.Start() @@ -88,7 +87,7 @@ func TestDomainForwarderStop(t *testing.T) { func TestDomainForwarderStop_WithConnectionReset(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 120*time.Second, false) forwarder.Stop(false) // this should be a noop forwarder.Start() @@ -101,7 +100,7 @@ func TestDomainForwarderStop_WithConnectionReset(t *testing.T) { func TestDomainForwarderSendHTTPTransactions(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) tr := newTestTransactionDomainForwarder() @@ -131,7 +130,7 @@ multi_region_failover: site: bar.ddhq.com ` mockConfig := pkgconfigsetup.ConfFromYAML(datadogYaml) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) // HA forwarder forwarder := newDomainForwarderForTest(mockConfig, log, 0, true) trSeries := newTestTransactionWithKindDomainForwarder(transaction.Series) @@ -179,7 +178,7 @@ multi_region_failover: site: bar.ddhq.com ` mockConfig := pkgconfigsetup.ConfFromYAML(datadogYaml) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) // HA forwarder forwarder := newDomainForwarderForTest(mockConfig, log, 0, true) trSeries := newTestTransactionWithKindDomainForwarder(transaction.Series) @@ -220,7 +219,7 @@ multi_region_failover: func TestRequeueTransaction(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) tr := transaction.NewHTTPTransaction() requireLenForwarderRetryQueue(t, forwarder, 0) @@ -230,7 +229,7 @@ func TestRequeueTransaction(t *testing.T) { func TestRetryTransactions(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) forwarder.init() @@ -265,7 +264,7 @@ func TestRetryTransactions(t *testing.T) { func TestForwarderRetry(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) forwarder.Start() defer forwarder.Stop(false) @@ -301,7 +300,7 @@ func TestForwarderRetry(t *testing.T) { func TestForwarderRetryLifo(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) forwarder.init() @@ -332,7 +331,7 @@ func TestForwarderRetryLifo(t *testing.T) { func TestForwarderRetryLimitQueue(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) forwarder.init() forwarder.blockedList.close("blocked") @@ -378,7 +377,7 @@ func TestDomainForwarderRetryQueueAllPayloadsMaxSize(t *testing.T) { telemetry, retry.NewPointCountTelemetryMock()) mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarder(mockConfig, log, "test", false, transactionRetryQueue, 0, 10, transaction.SortByCreatedTimeAndPriority{HighPriorityFirst: true}, retry.NewPointCountTelemetry("domain")) forwarder.blockedList.close("blocked") forwarder.blockedList.errorPerEndpoint["blocked"].until = time.Now().Add(1 * time.Minute) @@ -406,7 +405,7 @@ func TestDomainForwarderRetryQueueAllPayloadsMaxSize(t *testing.T) { func TestDomainForwarderInitConfigs(t *testing.T) { // Test default values mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := newDomainForwarderForTest(mockConfig, log, 0, false) forwarder.init() assert.Equal(t, 100, cap(forwarder.highPrio)) diff --git a/comp/forwarder/defaultforwarder/forwarder.go b/comp/forwarder/defaultforwarder/forwarder.go index d6accf3af2150..1d0041e8f9126 100644 --- a/comp/forwarder/defaultforwarder/forwarder.go +++ b/comp/forwarder/defaultforwarder/forwarder.go @@ -11,7 +11,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" ) diff --git a/comp/forwarder/defaultforwarder/forwarder_health.go b/comp/forwarder/defaultforwarder/forwarder_health.go index 11a8cdc01efc8..fbd29370ec5cf 100644 --- a/comp/forwarder/defaultforwarder/forwarder_health.go +++ b/comp/forwarder/defaultforwarder/forwarder_health.go @@ -15,7 +15,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/endpoints" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" diff --git a/comp/forwarder/defaultforwarder/forwarder_health_test.go b/comp/forwarder/defaultforwarder/forwarder_health_test.go index bfec4a3acae51..50827c2d5e0f0 100644 --- a/comp/forwarder/defaultforwarder/forwarder_health_test.go +++ b/comp/forwarder/defaultforwarder/forwarder_health_test.go @@ -18,8 +18,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -38,7 +37,7 @@ func TestCheckValidAPIKey(t *testing.T) { ts1.URL: {"api_key1", "api_key2"}, ts2.URL: {"key3"}, } - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) cfg := fxutil.Test[config.Component](t, config.MockModule()) fh := forwarderHealth{log: log, config: cfg, domainResolvers: resolver.NewSingleDomainResolvers(keysPerDomains)} fh.init() @@ -79,7 +78,7 @@ func TestComputeDomainsURL(t *testing.T) { for _, keys := range expectedMap { sort.Strings(keys) } - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) fh := forwarderHealth{log: log, domainResolvers: resolver.NewSingleDomainResolvers(keysPerDomains)} fh.init() @@ -119,7 +118,7 @@ func TestCheckValidAPIKeyErrors(t *testing.T) { ts2.URL: {"key3"}, ts3.URL: {"key4"}, } - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) cfg := fxutil.Test[config.Component](t, config.MockModule()) fh := forwarderHealth{log: log, config: cfg} fh.init() @@ -166,7 +165,7 @@ func TestUpdateAPIKey(t *testing.T) { ts2.URL: {"api_key3"}, } - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) cfg := fxutil.Test[config.Component](t, config.MockModule()) fh := forwarderHealth{log: log, config: cfg, domainResolvers: resolver.NewSingleDomainResolvers(keysPerDomains)} diff --git a/comp/forwarder/defaultforwarder/forwarder_test.go b/comp/forwarder/defaultforwarder/forwarder_test.go index 14a7cf4720db0..4aff0101a6078 100644 --- a/comp/forwarder/defaultforwarder/forwarder_test.go +++ b/comp/forwarder/defaultforwarder/forwarder_test.go @@ -18,15 +18,13 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/atomic" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/endpoints" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" configUtils "github.com/DataDog/datadog-agent/pkg/config/utils" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/version" ) @@ -51,7 +49,7 @@ var ( func TestNewDefaultForwarder(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(keysPerDomains))) assert.NotNil(t, forwarder) @@ -83,7 +81,7 @@ func TestFeature(t *testing.T) { func TestStart(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(monoKeysDomains))) err := forwarder.Start() defer forwarder.Stop() @@ -110,7 +108,7 @@ func TestStopWithPurgingTransaction(t *testing.T) { } func testStop(t *testing.T, mockConfig pkgconfigmodel.Config) { - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(keysPerDomains))) assert.Equal(t, Stopped, forwarder.State()) forwarder.Stop() // this should be a noop @@ -127,7 +125,7 @@ func testStop(t *testing.T, mockConfig pkgconfigmodel.Config) { func TestSubmitIfStopped(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(monoKeysDomains))) require.NotNil(t, forwarder) @@ -143,7 +141,7 @@ func TestSubmitIfStopped(t *testing.T) { func TestCreateHTTPTransactions(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(keysPerDomains))) endpoint := transaction.Endpoint{Route: "/api/foo", Name: "foo"} p1 := []byte("A payload") @@ -176,7 +174,7 @@ func TestCreateHTTPTransactions(t *testing.T) { func TestCreateHTTPTransactionsWithMultipleDomains(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(keysWithMultipleDomains))) endpoint := transaction.Endpoint{Route: "/api/foo", Name: "foo"} p1 := []byte("A payload") @@ -217,7 +215,7 @@ func TestCreateHTTPTransactionsWithDifferentResolvers(t *testing.T) { additionalResolver.RegisterAlternateDestination("diversion.domain", "diverted_name", resolver.Vector) resolvers["datadog.vector"] = additionalResolver mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolvers)) endpoint := transaction.Endpoint{Route: "/api/foo", Name: "diverted_name"} p1 := []byte("A payload") @@ -261,7 +259,7 @@ func TestCreateHTTPTransactionsWithOverrides(t *testing.T) { r.RegisterAlternateDestination("observability_pipelines_worker.tld", "diverted", resolver.Vector) resolvers[testDomain] = r mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolvers)) endpoint := transaction.Endpoint{Route: "/api/foo", Name: "no_diverted"} @@ -288,7 +286,7 @@ func TestArbitraryTagsHTTPHeader(t *testing.T) { mockConfig := pkgconfigsetup.Conf() mockConfig.SetWithoutSource("allow_arbitrary_tags", true) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(keysPerDomains))) endpoint := transaction.Endpoint{Route: "/api/foo", Name: "foo"} payload := []byte("A payload") @@ -301,7 +299,7 @@ func TestArbitraryTagsHTTPHeader(t *testing.T) { func TestSendHTTPTransactions(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(keysPerDomains))) endpoint := transaction.Endpoint{Route: "/api/foo", Name: "foo"} p1 := []byte("A payload") @@ -321,7 +319,7 @@ func TestSendHTTPTransactions(t *testing.T) { func TestSubmitV1Intake(t *testing.T) { mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) forwarder := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(monoKeysDomains))) forwarder.Start() defer forwarder.Stop() @@ -364,7 +362,7 @@ func TestForwarderEndtoEnd(t *testing.T) { mockConfig := pkgconfigsetup.Conf() mockConfig.SetWithoutSource("dd_url", ts.URL) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) f := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(map[string][]string{ts.URL: {"api_key1", "api_key2"}, "invalid": {}, "invalid2": nil}))) f.Start() @@ -420,7 +418,7 @@ func TestTransactionEventHandlers(t *testing.T) { mockConfig := pkgconfigsetup.Conf() mockConfig.SetWithoutSource("dd_url", ts.URL) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) f := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(map[string][]string{ts.URL: {"api_key1"}}))) _ = f.Start() @@ -475,7 +473,7 @@ func TestTransactionEventHandlersOnRetry(t *testing.T) { mockConfig := pkgconfigsetup.Conf() mockConfig.SetWithoutSource("dd_url", ts.URL) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) f := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(map[string][]string{ts.URL: {"api_key1"}}))) _ = f.Start() @@ -526,7 +524,7 @@ func TestTransactionEventHandlersNotRetryable(t *testing.T) { mockConfig := pkgconfigsetup.Conf() mockConfig.SetWithoutSource("dd_url", ts.URL) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) f := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(map[string][]string{ts.URL: {"api_key1"}}))) _ = f.Start() @@ -580,7 +578,7 @@ func TestProcessLikePayloadResponseTimeout(t *testing.T) { defaultResponseTimeout = responseTimeout }() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) f := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(map[string][]string{ts.URL: {"api_key1"}}))) _ = f.Start() @@ -631,7 +629,7 @@ func TestHighPriorityTransaction(t *testing.T) { flushInterval = 500 * time.Millisecond defer func() { flushInterval = oldFlushInterval }() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) f := NewDefaultForwarder(mockConfig, log, NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(map[string][]string{ts.URL: {"api_key1"}}))) f.Start() @@ -677,7 +675,7 @@ func TestCustomCompletionHandler(t *testing.T) { done <- struct{}{} } mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) options := NewOptionsWithResolvers(mockConfig, log, resolver.NewSingleDomainResolvers(map[string][]string{ srv.URL: {"api_key1"}, })) diff --git a/comp/forwarder/defaultforwarder/go.mod b/comp/forwarder/defaultforwarder/go.mod index 929726d1bae4a..10762c430671c 100644 --- a/comp/forwarder/defaultforwarder/go.mod +++ b/comp/forwarder/defaultforwarder/go.mod @@ -8,7 +8,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/config => ../../core/config github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../core/flare/types - github.com/DataDog/datadog-agent/comp/core/log => ../../core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../core/secrets github.com/DataDog/datadog-agent/comp/core/status => ../../core/status github.com/DataDog/datadog-agent/comp/core/telemetry => ../../core/telemetry @@ -48,7 +49,8 @@ replace ( require ( github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.3 - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/core/log/mock v0.0.0-00010101000000-000000000000 github.com/DataDog/datadog-agent/comp/core/status v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/setup v0.56.0-rc.3 @@ -79,7 +81,7 @@ require ( github.com/DataDog/datadog-agent/comp/def v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/collector/check/defaults v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/config/env v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/pkg/config/logs v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/config/logs v0.0.0-00010101000000-000000000000 // indirect github.com/DataDog/datadog-agent/pkg/util/executable v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/util/hostname/validate v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 // indirect diff --git a/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer.go b/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer.go index 9b78cc59f6de5..e38d5e4853df0 100644 --- a/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer.go +++ b/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" "github.com/DataDog/datadog-agent/pkg/util/common" diff --git a/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer_test.go b/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer_test.go index 544025e33b5aa..ef05027bdaafb 100644 --- a/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer_test.go +++ b/comp/forwarder/defaultforwarder/internal/retry/http_transactions_serializer_test.go @@ -14,11 +14,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) const apiKey1 = "apiKey1" @@ -39,7 +37,7 @@ func TestHTTPSerializeDeserializeWithResolverOverride(t *testing.T) { func runTestHTTPSerializeDeserializeWithResolver(t *testing.T, d string, r resolver.DomainResolver) { a := assert.New(t) tr := createHTTPTransactionTests(d) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) serializer := NewHTTPTransactionsSerializer(log, r) a.NoError(serializer.Add(tr)) @@ -65,7 +63,7 @@ func runTestHTTPSerializeDeserializeWithResolver(t *testing.T, d string, r resol func TestPartialDeserialize(t *testing.T) { a := assert.New(t) initialTransaction := createHTTPTransactionTests(domain) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) serializer := NewHTTPTransactionsSerializer(log, resolver.NewSingleDomainResolver(domain, nil)) a.NoError(serializer.Add(initialTransaction)) @@ -87,7 +85,7 @@ func TestPartialDeserialize(t *testing.T) { func TestHTTPTransactionSerializerMissingAPIKey(t *testing.T) { r := require.New(t) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) serializer := NewHTTPTransactionsSerializer(log, resolver.NewSingleDomainResolver(domain, []string{apiKey1, apiKey2})) r.NoError(serializer.Add(createHTTPTransactionWithHeaderTests(http.Header{"Key": []string{apiKey1}}, domain))) diff --git a/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue.go b/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue.go index 78e6978225e38..04c2eb4ee610a 100644 --- a/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue.go +++ b/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue.go @@ -13,7 +13,7 @@ import ( "sort" "time" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" "github.com/DataDog/datadog-agent/pkg/util/filesystem" ) diff --git a/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue_test.go b/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue_test.go index ca612ff66ea67..4509282d6e49b 100644 --- a/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue_test.go +++ b/comp/forwarder/defaultforwarder/internal/retry/on_disk_retry_queue_test.go @@ -13,12 +13,10 @@ import ( "github.com/stretchr/testify/assert" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" "github.com/DataDog/datadog-agent/pkg/util/filesystem" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) const domainName = "domain" @@ -135,7 +133,7 @@ func newTestOnDiskRetryQueue(t *testing.T, a *assert.Assertions, path string, ma Total: 10000, }} diskUsageLimit := NewDiskUsageLimit("", disk, maxSizeInBytes, 1) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) storage, err := newOnDiskRetryQueue(log, NewHTTPTransactionsSerializer(log, resolver.NewSingleDomainResolver(domainName, nil)), path, diskUsageLimit, telemetry, NewPointCountTelemetryMock()) a.NoError(err) return storage diff --git a/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue.go b/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue.go index afdd7a476e1d0..56a0369e6296e 100644 --- a/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue.go +++ b/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/go-multierror" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" ) diff --git a/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue_test.go b/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue_test.go index 4a07cea304654..4021af8487e60 100644 --- a/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue_test.go +++ b/comp/forwarder/defaultforwarder/internal/retry/transaction_retry_queue_test.go @@ -12,12 +12,10 @@ import ( "github.com/stretchr/testify/assert" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" "github.com/DataDog/datadog-agent/pkg/util/filesystem" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) // only used for testing @@ -181,7 +179,7 @@ func newOnDiskRetryQueueTest(t *testing.T, a *assert.Assertions) *onDiskRetryQue Total: 10000, }} diskUsageLimit := NewDiskUsageLimit("", disk, 1000, 1) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) q, err := newOnDiskRetryQueue( log, NewHTTPTransactionsSerializer(log, resolver.NewSingleDomainResolver("", nil)), diff --git a/comp/forwarder/defaultforwarder/params.go b/comp/forwarder/defaultforwarder/params.go index bb27caa760478..754ae29962a98 100644 --- a/comp/forwarder/defaultforwarder/params.go +++ b/comp/forwarder/defaultforwarder/params.go @@ -7,7 +7,7 @@ package defaultforwarder import ( "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/pkg/config/utils" ) diff --git a/comp/forwarder/defaultforwarder/sync_forwarder.go b/comp/forwarder/defaultforwarder/sync_forwarder.go index 64ea25d0efa12..2c894c36580b8 100644 --- a/comp/forwarder/defaultforwarder/sync_forwarder.go +++ b/comp/forwarder/defaultforwarder/sync_forwarder.go @@ -11,7 +11,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/endpoints" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" utilhttp "github.com/DataDog/datadog-agent/pkg/util/http" diff --git a/comp/forwarder/defaultforwarder/telemetry.go b/comp/forwarder/defaultforwarder/telemetry.go index d12460a9cbee4..0a2844c143904 100644 --- a/comp/forwarder/defaultforwarder/telemetry.go +++ b/comp/forwarder/defaultforwarder/telemetry.go @@ -8,7 +8,7 @@ package defaultforwarder import ( "expvar" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/endpoints" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" pkgorchestratormodel "github.com/DataDog/datadog-agent/pkg/orchestrator/model" diff --git a/comp/forwarder/defaultforwarder/test_common.go b/comp/forwarder/defaultforwarder/test_common.go index 19cb39618d216..8c17b76712d60 100644 --- a/comp/forwarder/defaultforwarder/test_common.go +++ b/comp/forwarder/defaultforwarder/test_common.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" ) diff --git a/comp/forwarder/defaultforwarder/transaction/transaction.go b/comp/forwarder/defaultforwarder/transaction/transaction.go index 97b857edca44d..2d7f90e3cbcbc 100644 --- a/comp/forwarder/defaultforwarder/transaction/transaction.go +++ b/comp/forwarder/defaultforwarder/transaction/transaction.go @@ -20,7 +20,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/telemetry" "github.com/DataDog/datadog-agent/pkg/util/scrubber" ) diff --git a/comp/forwarder/defaultforwarder/transaction/transaction_test.go b/comp/forwarder/defaultforwarder/transaction/transaction_test.go index b9cf5166bc1eb..b25860c93feee 100644 --- a/comp/forwarder/defaultforwarder/transaction/transaction_test.go +++ b/comp/forwarder/defaultforwarder/transaction/transaction_test.go @@ -14,10 +14,8 @@ import ( "testing" "time" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/stretchr/testify/assert" ) @@ -54,7 +52,7 @@ func TestProcess(t *testing.T) { client := &http.Client{} mockConfig := pkgconfigmodel.NewConfig("test", "DD", strings.NewReplacer(".", "_")) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) err := transaction.Process(context.Background(), mockConfig, log, client) assert.NoError(t, err) } @@ -69,7 +67,7 @@ func TestProcessInvalidDomain(t *testing.T) { client := &http.Client{} mockConfig := pkgconfigmodel.NewConfig("test", "DD", strings.NewReplacer(".", "_")) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) err := transaction.Process(context.Background(), mockConfig, log, client) assert.NoError(t, err) } @@ -84,7 +82,7 @@ func TestProcessNetworkError(t *testing.T) { client := &http.Client{} mockConfig := pkgconfigmodel.NewConfig("test", "DD", strings.NewReplacer(".", "_")) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) err := transaction.Process(context.Background(), mockConfig, log, client) assert.NotNil(t, err) } @@ -106,7 +104,7 @@ func TestProcessHTTPError(t *testing.T) { client := &http.Client{} mockConfig := pkgconfigmodel.NewConfig("test", "DD", strings.NewReplacer(".", "_")) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) err := transaction.Process(context.Background(), mockConfig, log, client) assert.NotNil(t, err) assert.Contains(t, err.Error(), "error \"503 Service Unavailable\" while sending transaction") @@ -138,7 +136,7 @@ func TestProcessCancel(t *testing.T) { cancel() mockConfig := pkgconfigmodel.NewConfig("test", "DD", strings.NewReplacer(".", "_")) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) err := transaction.Process(ctx, mockConfig, log, client) assert.NoError(t, err) } diff --git a/comp/forwarder/defaultforwarder/worker.go b/comp/forwarder/defaultforwarder/worker.go index a0d106b3b45ea..bf839d49093de 100644 --- a/comp/forwarder/defaultforwarder/worker.go +++ b/comp/forwarder/defaultforwarder/worker.go @@ -13,7 +13,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" httputils "github.com/DataDog/datadog-agent/pkg/util/http" ) diff --git a/comp/forwarder/defaultforwarder/worker_test.go b/comp/forwarder/defaultforwarder/worker_test.go index 715f0e60c0aa5..77052fffdda74 100644 --- a/comp/forwarder/defaultforwarder/worker_test.go +++ b/comp/forwarder/defaultforwarder/worker_test.go @@ -16,12 +16,10 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/atomic" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/transaction" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) func TestNewWorker(t *testing.T) { @@ -30,7 +28,7 @@ func TestNewWorker(t *testing.T) { requeue := make(chan transaction.Transaction) mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) w := NewWorker(mockConfig, log, highPrio, lowPrio, requeue, newBlockedEndpoints(mockConfig, log), &PointSuccessfullySentMock{}) assert.NotNil(t, w) assert.Equal(t, w.Client.Timeout, mockConfig.GetDuration("forwarder_timeout")*time.Second) @@ -43,7 +41,7 @@ func TestNewNoSSLWorker(t *testing.T) { mockConfig := pkgconfigsetup.Conf() mockConfig.SetWithoutSource("skip_ssl_validation", true) - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) w := NewWorker(mockConfig, log, highPrio, lowPrio, requeue, newBlockedEndpoints(mockConfig, log), &PointSuccessfullySentMock{}) assert.True(t, w.Client.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify) } @@ -54,7 +52,7 @@ func TestWorkerStart(t *testing.T) { requeue := make(chan transaction.Transaction, 1) sender := &PointSuccessfullySentMock{} mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) w := NewWorker(mockConfig, log, highPrio, lowPrio, requeue, newBlockedEndpoints(mockConfig, log), sender) mock := newTestTransaction() @@ -91,7 +89,7 @@ func TestWorkerRetry(t *testing.T) { lowPrio := make(chan transaction.Transaction) requeue := make(chan transaction.Transaction, 1) mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) w := NewWorker(mockConfig, log, highPrio, lowPrio, requeue, newBlockedEndpoints(mockConfig, log), &PointSuccessfullySentMock{}) mock := newTestTransaction() @@ -114,7 +112,7 @@ func TestWorkerRetryBlockedTransaction(t *testing.T) { lowPrio := make(chan transaction.Transaction) requeue := make(chan transaction.Transaction, 1) mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) w := NewWorker(mockConfig, log, highPrio, lowPrio, requeue, newBlockedEndpoints(mockConfig, log), &PointSuccessfullySentMock{}) mock := newTestTransaction() @@ -137,7 +135,7 @@ func TestWorkerResetConnections(t *testing.T) { lowPrio := make(chan transaction.Transaction) requeue := make(chan transaction.Transaction, 1) mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) w := NewWorker(mockConfig, log, highPrio, lowPrio, requeue, newBlockedEndpoints(mockConfig, log), &PointSuccessfullySentMock{}) mock := newTestTransaction() @@ -182,7 +180,7 @@ func TestWorkerPurgeOnStop(t *testing.T) { lowPrio := make(chan transaction.Transaction, 1) requeue := make(chan transaction.Transaction, 1) mockConfig := pkgconfigsetup.Conf() - log := fxutil.Test[log.Component](t, logimpl.MockModule()) + log := logmock.New(t) w := NewWorker(mockConfig, log, highPrio, lowPrio, requeue, newBlockedEndpoints(mockConfig, log), &PointSuccessfullySentMock{}) // making stopChan non blocking on insert and closing stopped channel // to avoid blocking in the Stop method since we don't actually start diff --git a/comp/forwarder/orchestrator/orchestratorimpl/forwarder_no_orchestrator.go b/comp/forwarder/orchestrator/orchestratorimpl/forwarder_no_orchestrator.go index 2ba0eac66dde5..151f85d2a7061 100644 --- a/comp/forwarder/orchestrator/orchestratorimpl/forwarder_no_orchestrator.go +++ b/comp/forwarder/orchestrator/orchestratorimpl/forwarder_no_orchestrator.go @@ -12,7 +12,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/comp/forwarder/orchestrator/orchestratorimpl/forwarder_orchestrator.go b/comp/forwarder/orchestrator/orchestratorimpl/forwarder_orchestrator.go index 87fd09041e110..ba079b7bb4c2b 100644 --- a/comp/forwarder/orchestrator/orchestratorimpl/forwarder_orchestrator.go +++ b/comp/forwarder/orchestrator/orchestratorimpl/forwarder_orchestrator.go @@ -14,7 +14,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" diff --git a/comp/forwarder/orchestrator/orchestratorinterface/go.mod b/comp/forwarder/orchestrator/orchestratorinterface/go.mod index 7ae26b70ee253..ba9fefd86e928 100644 --- a/comp/forwarder/orchestrator/orchestratorinterface/go.mod +++ b/comp/forwarder/orchestrator/orchestratorinterface/go.mod @@ -8,7 +8,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/config => ../../../core/config github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../core/flare/types - github.com/DataDog/datadog-agent/comp/core/log => ../../../core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../../core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../../core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../../core/secrets github.com/DataDog/datadog-agent/comp/core/status => ../../../core/status github.com/DataDog/datadog-agent/comp/core/telemetry => ../../../core/telemetry @@ -63,7 +64,7 @@ require ( github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/flare/builder v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 // indirect github.com/DataDog/datadog-agent/comp/core/secrets v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/status v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/telemetry v0.56.0-rc.3 // indirect diff --git a/comp/languagedetection/bundle_test.go b/comp/languagedetection/bundle_test.go index f2f7fea7652cf..bb1598219789b 100644 --- a/comp/languagedetection/bundle_test.go +++ b/comp/languagedetection/bundle_test.go @@ -12,7 +12,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" "github.com/DataDog/datadog-agent/comp/core/telemetry/telemetryimpl" @@ -29,10 +30,9 @@ func TestBundleDependencies(t *testing.T) { config.Module(), fx.Supply(config.Params{}), telemetryimpl.Module(), - logimpl.Module(), fxutil.ProvideOptional[secrets.Component](), + fx.Provide(func() log.Component { return logmock.New(t) }), secretsimpl.MockModule(), - fx.Supply(logimpl.Params{}), workloadmetafx.Module(), fx.Supply(workloadmeta.NewParams()), fx.Invoke(func(client.Component) {}), diff --git a/comp/languagedetection/client/clientimpl/client.go b/comp/languagedetection/client/clientimpl/client.go index 5d8c50e3f8fe7..becde06ae5206 100644 --- a/comp/languagedetection/client/clientimpl/client.go +++ b/comp/languagedetection/client/clientimpl/client.go @@ -12,7 +12,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/telemetry" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" clientComp "github.com/DataDog/datadog-agent/comp/languagedetection/client" @@ -21,7 +21,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/status/health" "github.com/DataDog/datadog-agent/pkg/util/clusteragent" "github.com/DataDog/datadog-agent/pkg/util/fxutil" - "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/optional" "go.uber.org/fx" @@ -50,7 +49,7 @@ type dependencies struct { Lc fx.Lifecycle Config config.Component - Log logComponent.Component + Log log.Component Telemetry telemetry.Component Workloadmeta workloadmeta.Component @@ -67,7 +66,7 @@ type languageDetectionClient interface { type client struct { ctx context.Context cancel context.CancelFunc - logger logComponent.Component + logger log.Component store workloadmeta.Component // mutex protecting UpdatedPodDetails and currentBatch @@ -226,7 +225,7 @@ func (c *client) startStreaming() { cancel() err := health.Deregister() if err != nil { - log.Warnf("error de-registering health check: %s", err) + c.logger.Warnf("error de-registering health check: %s", err) } return case healthDeadline := <-health.C: diff --git a/comp/languagedetection/client/clientimpl/client_test.go b/comp/languagedetection/client/clientimpl/client_test.go index 51ca2fddcd46f..19e5a3f24c2d5 100644 --- a/comp/languagedetection/client/clientimpl/client_test.go +++ b/comp/languagedetection/client/clientimpl/client_test.go @@ -19,7 +19,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" "github.com/DataDog/datadog-agent/comp/core/telemetry/telemetryimpl" @@ -56,7 +57,7 @@ func newTestClient(t *testing.T) (*client, chan *pbgo.ParentLanguageAnnotationRe "language_detection.reporting.buffer_period": "50ms", }}), telemetryimpl.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), )) @@ -103,7 +104,7 @@ func TestClientEnabled(t *testing.T) { }}), secretsimpl.MockModule(), telemetryimpl.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), )) diff --git a/comp/logs/agent/agentimpl/agent.go b/comp/logs/agent/agentimpl/agent.go index 6dad37de3315d..e73c267327145 100644 --- a/comp/logs/agent/agentimpl/agent.go +++ b/comp/logs/agent/agentimpl/agent.go @@ -19,7 +19,7 @@ import ( configComponent "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" "github.com/DataDog/datadog-agent/comp/core/hostname" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" statusComponent "github.com/DataDog/datadog-agent/comp/core/status" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/comp/logs/agent" @@ -45,7 +45,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/status/health" "github.com/DataDog/datadog-agent/pkg/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" - "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/optional" "github.com/DataDog/datadog-agent/pkg/util/startstop" ) @@ -73,7 +72,7 @@ type dependencies struct { fx.In Lc fx.Lifecycle - Log logComponent.Component + Log log.Component Config configComponent.Component InventoryAgent inventoryagent.Component Hostname hostname.Component @@ -95,7 +94,7 @@ type provides struct { // processes and sends logs to the backend. See the package README for // a description of its operation. type logAgent struct { - log logComponent.Component + log log.Component config pkgConfig.Reader inventoryAgent inventoryagent.Component hostname hostname.Component @@ -325,7 +324,7 @@ func (a *logAgent) onUpdateSDSRules(updates map[string]state.RawConfig, applySta } if err != nil { - log.Errorf("Can't update SDS standard rules: %v", err) + a.log.Errorf("Can't update SDS standard rules: %v", err) } // Apply the new status to all configs @@ -360,7 +359,7 @@ func (a *logAgent) onUpdateSDSAgentConfig(updates map[string]state.RawConfig, ap } if err != nil { - log.Errorf("Can't update SDS configurations: %v", err) + a.log.Errorf("Can't update SDS configurations: %v", err) } // Apply the new status to all configs diff --git a/comp/logs/agent/agentimpl/agent_test.go b/comp/logs/agent/agentimpl/agent_test.go index 97e2854838c25..141f323bb9673 100644 --- a/comp/logs/agent/agentimpl/agent_test.go +++ b/comp/logs/agent/agentimpl/agent_test.go @@ -24,8 +24,8 @@ import ( configComponent "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" "github.com/DataDog/datadog-agent/comp/logs/agent/config" @@ -110,8 +110,8 @@ func createAgent(suite *AgentTestSuite, endpoints *config.Endpoints) (*logAgent, deps := fxutil.Test[testDeps](suite.T(), fx.Options( fx.Supply(configComponent.Params{}), - fx.Supply(logimpl.Params{}), - logimpl.MockModule(), + fx.Supply(log.Params{}), + fx.Provide(func() log.Component { return logmock.New(suite.T()) }), configComponent.MockModule(), hostnameimpl.MockModule(), fx.Replace(configComponent.MockParams{Overrides: suite.configOverrides}), @@ -387,8 +387,8 @@ func (suite *AgentTestSuite) TestFlareProvider() { func (suite *AgentTestSuite) createDeps() dependencies { return fxutil.Test[dependencies](suite.T(), fx.Options( fx.Supply(configComponent.Params{}), - fx.Supply(logimpl.Params{}), - logimpl.MockModule(), + fx.Supply(log.Params{}), + fx.Provide(func() log.Component { return logmock.New(suite.T()) }), configComponent.MockModule(), hostnameimpl.MockModule(), fx.Replace(configComponent.MockParams{Overrides: suite.configOverrides}), diff --git a/comp/logs/agent/agentimpl/serverless.go b/comp/logs/agent/agentimpl/serverless.go index 1f86b5764ad74..82afcbc110d98 100644 --- a/comp/logs/agent/agentimpl/serverless.go +++ b/comp/logs/agent/agentimpl/serverless.go @@ -9,7 +9,7 @@ import ( "context" flareController "github.com/DataDog/datadog-agent/comp/logs/agent/flare" - logComponent "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logComponent "github.com/DataDog/datadog-agent/comp/core/log/impl" "github.com/DataDog/datadog-agent/comp/logs/agent" pkgConfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/logs/service" diff --git a/comp/metadata/host/hostimpl/host.go b/comp/metadata/host/hostimpl/host.go index c328a9b0a4010..3404b98724ff8 100644 --- a/comp/metadata/host/hostimpl/host.go +++ b/comp/metadata/host/hostimpl/host.go @@ -18,7 +18,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" hostComp "github.com/DataDog/datadog-agent/comp/metadata/host" "github.com/DataDog/datadog-agent/comp/metadata/resources" diff --git a/comp/metadata/host/hostimpl/host_test.go b/comp/metadata/host/hostimpl/host_test.go index b421a900c489b..3464dba0843de 100644 --- a/comp/metadata/host/hostimpl/host_test.go +++ b/comp/metadata/host/hostimpl/host_test.go @@ -17,7 +17,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" flarehelpers "github.com/DataDog/datadog-agent/comp/core/flare/helpers" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/metadata/resources" "github.com/DataDog/datadog-agent/comp/metadata/resources/resourcesimpl" configUtils "github.com/DataDog/datadog-agent/pkg/config/utils" @@ -29,7 +30,7 @@ func TestNewHostProviderDefaultInterval(t *testing.T) { ret := newHostProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), resourcesimpl.MockModule(), fx.Replace(resources.MockParams{Data: nil}), @@ -53,7 +54,7 @@ func TestNewHostProviderCustomInterval(t *testing.T) { ret := newHostProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), resourcesimpl.MockModule(), fx.Replace(resources.MockParams{Data: nil}), @@ -78,7 +79,7 @@ func TestNewHostProviderInvalidCustomInterval(t *testing.T) { ret := newHostProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), resourcesimpl.MockModule(), fx.Replace(resources.MockParams{Data: nil}), @@ -94,7 +95,7 @@ func TestFlareProvider(t *testing.T) { ret := newHostProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), resourcesimpl.MockModule(), fx.Replace(resources.MockParams{Data: nil}), @@ -113,7 +114,7 @@ func TestStatusHeaderProvider(t *testing.T) { ret := newHostProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), resourcesimpl.MockModule(), fx.Replace(resources.MockParams{Data: nil}), diff --git a/comp/metadata/internal/util/inventory_payload.go b/comp/metadata/internal/util/inventory_payload.go index 5b5441be68bc2..0104aa6d704cd 100644 --- a/comp/metadata/internal/util/inventory_payload.go +++ b/comp/metadata/internal/util/inventory_payload.go @@ -63,7 +63,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/metadata/runner/runnerimpl" "github.com/DataDog/datadog-agent/pkg/serializer" "github.com/DataDog/datadog-agent/pkg/serializer/marshaler" diff --git a/comp/metadata/internal/util/inventory_payload_test.go b/comp/metadata/internal/util/inventory_payload_test.go index 6bfd581081565..8e10783cad8bd 100644 --- a/comp/metadata/internal/util/inventory_payload_test.go +++ b/comp/metadata/internal/util/inventory_payload_test.go @@ -18,8 +18,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare/helpers" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/pkg/serializer/marshaler" serializermock "github.com/DataDog/datadog-agent/pkg/serializer/mocks" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -39,7 +38,7 @@ func (p *testPayload) SplitPayload(_ int) ([]marshaler.AbstractMarshaler, error) func getTestInventoryPayload(t *testing.T, confOverrides map[string]any) *InventoryPayload { i := CreateInventoryPayload( fxutil.Test[config.Component](t, config.MockModule(), fx.Replace(config.MockParams{Overrides: confOverrides})), - fxutil.Test[log.Component](t, logimpl.MockModule()), + logmock.New(t), serializermock.NewMetricSerializer(t), func() marshaler.JSONMarshaler { return &testPayload{} }, "test.json", diff --git a/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent.go b/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent.go index 4b85a5c0069f6..f8505ccd27923 100644 --- a/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent.go +++ b/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent.go @@ -24,7 +24,7 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/metadata/internal/util" diff --git a/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent_test.go b/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent_test.go index 8d696de90fc05..ddcb8eaac4814 100644 --- a/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent_test.go +++ b/comp/metadata/inventoryagent/inventoryagentimpl/inventoryagent_test.go @@ -20,7 +20,8 @@ import ( authtokenimpl "github.com/DataDog/datadog-agent/comp/api/authtoken/fetchonlyimpl" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -40,7 +41,7 @@ func getProvides(t *testing.T, confOverrides map[string]any, sysprobeConfOverrid return newInventoryAgentProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Replace(config.MockParams{Overrides: confOverrides}), sysprobeconfigimpl.MockModule(), @@ -519,7 +520,7 @@ func TestFetchSystemProbeAgent(t *testing.T) { p := newInventoryAgentProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), sysprobeconfig.NoneModule(), fx.Provide(func() serializer.MetricSerializer { return serializermock.NewMetricSerializer(t) }), diff --git a/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks.go b/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks.go index 51a868910c6e3..0172d85a72fd2 100644 --- a/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks.go +++ b/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks.go @@ -9,6 +9,7 @@ package inventorychecksimpl import ( "context" "encoding/json" + "expvar" "fmt" "net/http" "reflect" @@ -21,7 +22,7 @@ import ( "github.com/DataDog/datadog-agent/comp/collector/collector" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" logagent "github.com/DataDog/datadog-agent/comp/logs/agent" "github.com/DataDog/datadog-agent/comp/metadata/internal/util" "github.com/DataDog/datadog-agent/comp/metadata/inventorychecks" @@ -133,6 +134,14 @@ func newInventoryChecksProvider(deps dependencies) provides { ic.sources.Set(logAgent.GetSources()) } + // Set the expvar callback to the current inventorycheck + // This should be removed when migrated to collector component + if icExpvar := expvar.Get("inventories"); icExpvar == nil { + expvar.Publish("inventories", expvar.Func(func() interface{} { + return ic.getPayload() + })) + } + return provides{ Comp: ic, Provider: ic.MetadataProvider(), diff --git a/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks_test.go b/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks_test.go index 838ec138268ff..a10cbd7ff4e39 100644 --- a/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks_test.go +++ b/comp/metadata/inventorychecks/inventorychecksimpl/inventorychecks_test.go @@ -6,6 +6,7 @@ package inventorychecksimpl import ( + "expvar" "fmt" "testing" @@ -16,7 +17,8 @@ import ( "github.com/DataDog/datadog-agent/comp/collector/collector/collectorimpl" "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" logsBundle "github.com/DataDog/datadog-agent/comp/logs" @@ -36,7 +38,7 @@ func getTestInventoryChecks(t *testing.T, coll optional.Option[collector.Compone p := newInventoryChecksProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Replace(config.MockParams{Overrides: overrides}), fx.Provide(func() serializer.MetricSerializer { return serializermock.NewMetricSerializer(t) }), @@ -249,3 +251,11 @@ func TestFlareProviderFilename(t *testing.T) { ) assert.Equal(t, "checks.json", ic.FlareFileName) } + +// TODO (Component): This test will be removed when the inventorychecks component will be move into the collector component +func TestExpvarExist(t *testing.T) { + getTestInventoryChecks( + t, optional.NewNoneOption[collector.Component](), optional.Option[logagent.Component]{}, nil, + ) + assert.NotNil(t, expvar.Get("inventories")) +} diff --git a/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost.go b/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost.go index e92f1124848ac..6bf753c32d281 100644 --- a/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost.go +++ b/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost.go @@ -18,7 +18,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/metadata/host/hostimpl/utils" "github.com/DataDog/datadog-agent/comp/metadata/internal/util" "github.com/DataDog/datadog-agent/comp/metadata/inventoryhost" diff --git a/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost_test.go b/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost_test.go index 193b1b7942f5f..3aff19ed5a9e1 100644 --- a/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost_test.go +++ b/comp/metadata/inventoryhost/inventoryhostimpl/inventoryhost_test.go @@ -13,8 +13,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/metadata/host/hostimpl/utils" pkgUtils "github.com/DataDog/datadog-agent/comp/metadata/packagesigning/utils" "github.com/DataDog/datadog-agent/pkg/gohai/cpu" @@ -121,7 +121,7 @@ func getTestInventoryHost(t *testing.T) *invHost { p := newInventoryHostProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Provide(func() serializer.MetricSerializer { return serializermock.NewMetricSerializer(t) }), ), diff --git a/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel.go b/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel.go index 5d20864fcb699..1612697ca8c26 100644 --- a/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel.go +++ b/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel.go @@ -24,7 +24,7 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/metadata/internal/util" iointerface "github.com/DataDog/datadog-agent/comp/metadata/inventoryotel" diff --git a/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel_test.go b/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel_test.go index bf760d4e1a1f1..4617b590bc214 100644 --- a/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel_test.go +++ b/comp/metadata/inventoryotel/inventoryotelimpl/inventoryotel_test.go @@ -18,7 +18,8 @@ import ( authtokenimpl "github.com/DataDog/datadog-agent/comp/api/authtoken/fetchonlyimpl" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model" "github.com/DataDog/datadog-agent/pkg/serializer" @@ -30,7 +31,7 @@ func getProvides(t *testing.T, confOverrides map[string]any) (provides, error) { return newInventoryOtelProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Replace(config.MockParams{Overrides: confOverrides}), fx.Provide(func() serializer.MetricSerializer { return serializermock.NewMetricSerializer(t) }), diff --git a/comp/metadata/packagesigning/packagesigningimpl/aptsigning.go b/comp/metadata/packagesigning/packagesigningimpl/aptsigning.go index e039f2ef4f47b..126e97e0a31b7 100644 --- a/comp/metadata/packagesigning/packagesigningimpl/aptsigning.go +++ b/comp/metadata/packagesigning/packagesigningimpl/aptsigning.go @@ -14,7 +14,7 @@ import ( "regexp" "strings" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" pkgUtils "github.com/DataDog/datadog-agent/comp/metadata/packagesigning/utils" ) diff --git a/comp/metadata/packagesigning/packagesigningimpl/packagesigning.go b/comp/metadata/packagesigning/packagesigningimpl/packagesigning.go index e6b612493cb7e..2156c02a1c812 100644 --- a/comp/metadata/packagesigning/packagesigningimpl/packagesigning.go +++ b/comp/metadata/packagesigning/packagesigningimpl/packagesigning.go @@ -20,7 +20,7 @@ import ( api "github.com/DataDog/datadog-agent/comp/api/api/def" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/metadata/internal/util" "github.com/DataDog/datadog-agent/comp/metadata/packagesigning" pkgUtils "github.com/DataDog/datadog-agent/comp/metadata/packagesigning/utils" diff --git a/comp/metadata/packagesigning/packagesigningimpl/packagesigning_test.go b/comp/metadata/packagesigning/packagesigningimpl/packagesigning_test.go index 86e0a94acf225..d3c2661ddba24 100644 --- a/comp/metadata/packagesigning/packagesigningimpl/packagesigning_test.go +++ b/comp/metadata/packagesigning/packagesigningimpl/packagesigning_test.go @@ -15,8 +15,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" pkgUtils "github.com/DataDog/datadog-agent/comp/metadata/packagesigning/utils" "github.com/DataDog/datadog-agent/pkg/serializer" serializermock "github.com/DataDog/datadog-agent/pkg/serializer/mocks" @@ -90,7 +90,7 @@ func getTestPackageSigning(t *testing.T) *pkgSigning { p := newPackageSigningProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Provide(func() serializer.MetricSerializer { return serializermock.NewMetricSerializer(t) }), ), diff --git a/comp/metadata/packagesigning/packagesigningimpl/rpmsigning.go b/comp/metadata/packagesigning/packagesigningimpl/rpmsigning.go index 705557a354a6a..1e7baf21f700e 100644 --- a/comp/metadata/packagesigning/packagesigningimpl/rpmsigning.go +++ b/comp/metadata/packagesigning/packagesigningimpl/rpmsigning.go @@ -16,7 +16,7 @@ import ( "strings" "time" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" pkgUtils "github.com/DataDog/datadog-agent/comp/metadata/packagesigning/utils" ) diff --git a/comp/metadata/packagesigning/utils/linux.go b/comp/metadata/packagesigning/utils/linux.go index bbf2ae979fe89..c471c7a095638 100644 --- a/comp/metadata/packagesigning/utils/linux.go +++ b/comp/metadata/packagesigning/utils/linux.go @@ -10,7 +10,7 @@ import ( "os" "runtime" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ) // GetLinuxGlobalSigningPolicies returns: diff --git a/comp/metadata/resources/resourcesimpl/resources.go b/comp/metadata/resources/resourcesimpl/resources.go index 702a92e246947..7ed04a41842ed 100644 --- a/comp/metadata/resources/resourcesimpl/resources.go +++ b/comp/metadata/resources/resourcesimpl/resources.go @@ -13,7 +13,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/metadata/resources" "github.com/DataDog/datadog-agent/comp/metadata/runner/runnerimpl" configUtils "github.com/DataDog/datadog-agent/pkg/config/utils" diff --git a/comp/metadata/resources/resourcesimpl/resources_non_supported.go b/comp/metadata/resources/resourcesimpl/resources_non_supported.go index a945fc70b7a87..547eb267607aa 100644 --- a/comp/metadata/resources/resourcesimpl/resources_non_supported.go +++ b/comp/metadata/resources/resourcesimpl/resources_non_supported.go @@ -9,7 +9,7 @@ package resourcesimpl import ( "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/metadata/resources" "go.uber.org/fx" ) diff --git a/comp/metadata/resources/resourcesimpl/resources_test.go b/comp/metadata/resources/resourcesimpl/resources_test.go index 99096f929acb6..d26cb390ae4bb 100644 --- a/comp/metadata/resources/resourcesimpl/resources_test.go +++ b/comp/metadata/resources/resourcesimpl/resources_test.go @@ -21,7 +21,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" configUtils "github.com/DataDog/datadog-agent/pkg/config/utils" "github.com/DataDog/datadog-agent/pkg/serializer" serializermock "github.com/DataDog/datadog-agent/pkg/serializer/mocks" @@ -41,7 +42,7 @@ func TestConfDisabled(t *testing.T) { ret := newResourcesProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Replace(config.MockParams{Overrides: overrides}), fx.Provide(func() serializer.MetricSerializer { return nil }), @@ -65,7 +66,7 @@ func TestConfInterval(t *testing.T) { ret := newResourcesProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Replace(config.MockParams{Overrides: overrides}), fx.Provide(func() serializer.MetricSerializer { return nil }), @@ -98,7 +99,7 @@ func TestCollect(t *testing.T) { ret := newResourcesProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Provide(func() serializer.MetricSerializer { return s }), ), @@ -122,7 +123,7 @@ func TestCollectError(t *testing.T) { ret := newResourcesProvider( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Provide(func() serializer.MetricSerializer { return s }), ), diff --git a/comp/metadata/runner/runnerimpl/runner.go b/comp/metadata/runner/runnerimpl/runner.go index 041ac23ef6b62..9de9805d513dc 100644 --- a/comp/metadata/runner/runnerimpl/runner.go +++ b/comp/metadata/runner/runnerimpl/runner.go @@ -11,7 +11,7 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/metadata/runner" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "go.uber.org/fx" diff --git a/comp/metadata/runner/runnerimpl/runner_test.go b/comp/metadata/runner/runnerimpl/runner_test.go index 4a4e536be7c45..d3f4efcff2802 100644 --- a/comp/metadata/runner/runnerimpl/runner_test.go +++ b/comp/metadata/runner/runnerimpl/runner_test.go @@ -13,7 +13,8 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/metadata/runner" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/stretchr/testify/assert" @@ -34,7 +35,7 @@ func TestHandleProvider(t *testing.T) { r := createRunner( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(NewProvider(provider)), )) @@ -59,7 +60,7 @@ func TestRunnerCreation(t *testing.T) { fxutil.Test[runner.Component]( t, fx.Supply(lc), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), Module(), // Supplying our provider by using the helper function diff --git a/comp/metadata/securityagent/impl/security_agent.go b/comp/metadata/securityagent/impl/security_agent.go index d95fcc714b13d..b49a029830324 100644 --- a/comp/metadata/securityagent/impl/security_agent.go +++ b/comp/metadata/securityagent/impl/security_agent.go @@ -19,7 +19,7 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/metadata/internal/util" "github.com/DataDog/datadog-agent/comp/metadata/runner/runnerimpl" "github.com/DataDog/datadog-agent/comp/metadata/securityagent/def" diff --git a/comp/metadata/securityagent/impl/security_agent_test.go b/comp/metadata/securityagent/impl/security_agent_test.go index 496d638404d11..c20eb56bc2830 100644 --- a/comp/metadata/securityagent/impl/security_agent_test.go +++ b/comp/metadata/securityagent/impl/security_agent_test.go @@ -20,8 +20,8 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" authtokenimpl "github.com/DataDog/datadog-agent/comp/api/authtoken/fetchonlyimpl" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher" "github.com/DataDog/datadog-agent/pkg/config/model" serializermock "github.com/DataDog/datadog-agent/pkg/serializer/mocks" @@ -51,7 +51,7 @@ func setupFetcher(t *testing.T) { } func getSecurityAgentComp(t *testing.T, enableConfig bool) *securityagent { - l := fxutil.Test[log.Component](t, logimpl.MockModule()) + l := logmock.New(t) cfg := fxutil.Test[config.Component](t, config.MockModule()) cfg.Set("inventories_configuration_enabled", enableConfig, model.SourceUnknown) diff --git a/comp/metadata/systemprobe/impl/system_probe.go b/comp/metadata/systemprobe/impl/system_probe.go index 851a32d3b237c..0fc1ad0cc4f60 100644 --- a/comp/metadata/systemprobe/impl/system_probe.go +++ b/comp/metadata/systemprobe/impl/system_probe.go @@ -19,7 +19,7 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/metadata/internal/util" "github.com/DataDog/datadog-agent/comp/metadata/runner/runnerimpl" diff --git a/comp/metadata/systemprobe/impl/system_probe_test.go b/comp/metadata/systemprobe/impl/system_probe_test.go index 21681615e86ce..5b4f98f424801 100644 --- a/comp/metadata/systemprobe/impl/system_probe_test.go +++ b/comp/metadata/systemprobe/impl/system_probe_test.go @@ -20,8 +20,8 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken" authtokenimpl "github.com/DataDog/datadog-agent/comp/api/authtoken/fetchonlyimpl" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" configFetcher "github.com/DataDog/datadog-agent/pkg/config/fetcher" @@ -54,7 +54,7 @@ func setupFetcher(t *testing.T) { } func getSystemProbeComp(t *testing.T, enableConfig bool) *systemprobe { - l := fxutil.Test[log.Component](t, logimpl.MockModule()) + l := logmock.New(t) cfg := fxutil.Test[config.Component](t, config.MockModule()) cfg.Set("inventories_configuration_enabled", enableConfig, model.SourceUnknown) diff --git a/comp/netflow/config/config.go b/comp/netflow/config/config.go index e951450e998fb..ed5db3eb41bbc 100644 --- a/comp/netflow/config/config.go +++ b/comp/netflow/config/config.go @@ -8,9 +8,9 @@ package config import ( "fmt" - "github.com/DataDog/datadog-agent/comp/core/log" "github.com/DataDog/datadog-agent/comp/core/config" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/snmp/utils" diff --git a/comp/netflow/config/config_test.go b/comp/netflow/config/config_test.go index 9774cda69ca4f..89f232a601a0b 100644 --- a/comp/netflow/config/config_test.go +++ b/comp/netflow/config/config_test.go @@ -9,19 +9,16 @@ import ( "strings" "testing" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/netflow/common" "github.com/DataDog/datadog-agent/pkg/config" ) func TestReadConfig(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) var tests = []struct { name string diff --git a/comp/netflow/config/mock.go b/comp/netflow/config/mock.go index 06ce985026b7e..91b2ef7fd3cd7 100644 --- a/comp/netflow/config/mock.go +++ b/comp/netflow/config/mock.go @@ -8,7 +8,7 @@ package config import ( - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "go.uber.org/fx" ) diff --git a/comp/netflow/config/service.go b/comp/netflow/config/service.go index 4e49d1e6b3a31..ab0bfb3638154 100644 --- a/comp/netflow/config/service.go +++ b/comp/netflow/config/service.go @@ -7,7 +7,7 @@ package config import ( "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ) type configService struct { diff --git a/comp/netflow/flowaggregator/aggregator.go b/comp/netflow/flowaggregator/aggregator.go index 3c1b2c8f77ade..2f41e2ed85716 100644 --- a/comp/netflow/flowaggregator/aggregator.go +++ b/comp/netflow/flowaggregator/aggregator.go @@ -16,7 +16,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "go.uber.org/atomic" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/netflow/format" rdnsquerier "github.com/DataDog/datadog-agent/comp/rdnsquerier/def" diff --git a/comp/netflow/flowaggregator/aggregator_test.go b/comp/netflow/flowaggregator/aggregator_test.go index 89b17806795ef..181915ab3f628 100644 --- a/comp/netflow/flowaggregator/aggregator_test.go +++ b/comp/netflow/flowaggregator/aggregator_test.go @@ -29,8 +29,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" "github.com/DataDog/datadog-agent/pkg/aggregator/mocksender" "github.com/DataDog/datadog-agent/pkg/logs/message" @@ -168,7 +167,7 @@ func TestAggregator(t *testing.T) { epForwarder.EXPECT().SendEventPlatformEventBlocking(message.NewMessage(compactEvent.Bytes(), nil, "", 0), "network-devices-netflow").Return(nil).Times(1) epForwarder.EXPECT().SendEventPlatformEventBlocking(message.NewMessage(compactMetadataEvent.Bytes(), nil, "", 0), "network-devices-metadata").Return(nil).Times(1) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -271,7 +270,7 @@ func TestAggregator_withMockPayload(t *testing.T) { epForwarder.EXPECT().SendEventPlatformEventBlocking(message.NewMessage(compactMetadataEvent.Bytes(), nil, "", 0), "network-devices-metadata").Return(nil).Times(1) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) aggregator.FlushFlowsToSendInterval = 1 * time.Second @@ -332,7 +331,7 @@ func TestAggregator_withMockPayload(t *testing.T) { func TestFlowAggregator_flush_submitCollectorMetrics_error(t *testing.T) { // 1/ Arrange - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) var b bytes.Buffer w := bufio.NewWriter(&b) @@ -404,7 +403,7 @@ func TestFlowAggregator_submitCollectorMetrics(t *testing.T) { ctrl := gomock.NewController(t) epForwarder := eventplatformimpl.NewMockEventPlatformForwarder(ctrl) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -481,7 +480,7 @@ func TestFlowAggregator_submitCollectorMetrics_error(t *testing.T) { ctrl := gomock.NewController(t) epForwarder := eventplatformimpl.NewMockEventPlatformForwarder(ctrl) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -516,7 +515,7 @@ func TestFlowAggregator_sendExporterMetadata_multiplePayloads(t *testing.T) { ctrl := gomock.NewController(t) epForwarder := eventplatformimpl.NewMockEventPlatformForwarder(ctrl) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -601,7 +600,7 @@ func TestFlowAggregator_sendExporterMetadata_noPayloads(t *testing.T) { ctrl := gomock.NewController(t) epForwarder := eventplatformimpl.NewMockEventPlatformForwarder(ctrl) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -635,7 +634,7 @@ func TestFlowAggregator_sendExporterMetadata_invalidIPIgnored(t *testing.T) { ctrl := gomock.NewController(t) epForwarder := eventplatformimpl.NewMockEventPlatformForwarder(ctrl) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -720,7 +719,7 @@ func TestFlowAggregator_sendExporterMetadata_multipleNamespaces(t *testing.T) { ctrl := gomock.NewController(t) epForwarder := eventplatformimpl.NewMockEventPlatformForwarder(ctrl) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -823,7 +822,7 @@ func TestFlowAggregator_sendExporterMetadata_singleExporterIpWithMultipleFlowTyp ctrl := gomock.NewController(t) epForwarder := eventplatformimpl.NewMockEventPlatformForwarder(ctrl) - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) aggregator := NewFlowAggregator(sender, epForwarder, &conf, "my-hostname", logger, rdnsQuerier) @@ -893,7 +892,7 @@ func TestFlowAggregator_sendExporterMetadata_singleExporterIpWithMultipleFlowTyp } func TestFlowAggregator_getSequenceDelta(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) type round struct { flowsToFlush []*common.Flow diff --git a/comp/netflow/flowaggregator/flowaccumulator.go b/comp/netflow/flowaggregator/flowaccumulator.go index d27b043846789..de397e8694294 100644 --- a/comp/netflow/flowaggregator/flowaccumulator.go +++ b/comp/netflow/flowaggregator/flowaccumulator.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/netflow/common" "github.com/DataDog/datadog-agent/comp/netflow/portrollup" rdnsquerier "github.com/DataDog/datadog-agent/comp/rdnsquerier/def" diff --git a/comp/netflow/flowaggregator/flowaccumulator_test.go b/comp/netflow/flowaggregator/flowaccumulator_test.go index d976c20ed61db..8e51b56ac1f82 100644 --- a/comp/netflow/flowaggregator/flowaccumulator_test.go +++ b/comp/netflow/flowaggregator/flowaccumulator_test.go @@ -9,8 +9,7 @@ import ( "testing" "time" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/netflow/common" "github.com/DataDog/datadog-agent/comp/netflow/portrollup" rdnsquerier "github.com/DataDog/datadog-agent/comp/rdnsquerier/def" @@ -35,7 +34,7 @@ func setMockTimeNow(newTime time.Time) { } func Test_flowAccumulator_add(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) synFlag := uint32(2) ackFlag := uint32(16) @@ -117,7 +116,7 @@ func Test_flowAccumulator_add(t *testing.T) { } func Test_flowAccumulator_portRollUp(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) synFlag := uint32(2) ackFlag := uint32(16) @@ -221,7 +220,7 @@ func Test_flowAccumulator_portRollUp(t *testing.T) { } func Test_flowAccumulator_flush(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) rdnsQuerier := fxutil.Test[rdnsquerier.Component](t, rdnsquerierfxmock.MockModule()) timeNow = MockTimeNow zeroTime := time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC) diff --git a/comp/netflow/goflowlib/flowstate.go b/comp/netflow/goflowlib/flowstate.go index a4ab6e80502ae..433fcd644e8bc 100644 --- a/comp/netflow/goflowlib/flowstate.go +++ b/comp/netflow/goflowlib/flowstate.go @@ -8,6 +8,7 @@ package goflowlib import ( "context" "fmt" + "github.com/DataDog/datadog-agent/comp/netflow/config" "github.com/DataDog/datadog-agent/comp/netflow/goflowlib/netflowstate" @@ -18,7 +19,7 @@ import ( _ "github.com/netsampler/goflow2/decoders/netflow/templates/memory" "github.com/netsampler/goflow2/utils" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/netflow/common" ) diff --git a/comp/netflow/goflowlib/flowstate_test.go b/comp/netflow/goflowlib/flowstate_test.go index 4207905834715..10c109e621105 100644 --- a/comp/netflow/goflowlib/flowstate_test.go +++ b/comp/netflow/goflowlib/flowstate_test.go @@ -13,14 +13,12 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/atomic" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/netflow/common" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) func TestStartFlowRoutine_invalidType(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) listenerErr := atomic.NewString("") listenerFlowCount := atomic.NewInt64(0) diff --git a/comp/netflow/goflowlib/logger.go b/comp/netflow/goflowlib/logger.go index 71909b67d15ff..62035bcd052e5 100644 --- a/comp/netflow/goflowlib/logger.go +++ b/comp/netflow/goflowlib/logger.go @@ -9,7 +9,7 @@ import ( "github.com/cihub/seelog" "github.com/sirupsen/logrus" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ddlog "github.com/DataDog/datadog-agent/pkg/util/log" ) diff --git a/comp/netflow/server/listener.go b/comp/netflow/server/listener.go index 0309bbfc927cd..6d47d0a06926d 100644 --- a/comp/netflow/server/listener.go +++ b/comp/netflow/server/listener.go @@ -6,7 +6,7 @@ package server import ( - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/netflow/config" "github.com/DataDog/datadog-agent/comp/netflow/flowaggregator" "github.com/DataDog/datadog-agent/comp/netflow/goflowlib" diff --git a/comp/netflow/server/server.go b/comp/netflow/server/server.go index dab01bf775898..482ed0054a4cd 100644 --- a/comp/netflow/server/server.go +++ b/comp/netflow/server/server.go @@ -16,7 +16,7 @@ import ( "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/ndmtmp/forwarder" nfconfig "github.com/DataDog/datadog-agent/comp/netflow/config" diff --git a/comp/networkpath/npcollector/npcollectorimpl/npcollector.go b/comp/networkpath/npcollector/npcollectorimpl/npcollector.go index b541767c7a99c..e7cb212833032 100644 --- a/comp/networkpath/npcollector/npcollectorimpl/npcollector.go +++ b/comp/networkpath/npcollector/npcollectorimpl/npcollector.go @@ -17,7 +17,7 @@ import ( ddgostatsd "github.com/DataDog/datadog-go/v5/statsd" "go.uber.org/atomic" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" telemetryComp "github.com/DataDog/datadog-agent/comp/core/telemetry" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/common" diff --git a/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go b/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go index 2e749a332f7ac..ec345094590e2 100644 --- a/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go +++ b/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go @@ -60,6 +60,7 @@ func Test_NpCollector_StartAndStop(t *testing.T) { assert.False(t, npCollector.running) // TEST START/STOP using logs + l.Close() // We need to first close the logger to avoid a race-cond between seelog and out test when calling w.Flush() w.Flush() logs := b.String() diff --git a/comp/networkpath/npcollector/npcollectorimpl/npcollectorcomp.go b/comp/networkpath/npcollector/npcollectorimpl/npcollectorcomp.go index ec5f36d3fc48a..9102604bf3e43 100644 --- a/comp/networkpath/npcollector/npcollectorimpl/npcollectorcomp.go +++ b/comp/networkpath/npcollector/npcollectorimpl/npcollectorcomp.go @@ -11,7 +11,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/telemetry" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/networkpath/npcollector" diff --git a/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore.go b/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore.go index 64489f1b616d3..9a7fb594cbcba 100644 --- a/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore.go +++ b/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore.go @@ -10,7 +10,7 @@ import ( "sync" time "time" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/common" ) diff --git a/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go b/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go index c8bbf1ffc26ca..4fd758f2253d6 100644 --- a/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go +++ b/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go @@ -9,11 +9,10 @@ import ( "testing" "time" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" - "github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/common" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/stretchr/testify/assert" + + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" + "github.com/DataDog/datadog-agent/comp/networkpath/npcollector/npcollectorimpl/common" ) // MockTimeNow mocks time.Now @@ -31,7 +30,7 @@ func setMockTimeNow(newTime time.Time) { } func Test_pathtestStore_add(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) // GIVEN store := NewPathtestStore(10*time.Minute, 1*time.Minute, logger) @@ -54,7 +53,7 @@ func Test_pathtestStore_add(t *testing.T) { } func Test_pathtestStore_flush(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) timeNow = MockTimeNow runDurationFromDisc := 10 * time.Minute runInterval := 1 * time.Minute diff --git a/comp/otelcol/collector-contrib/impl/go.mod b/comp/otelcol/collector-contrib/impl/go.mod index 3bcc306132131..4e5f88e8316c7 100644 --- a/comp/otelcol/collector-contrib/impl/go.mod +++ b/comp/otelcol/collector-contrib/impl/go.mod @@ -308,4 +308,32 @@ replace github.com/mattn/go-ieproxy => github.com/mattn/go-ieproxy v0.0.1 replace github.com/openshift/api => github.com/openshift/api v0.0.0-20230726162818-81f778f3b3ec +replace github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector => github.com/open-telemetry/opentelemetry-collector-contrib/connector/datadogconnector v0.103.0 + +replace github.com/DataDog/datadog-agent/comp/core/config => ../../../core/config + +replace github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../core/flare/builder + +replace github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../core/flare/types + +replace github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface => ../../../core/hostname/hostnameinterface + +replace github.com/DataDog/datadog-agent/comp/core/log/def => ../../../core/log/def + +replace github.com/DataDog/datadog-agent/comp/core/log/mock => ../../../core/log/mock + +replace github.com/DataDog/datadog-agent/comp/core/secrets => ../../../core/secrets + +replace github.com/DataDog/datadog-agent/comp/core/telemetry => ../../../core/telemetry + +replace github.com/DataDog/datadog-agent/comp/def => ../../../def + +replace github.com/DataDog/datadog-agent/comp/trace/compression/impl-gzip => ../../../trace/compression/impl-gzip + +replace github.com/DataDog/datadog-agent/comp/trace/compression/def => ../../../trace/compression/def + +replace github.com/DataDog/datadog-agent/comp/trace/compression/impl-zstd => ../../../trace/compression/impl-zstd + +replace github.com/DataDog/datadog-agent/comp/logs/agent/config => ../../../logs/agent/config + replace github.com/DataDog/datadog-agent/comp/otelcol/collector-contrib/def => ../def diff --git a/comp/otelcol/collector/impl-pipeline/pipeline.go b/comp/otelcol/collector/impl-pipeline/pipeline.go index eae395c2f51ee..e2b4f46288938 100644 --- a/comp/otelcol/collector/impl-pipeline/pipeline.go +++ b/comp/otelcol/collector/impl-pipeline/pipeline.go @@ -13,7 +13,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - corelog "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/core/tagger" compdef "github.com/DataDog/datadog-agent/comp/def" @@ -42,7 +42,7 @@ type Requires struct { Config config.Component // Log specifies the logging component. - Log corelog.Component + Log log.Component // Serializer specifies the metrics serializer that is used to export metrics // to Datadog. @@ -69,7 +69,7 @@ type Provides struct { type collectorImpl struct { col *otlp.Pipeline config config.Component - log corelog.Component + log log.Component serializer serializer.MetricSerializer logsAgent optional.Option[logsagentpipeline.Component] inventoryAgent inventoryagent.Component diff --git a/comp/otelcol/collector/impl/collector.go b/comp/otelcol/collector/impl/collector.go index 16b54cb303d35..7805b96f31275 100644 --- a/comp/otelcol/collector/impl/collector.go +++ b/comp/otelcol/collector/impl/collector.go @@ -21,7 +21,7 @@ import ( "go.opentelemetry.io/collector/confmap/provider/yamlprovider" "go.opentelemetry.io/collector/otelcol" - corelog "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/tagger" compdef "github.com/DataDog/datadog-agent/comp/def" collectorcontrib "github.com/DataDog/datadog-agent/comp/otelcol/collector-contrib/def" @@ -44,7 +44,7 @@ import ( ) type collectorImpl struct { - log corelog.Component + log log.Component set otelcol.CollectorSettings col *otelcol.Collector } @@ -56,7 +56,7 @@ type Requires struct { Lc compdef.Lifecycle // Log specifies the logging component. - Log corelog.Component + Log log.Component Provider confmap.Converter ConfigStore configstore.Component CollectorContrib collectorcontrib.Component diff --git a/comp/otelcol/extension/impl/go.mod b/comp/otelcol/extension/impl/go.mod index edcf06ef104bf..394108f1642b8 100644 --- a/comp/otelcol/extension/impl/go.mod +++ b/comp/otelcol/extension/impl/go.mod @@ -7,7 +7,7 @@ replace ( github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface => ../../../core/hostname/hostnameinterface - github.com/DataDog/datadog-agent/comp/core/log => ../../../core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../../core/log/def github.com/DataDog/datadog-agent/comp/core/secrets => ../../../core/secrets github.com/DataDog/datadog-agent/comp/core/telemetry => ../../../core/telemetry github.com/DataDog/datadog-agent/comp/def => ../../../def diff --git a/comp/otelcol/logsagentpipeline/go.mod b/comp/otelcol/logsagentpipeline/go.mod index dbd22c84e354e..c1753d6fd2557 100644 --- a/comp/otelcol/logsagentpipeline/go.mod +++ b/comp/otelcol/logsagentpipeline/go.mod @@ -9,7 +9,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface => ../../core/hostname/hostnameinterface - github.com/DataDog/datadog-agent/comp/core/log => ../../core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../core/secrets github.com/DataDog/datadog-agent/comp/core/telemetry => ../../core/telemetry github.com/DataDog/datadog-agent/comp/def => ../../def diff --git a/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent.go b/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent.go index c874c00b21fba..d1910d28db034 100644 --- a/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent.go +++ b/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent.go @@ -13,7 +13,7 @@ import ( configComponent "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/logs/agent/config" "github.com/DataDog/datadog-agent/comp/otelcol/logsagentpipeline" pkgconfigmodel "github.com/DataDog/datadog-agent/pkg/config/model" @@ -42,14 +42,14 @@ type Dependencies struct { fx.In Lc fx.Lifecycle - Log logComponent.Component + Log log.Component Config configComponent.Component Hostname hostnameinterface.Component } // Agent represents the data pipeline that collects, decodes, processes and sends logs to the backend. type Agent struct { - log logComponent.Component + log log.Component config pkgconfigmodel.Reader hostname hostnameinterface.Component @@ -219,7 +219,7 @@ func (a *Agent) SetupPipeline( } // buildEndpoints builds endpoints for the logs agent -func buildEndpoints(coreConfig pkgconfigmodel.Reader, log logComponent.Component) (*config.Endpoints, error) { +func buildEndpoints(coreConfig pkgconfigmodel.Reader, log log.Component) (*config.Endpoints, error) { httpConnectivity := config.HTTPConnectivityFailure if endpoints, err := config.BuildHTTPEndpoints(coreConfig, intakeTrackType, config.AgentJSONIntakeProtocol, config.DefaultIntakeOrigin); err == nil { httpConnectivity = http.CheckConnectivity(endpoints.Main, coreConfig) diff --git a/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent_test.go b/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent_test.go index 50cf5d335f10b..da2be9d72e4d7 100644 --- a/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent_test.go +++ b/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/agent_test.go @@ -13,8 +13,8 @@ import ( "go.uber.org/fx" configComponent "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/logs/agent/config" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/logs/client/http" @@ -66,7 +66,7 @@ func (suite *AgentTestSuite) TearDownTest() { func createAgent(suite *AgentTestSuite, endpoints *config.Endpoints) *Agent { deps := fxutil.Test[testDeps](suite.T(), fx.Options( configComponent.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(suite.T()) }), fx.Replace(configComponent.MockParams{Overrides: suite.configOverrides}), )) @@ -177,7 +177,7 @@ func TestAgentTestSuite(t *testing.T) { func TestBuildEndpoints(t *testing.T) { deps := fxutil.Test[testDeps](t, fx.Options( configComponent.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), )) endpoints, err := buildEndpoints(deps.Config, deps.Log) diff --git a/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/go.mod b/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/go.mod index 2518970cc1d12..4802ed90b4ed9 100644 --- a/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/go.mod +++ b/comp/otelcol/logsagentpipeline/logsagentpipelineimpl/go.mod @@ -9,7 +9,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface => ../../../core/hostname/hostnameinterface - github.com/DataDog/datadog-agent/comp/core/log => ../../../core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../../core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../../core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../../core/secrets github.com/DataDog/datadog-agent/comp/core/telemetry => ../../../core/telemetry github.com/DataDog/datadog-agent/comp/def => ../../../def @@ -58,7 +59,8 @@ replace ( require ( github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface v0.56.0-rc.3 - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/core/log/mock v0.0.0-00010101000000-000000000000 github.com/DataDog/datadog-agent/comp/logs/agent/config v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/otelcol/logsagentpipeline v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.3 @@ -90,7 +92,7 @@ require ( github.com/DataDog/datadog-agent/comp/def v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/collector/check/defaults v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/config/env v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/pkg/config/logs v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/pkg/config/logs v0.0.0-00010101000000-000000000000 // indirect github.com/DataDog/datadog-agent/pkg/config/utils v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/logs/processor v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/pkg/logs/sds v0.56.0-rc.3 // indirect diff --git a/comp/otelcol/otlp/components/exporter/datadogexporter/go.mod b/comp/otelcol/otlp/components/exporter/datadogexporter/go.mod index 69af597ad68f2..bd17cc8e1d60b 100644 --- a/comp/otelcol/otlp/components/exporter/datadogexporter/go.mod +++ b/comp/otelcol/otlp/components/exporter/datadogexporter/go.mod @@ -9,7 +9,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../../../core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../../../core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface => ../../../../../core/hostname/hostnameinterface - github.com/DataDog/datadog-agent/comp/core/log => ../../../../../core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../../../../core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../../../../core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../../../../core/secrets github.com/DataDog/datadog-agent/comp/core/status => ../../../../../core/status github.com/DataDog/datadog-agent/comp/core/telemetry => ../../../../../core/telemetry @@ -124,7 +125,7 @@ require ( github.com/DataDog/datadog-agent/comp/core/flare/builder v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 // indirect github.com/DataDog/datadog-agent/comp/core/secrets v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/status v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/telemetry v0.56.0-rc.3 // indirect diff --git a/comp/otelcol/otlp/components/exporter/serializerexporter/go.mod b/comp/otelcol/otlp/components/exporter/serializerexporter/go.mod index 149df6493ce5c..82ecf4c22a49d 100644 --- a/comp/otelcol/otlp/components/exporter/serializerexporter/go.mod +++ b/comp/otelcol/otlp/components/exporter/serializerexporter/go.mod @@ -8,7 +8,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/config => ../../../../../core/config github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../../../../core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../../../../core/flare/types - github.com/DataDog/datadog-agent/comp/core/log => ../../../../../core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../../../../core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../../../../core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../../../../core/secrets github.com/DataDog/datadog-agent/comp/core/status => ../../../../../core/status github.com/DataDog/datadog-agent/comp/core/telemetry => ../../../../../core/telemetry @@ -89,7 +90,7 @@ require ( github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/flare/builder v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 // indirect github.com/DataDog/datadog-agent/comp/core/secrets v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/status v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/telemetry v0.56.0-rc.3 // indirect diff --git a/comp/otelcol/otlp/components/statsprocessor/agent_test.go b/comp/otelcol/otlp/components/statsprocessor/agent_test.go index 2cf3f38674ad9..8810c0513abcc 100644 --- a/comp/otelcol/otlp/components/statsprocessor/agent_test.go +++ b/comp/otelcol/otlp/components/statsprocessor/agent_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/otel/sdk/metric" @@ -79,22 +80,25 @@ func TestTraceAgent(t *testing.T) { a.Ingest(ctx, traces) var stats *pb.StatsPayload - timeout := time.After(500 * time.Millisecond) -loop: - for { + timeout := time.After(5 * time.Second) + var actual []*pb.ClientGroupedStats + // Depending on the time bucket boundaries, the stats can come in one or multiple payloads. + // Wait until all payloads are received. + for len(actual) < traces.SpanCount() { select { case stats = <-out: if len(stats.Stats) != 0 { - break loop + require.Len(t, stats.Stats, 1) + require.Len(t, stats.Stats[0].Stats, 1) + assert.Greater(t, len(stats.Stats[0].Stats[0].Stats), 0) + actual = append(actual, stats.Stats[0].Stats[0].Stats...) } case <-timeout: t.Fatal("timed out") } } - require.Len(t, stats.Stats, 1) - require.Len(t, stats.Stats[0].Stats, 1) // considering all spans in rspans have distinct aggregations, we should have an equal amount // of groups - require.Len(t, stats.Stats[0].Stats[0].Stats, traces.SpanCount()) + require.Len(t, actual, traces.SpanCount()) } diff --git a/comp/otelcol/otlp/integrationtest/integration_test.go b/comp/otelcol/otlp/integrationtest/integration_test.go index d7c599a633964..55a58caf34f95 100644 --- a/comp/otelcol/otlp/integrationtest/integration_test.go +++ b/comp/otelcol/otlp/integrationtest/integration_test.go @@ -37,8 +37,8 @@ import ( "github.com/DataDog/datadog-agent/comp/api/authtoken/fetchonlyimpl" coreconfig "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface" - corelogimpl "github.com/DataDog/datadog-agent/comp/core/log/logimpl" - "github.com/DataDog/datadog-agent/comp/core/log/tracelogimpl" + logdef "github.com/DataDog/datadog-agent/comp/core/log/def" + logtrace "github.com/DataDog/datadog-agent/comp/core/log/fx-trace" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/tagger" @@ -81,7 +81,7 @@ import ( func runTestOTelAgent(ctx context.Context, params *subcommands.GlobalParams) error { return fxutil.Run( forwarder.Bundle(), - tracelogimpl.Module(), // cannot have corelogimpl and tracelogimpl at the same time + logtrace.Module(), inventoryagentimpl.Module(), workloadmetafx.Module(), fx.Supply(metricsclient.NewStatsdClientWrapper(&ddgostatsd.NoOpClient{})), @@ -117,8 +117,8 @@ func runTestOTelAgent(ctx context.Context, params *subcommands.GlobalParams) err hostnameinterface.MockModule(), fx.Supply(optional.NewNoneOption[secrets.Component]()), - fx.Provide(func(c coreconfig.Component) corelogimpl.Params { - return corelogimpl.ForDaemon(params.LoggerName, "log_file", pkgconfigsetup.DefaultOTelAgentLogFile) + fx.Provide(func(c coreconfig.Component) logdef.Params { + return logdef.ForDaemon(params.LoggerName, "log_file", pkgconfigsetup.DefaultOTelAgentLogFile) }), logsagentpipelineimpl.Module(), // We create strategy.ZlibStrategy directly to avoid build tags diff --git a/comp/process/agent/agent_fallback.go b/comp/process/agent/agent_fallback.go index 0ea2f08114684..43daf32d7ae37 100644 --- a/comp/process/agent/agent_fallback.go +++ b/comp/process/agent/agent_fallback.go @@ -9,13 +9,13 @@ package agent import ( "github.com/DataDog/datadog-agent/comp/core/config" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/process/types" "github.com/DataDog/datadog-agent/pkg/util/flavor" ) // Enabled determines whether the process agent is enabled based on the configuration // The process-agent always runs as a stand-alone agent in all non-linux platforms -func Enabled(_ config.Component, _ []types.CheckComponent, _ logComponent.Component) bool { +func Enabled(_ config.Component, _ []types.CheckComponent, _ log.Component) bool { return flavor.GetFlavor() == flavor.ProcessAgent } diff --git a/comp/process/agent/agent_linux.go b/comp/process/agent/agent_linux.go index d6161b4cae4ef..2a5b1513719c4 100644 --- a/comp/process/agent/agent_linux.go +++ b/comp/process/agent/agent_linux.go @@ -12,7 +12,7 @@ import ( "sync" "github.com/DataDog/datadog-agent/comp/core/config" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/process/types" "github.com/DataDog/datadog-agent/pkg/process/checks" "github.com/DataDog/datadog-agent/pkg/util/flavor" @@ -32,7 +32,7 @@ var ( } ) -func enabledHelper(config config.Component, checkComponents []types.CheckComponent, log logComponent.Component) bool { +func enabledHelper(config config.Component, checkComponents []types.CheckComponent, l log.Component) bool { runInCoreAgent := config.GetBool("process_config.run_in_core_agent.enabled") var npmEnabled bool @@ -50,15 +50,15 @@ func enabledHelper(config config.Component, checkComponents []types.CheckCompone case flavor.ProcessAgent: if npmEnabled { if runInCoreAgent { - log.Info("Network Performance Monitoring is not supported in the core agent. " + + l.Info("Network Performance Monitoring is not supported in the core agent. " + "The process-agent will be enabled as a standalone agent") } } if runInCoreAgent { - log.Info("The process checks will run in the core agent") + l.Info("The process checks will run in the core agent") } else if processEnabled { - log.Info("Process/Container Collection in the Process Agent will be deprecated in a future release " + + l.Info("Process/Container Collection in the Process Agent will be deprecated in a future release " + "and will instead be run in the Core Agent. " + "Set process_config.run_in_core_agent.enabled to true to switch now.") } @@ -66,7 +66,7 @@ func enabledHelper(config config.Component, checkComponents []types.CheckCompone return !runInCoreAgent || npmEnabled case flavor.DefaultAgent: if npmEnabled && runInCoreAgent { - log.Info("Network Performance Monitoring is not supported in the core agent. " + + l.Info("Network Performance Monitoring is not supported in the core agent. " + "The process-agent will be enabled as a standalone agent to collect network performance metrics.") } return runInCoreAgent @@ -83,9 +83,9 @@ func enabledHelper(config config.Component, checkComponents []types.CheckCompone // enabled. // If 'run_in_core_agent' flag is enabled and the connections/NPM check is not enabled, the process-agent will run in // the core agent. -func Enabled(config config.Component, checkComponents []types.CheckComponent, log logComponent.Component) bool { +func Enabled(config config.Component, checkComponents []types.CheckComponent, l log.Component) bool { Once.Do(func() { - enabled = enabledHelper(config, checkComponents, log) + enabled = enabledHelper(config, checkComponents, l) }) return enabled } diff --git a/comp/process/agent/agentimpl/agent.go b/comp/process/agent/agentimpl/agent.go index 29e9e4787290b..4eb469a1540e4 100644 --- a/comp/process/agent/agentimpl/agent.go +++ b/comp/process/agent/agentimpl/agent.go @@ -11,7 +11,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" flaretypes "github.com/DataDog/datadog-agent/comp/core/flare/types" - logComponent "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" statusComponent "github.com/DataDog/datadog-agent/comp/core/status" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" statsdComp "github.com/DataDog/datadog-agent/comp/dogstatsd/statsd" @@ -48,7 +48,7 @@ type dependencies struct { fx.In Lc fx.Lifecycle - Log logComponent.Component + Log log.Component Config config.Component Checks []types.CheckComponent `group:"check"` Runner runner.Component @@ -61,7 +61,7 @@ type dependencies struct { type processAgent struct { enabled bool Checks []checks.Check - Log logComponent.Component + Log log.Component flarehelper *agent.FlareHelper } diff --git a/comp/process/apiserver/apiserver.go b/comp/process/apiserver/apiserver.go index d537c201dc5e6..342b8651b334b 100644 --- a/comp/process/apiserver/apiserver.go +++ b/comp/process/apiserver/apiserver.go @@ -15,7 +15,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/cmd/process-agent/api" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ddconfig "github.com/DataDog/datadog-agent/pkg/config" ) diff --git a/comp/process/bundle_test.go b/comp/process/bundle_test.go index 45bde5e6a52bf..dc39090d6f6e7 100644 --- a/comp/process/bundle_test.go +++ b/comp/process/bundle_test.go @@ -14,7 +14,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" configComp "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/settings/settingsimpl" "github.com/DataDog/datadog-agent/comp/core/status" coreStatusImpl "github.com/DataDog/datadog-agent/comp/core/status/statusimpl" @@ -34,7 +34,7 @@ import ( var mockCoreBundleParams = core.BundleParams{ ConfigParams: configComp.NewParams("", configComp.WithConfigMissingOK(true)), - LogParams: logimpl.ForOneShot("PROCESS", "trace", false), + LogParams: log.ForOneShot("PROCESS", "trace", false), } func TestBundleDependencies(t *testing.T) { diff --git a/comp/process/expvars/expvarsimpl/expvars.go b/comp/process/expvars/expvarsimpl/expvars.go index 4200f2b37aa18..5d2de42de0f6f 100644 --- a/comp/process/expvars/expvarsimpl/expvars.go +++ b/comp/process/expvars/expvarsimpl/expvars.go @@ -16,7 +16,7 @@ import ( sysconfig "github.com/DataDog/datadog-agent/cmd/system-probe/config" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/telemetry" "github.com/DataDog/datadog-agent/comp/process/expvars" diff --git a/comp/process/forwarders/forwardersimpl/forwarders.go b/comp/process/forwarders/forwardersimpl/forwarders.go index 90aeb0ef0dbd4..38291418d9b56 100644 --- a/comp/process/forwarders/forwardersimpl/forwarders.go +++ b/comp/process/forwarders/forwardersimpl/forwarders.go @@ -10,7 +10,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder/resolver" "github.com/DataDog/datadog-agent/comp/process/forwarders" diff --git a/comp/process/hostinfo/hostinfoimpl/hostinfo.go b/comp/process/hostinfo/hostinfoimpl/hostinfo.go index 95f499099b375..522cb6404a8fa 100644 --- a/comp/process/hostinfo/hostinfoimpl/hostinfo.go +++ b/comp/process/hostinfo/hostinfoimpl/hostinfo.go @@ -12,7 +12,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" hostinfoComp "github.com/DataDog/datadog-agent/comp/process/hostinfo" "github.com/DataDog/datadog-agent/pkg/process/checks" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/comp/process/runner/runnerimpl/runner.go b/comp/process/runner/runnerimpl/runner.go index f455ab75929d1..a0cabc22c3ce9 100644 --- a/comp/process/runner/runnerimpl/runner.go +++ b/comp/process/runner/runnerimpl/runner.go @@ -12,7 +12,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/process/agent" "github.com/DataDog/datadog-agent/comp/process/hostinfo" diff --git a/comp/process/runner/runnerimpl/runner_test.go b/comp/process/runner/runnerimpl/runner_test.go index 71bff260b923b..1257df2bab329 100644 --- a/comp/process/runner/runnerimpl/runner_test.go +++ b/comp/process/runner/runnerimpl/runner_test.go @@ -16,7 +16,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafx "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx" "github.com/DataDog/datadog-agent/comp/process/containercheck/containercheckimpl" diff --git a/comp/process/submitter/submitterimpl/submitter.go b/comp/process/submitter/submitterimpl/submitter.go index 9302618d6c4ab..aee08b06d5e2a 100644 --- a/comp/process/submitter/submitterimpl/submitter.go +++ b/comp/process/submitter/submitterimpl/submitter.go @@ -14,7 +14,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/process/agent" "github.com/DataDog/datadog-agent/comp/process/forwarders" "github.com/DataDog/datadog-agent/comp/process/hostinfo" diff --git a/comp/rdnsquerier/impl/rdnsquerier.go b/comp/rdnsquerier/impl/rdnsquerier.go index a9873eb47d19f..163ae12b108cb 100644 --- a/comp/rdnsquerier/impl/rdnsquerier.go +++ b/comp/rdnsquerier/impl/rdnsquerier.go @@ -14,7 +14,7 @@ import ( "sync" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/telemetry" compdef "github.com/DataDog/datadog-agent/comp/def" rdnsquerier "github.com/DataDog/datadog-agent/comp/rdnsquerier/def" diff --git a/comp/rdnsquerier/impl/rdnsquerier_testutils.go b/comp/rdnsquerier/impl/rdnsquerier_testutils.go index 04480344181bc..b68681a34cbe7 100644 --- a/comp/rdnsquerier/impl/rdnsquerier_testutils.go +++ b/comp/rdnsquerier/impl/rdnsquerier_testutils.go @@ -17,8 +17,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/telemetry" "github.com/DataDog/datadog-agent/comp/core/telemetry/telemetryimpl" compdef "github.com/DataDog/datadog-agent/comp/def" @@ -51,7 +51,7 @@ func testSetup(t *testing.T, overrides map[string]interface{}, start bool) *test fx.Replace(config.MockParams{Overrides: overrides}), )) - logComp := fxutil.Test[log.Component](t, logimpl.MockModule()) + logComp := logmock.New(t) telemetryComp := fxutil.Test[telemetry.Component](t, telemetryimpl.MockModule()) requires := Requires{ diff --git a/comp/remote-config/rcclient/rcclientimpl/rcclient.go b/comp/remote-config/rcclient/rcclientimpl/rcclient.go index a0465be649e10..693c7d42e1971 100644 --- a/comp/remote-config/rcclient/rcclientimpl/rcclient.go +++ b/comp/remote-config/rcclient/rcclientimpl/rcclient.go @@ -16,7 +16,7 @@ import ( "github.com/pkg/errors" "go.uber.org/fx" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/remote-config/rcclient" "github.com/DataDog/datadog-agent/comp/remote-config/rcclient/types" diff --git a/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go b/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go index 41455bf8b95d7..b7ba8ab8ff88d 100644 --- a/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go +++ b/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go @@ -10,7 +10,8 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/settings/settingsimpl" "github.com/DataDog/datadog-agent/comp/remote-config/rcclient" @@ -64,7 +65,7 @@ func TestRCClientCreate(t *testing.T) { _, err := newRemoteConfigClient( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), settingsimpl.MockModule(), ), ) @@ -74,7 +75,7 @@ func TestRCClientCreate(t *testing.T) { client, err := newRemoteConfigClient( fxutil.Test[dependencies]( t, - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( rcclient.Params{ AgentName: "test-agent", @@ -96,7 +97,7 @@ func TestAgentConfigCallback(t *testing.T) { rc := fxutil.Test[rcclient.Component](t, fx.Options( Module(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply( rcclient.Params{ AgentName: "test-agent", diff --git a/comp/remote-config/rcservice/rcserviceimpl/rcservice.go b/comp/remote-config/rcservice/rcserviceimpl/rcservice.go index 3bf5c6312967b..56f051b9aa77e 100644 --- a/comp/remote-config/rcservice/rcserviceimpl/rcservice.go +++ b/comp/remote-config/rcservice/rcserviceimpl/rcservice.go @@ -10,7 +10,7 @@ import ( "context" "fmt" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/util/optional" cfgcomp "github.com/DataDog/datadog-agent/comp/core/config" diff --git a/comp/remote-config/rcservicemrf/rcservicemrfimpl/rcservicemrf.go b/comp/remote-config/rcservicemrf/rcservicemrfimpl/rcservicemrf.go index d64d55b07d15f..e99854e6af15d 100644 --- a/comp/remote-config/rcservicemrf/rcservicemrfimpl/rcservicemrf.go +++ b/comp/remote-config/rcservicemrf/rcservicemrfimpl/rcservicemrf.go @@ -10,7 +10,7 @@ import ( "context" "fmt" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" cfgcomp "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname" diff --git a/comp/snmptraps/bundle_test.go b/comp/snmptraps/bundle_test.go index c17b9abb770a1..08472fc42e5b4 100644 --- a/comp/snmptraps/bundle_test.go +++ b/comp/snmptraps/bundle_test.go @@ -13,16 +13,18 @@ import ( "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/pkg/util/fxutil" + "go.uber.org/fx" ) func TestBundleDependencies(t *testing.T) { fxutil.TestBundle(t, Bundle(), config.MockModule(), hostnameimpl.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), demultiplexerimpl.MockModule(), defaultforwarder.MockModule(), ) diff --git a/comp/snmptraps/config/config.go b/comp/snmptraps/config/config.go index 425717c723700..97afe10653c77 100644 --- a/comp/snmptraps/config/config.go +++ b/comp/snmptraps/config/config.go @@ -12,7 +12,7 @@ import ( "github.com/gosnmp/gosnmp" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/snmptraps/snmplog" "github.com/DataDog/datadog-agent/pkg/snmp/gosnmplib" "github.com/DataDog/datadog-agent/pkg/snmp/utils" diff --git a/comp/snmptraps/config/config_test.go b/comp/snmptraps/config/config_test.go index a60f6ca87bd96..49064af0866e6 100644 --- a/comp/snmptraps/config/config_test.go +++ b/comp/snmptraps/config/config_test.go @@ -13,8 +13,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/gosnmp/gosnmp" "github.com/mitchellh/mapstructure" @@ -129,12 +129,14 @@ func buildConfig(conf config.Component, hnService hostname.Component) (*TrapsCon } // testOptions provides several fx options that multiple tests need -var testOptions = fx.Options( - fx.Provide(buildConfig), - hostnameimpl.MockModule(), - fx.Replace(hostnameimpl.MockHostname(mockedHostname)), - logimpl.MockModule(), -) +func testOptions(t *testing.T) fx.Option { + return fx.Options( + fx.Provide(buildConfig), + hostnameimpl.MockModule(), + fx.Replace(hostnameimpl.MockHostname(mockedHostname)), + fx.Provide(func() log.Component { return logmock.New(t) }), + ) +} func TestFullConfig(t *testing.T) { deps := fxutil.Test[struct { @@ -142,7 +144,7 @@ func TestFullConfig(t *testing.T) { Config *TrapsConfig Logger log.Component }](t, - testOptions, + testOptions(t), withConfig(t, &TrapsConfig{ Port: 1234, Users: usersV3, @@ -207,7 +209,7 @@ func TestMinimalConfig(t *testing.T) { Logger log.Component }](t, config.MockModule(), - testOptions, + testOptions(t), ) config := deps.Config logger := deps.Logger @@ -229,7 +231,7 @@ func TestMinimalConfig(t *testing.T) { func TestDefaultUsers(t *testing.T) { config := fxutil.Test[*TrapsConfig](t, - testOptions, + testOptions(t), withConfig(t, &TrapsConfig{ CommunityStrings: []string{"public"}, StopTimeout: 11, @@ -252,7 +254,7 @@ func TestBuildAuthoritativeEngineID(t *testing.T) { func TestNamespaceIsNormalized(t *testing.T) { config := fxutil.Test[*TrapsConfig](t, - testOptions, + testOptions(t), withConfig(t, &TrapsConfig{ Namespace: "><\n\r\tfoo", }, ""), @@ -272,7 +274,7 @@ func TestInvalidNamespace(t *testing.T) { func TestNamespaceSetGlobally(t *testing.T) { config := fxutil.Test[*TrapsConfig](t, - testOptions, + testOptions(t), withConfig(t, nil, "foo"), ) assert.Equal(t, "foo", config.Namespace) @@ -280,7 +282,7 @@ func TestNamespaceSetGlobally(t *testing.T) { func TestNamespaceSetBothGloballyAndLocally(t *testing.T) { config := fxutil.Test[*TrapsConfig](t, - testOptions, + testOptions(t), withConfig(t, &TrapsConfig{Namespace: "bar"}, "foo"), diff --git a/comp/snmptraps/formatter/formatterimpl/formatter.go b/comp/snmptraps/formatter/formatterimpl/formatter.go index 185c0b0d7c204..df73ce5881680 100644 --- a/comp/snmptraps/formatter/formatterimpl/formatter.go +++ b/comp/snmptraps/formatter/formatterimpl/formatter.go @@ -15,7 +15,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/snmptraps/formatter" "github.com/DataDog/datadog-agent/comp/snmptraps/oidresolver" "github.com/DataDog/datadog-agent/comp/snmptraps/packet" diff --git a/comp/snmptraps/formatter/formatterimpl/formatter_test.go b/comp/snmptraps/formatter/formatterimpl/formatter_test.go index b823d04b950d3..240d77d657c8e 100644 --- a/comp/snmptraps/formatter/formatterimpl/formatter_test.go +++ b/comp/snmptraps/formatter/formatterimpl/formatter_test.go @@ -13,8 +13,7 @@ import ( "go.uber.org/fx" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/snmptraps/formatter" "github.com/DataDog/datadog-agent/comp/snmptraps/oidresolver" "github.com/DataDog/datadog-agent/comp/snmptraps/oidresolver/oidresolverimpl" @@ -854,7 +853,7 @@ func TestIsBitEnabled(t *testing.T) { } func TestEnrichBits(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) data := []struct { description string variable trapVariable diff --git a/comp/snmptraps/forwarder/forwarderimpl/forwarder.go b/comp/snmptraps/forwarder/forwarderimpl/forwarder.go index 0f77eb8027076..9d6299edd5fc2 100644 --- a/comp/snmptraps/forwarder/forwarderimpl/forwarder.go +++ b/comp/snmptraps/forwarder/forwarderimpl/forwarder.go @@ -13,7 +13,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/snmptraps/config" "github.com/DataDog/datadog-agent/comp/snmptraps/formatter" diff --git a/comp/snmptraps/listener/listenerimpl/listener.go b/comp/snmptraps/listener/listenerimpl/listener.go index c5b4cf5ee1654..d8e73d0e8e055 100644 --- a/comp/snmptraps/listener/listenerimpl/listener.go +++ b/comp/snmptraps/listener/listenerimpl/listener.go @@ -20,7 +20,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/snmptraps/config" "github.com/DataDog/datadog-agent/comp/snmptraps/listener" "github.com/DataDog/datadog-agent/comp/snmptraps/packet" diff --git a/comp/snmptraps/listener/listenerimpl/listener_test.go b/comp/snmptraps/listener/listenerimpl/listener_test.go index 954467d40fd60..3623a5784bf90 100644 --- a/comp/snmptraps/listener/listenerimpl/listener_test.go +++ b/comp/snmptraps/listener/listenerimpl/listener_test.go @@ -12,7 +12,7 @@ import ( "go.uber.org/fx" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/snmptraps/config" "github.com/DataDog/datadog-agent/comp/snmptraps/config/configimpl" "github.com/DataDog/datadog-agent/comp/snmptraps/listener" diff --git a/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver.go b/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver.go index ac21e6e62a7a1..43a67cf332de3 100644 --- a/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver.go +++ b/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver.go @@ -21,7 +21,7 @@ import ( "gopkg.in/yaml.v2" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/snmptraps/oidresolver" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) diff --git a/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver_test.go b/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver_test.go index 9477dcd611299..f075c0a24f8f0 100644 --- a/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver_test.go +++ b/comp/snmptraps/oidresolver/oidresolverimpl/oid_resolver_test.go @@ -15,12 +15,11 @@ import ( "testing" "time" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + "gopkg.in/yaml.v2" + + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/snmptraps/oidresolver" - "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" ) type MockedDirEntry struct { @@ -45,7 +44,7 @@ func (m MockedDirEntry) Type() fs.FileMode { } func blankResolver(t testing.TB) *multiFilesOIDResolver { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) return &multiFilesOIDResolver{traps: make(oidresolver.TrapSpec), logger: logger} } @@ -74,7 +73,7 @@ func TestDecoding(t *testing.T) { } func TestSortFiles(t *testing.T) { - logger := fxutil.Test[log.Component](t, logimpl.MockModule()) + logger := logmock.New(t) files := []fs.DirEntry{ MockedDirEntry{name: "totoro", isDir: false}, MockedDirEntry{name: "porco", isDir: false}, diff --git a/comp/snmptraps/server/serverimpl/server.go b/comp/snmptraps/server/serverimpl/server.go index c8bfec6f25391..269d771b2ee45 100644 --- a/comp/snmptraps/server/serverimpl/server.go +++ b/comp/snmptraps/server/serverimpl/server.go @@ -12,7 +12,7 @@ import ( "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" coreStatus "github.com/DataDog/datadog-agent/comp/core/status" "go.uber.org/fx" diff --git a/comp/snmptraps/snmplog/snmplog.go b/comp/snmptraps/snmplog/snmplog.go index ca9f4a03bc69b..c7987733241c6 100644 --- a/comp/snmptraps/snmplog/snmplog.go +++ b/comp/snmptraps/snmplog/snmplog.go @@ -9,7 +9,7 @@ package snmplog import ( "github.com/gosnmp/gosnmp" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" ) // SNMPLogger is a GoSNMP logger interface implementation. diff --git a/comp/systray/systray/systrayimpl/systray.go b/comp/systray/systray/systrayimpl/systray.go index 449276e55c0a5..406c98b96e44d 100644 --- a/comp/systray/systray/systrayimpl/systray.go +++ b/comp/systray/systray/systrayimpl/systray.go @@ -21,7 +21,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/systray/systray" "github.com/DataDog/datadog-agent/pkg/util/fxutil" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" diff --git a/comp/trace/bundle_test.go b/comp/trace/bundle_test.go index 35205a42dfb6c..f4037b6816796 100644 --- a/comp/trace/bundle_test.go +++ b/comp/trace/bundle_test.go @@ -14,9 +14,12 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + coreconfig "github.com/DataDog/datadog-agent/comp/core/config" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" + "github.com/DataDog/datadog-agent/comp/core/telemetry/telemetryimpl" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafx "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx" "github.com/DataDog/datadog-agent/comp/dogstatsd/statsd" @@ -60,7 +63,9 @@ func TestMockBundleDependencies(t *testing.T) { cfg := fxutil.Test[config.Component](t, fx.Options( fx.Provide(func() context.Context { return context.TODO() }), // fx.Supply(ctx) fails with a missing type error. fx.Supply(core.BundleParams{}), - traceMockBundle, + coreconfig.MockModule(), + telemetryimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply(workloadmeta.NewParams()), workloadmetafx.Module(), fx.Invoke(func(_ config.Component) {}), @@ -76,10 +81,3 @@ func TestMockBundleDependencies(t *testing.T) { require.NotNil(t, cfg.Object()) } - -var traceMockBundle = core.MakeMockBundle( - fx.Provide(func() logimpl.Params { - return logimpl.ForDaemon("TRACE", "apm_config.log_file", config.DefaultLogFilePath) - }), - logimpl.TraceMockModule(), -) diff --git a/comp/trace/etwtracer/etwtracerimpl/etwtracerimpl.go b/comp/trace/etwtracer/etwtracerimpl/etwtracerimpl.go index 9c98dcfcf7224..68cea9d080111 100644 --- a/comp/trace/etwtracer/etwtracerimpl/etwtracerimpl.go +++ b/comp/trace/etwtracer/etwtracerimpl/etwtracerimpl.go @@ -28,7 +28,7 @@ import ( "go.uber.org/fx" "golang.org/x/sys/windows" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/etw" "github.com/DataDog/datadog-agent/comp/trace/etwtracer" "github.com/DataDog/datadog-agent/pkg/util/fxutil" diff --git a/comp/updater/localapi/localapiimpl/local_api.go b/comp/updater/localapi/localapiimpl/local_api.go index 9456a65443e57..a1bfaf937efbf 100644 --- a/comp/updater/localapi/localapiimpl/local_api.go +++ b/comp/updater/localapi/localapiimpl/local_api.go @@ -12,7 +12,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/updater/localapi" updatercomp "github.com/DataDog/datadog-agent/comp/updater/updater" "github.com/DataDog/datadog-agent/pkg/fleet/daemon" diff --git a/comp/updater/updater/updaterimpl/updater.go b/comp/updater/updater/updaterimpl/updater.go index 46a52f26913ec..117ea9c937653 100644 --- a/comp/updater/updater/updaterimpl/updater.go +++ b/comp/updater/updater/updaterimpl/updater.go @@ -13,7 +13,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/remote-config/rcservice" updatercomp "github.com/DataDog/datadog-agent/comp/updater/updater" "github.com/DataDog/datadog-agent/pkg/fleet/daemon" diff --git a/go.mod b/go.mod index 055415457af3c..413deeec6c270 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,10 @@ replace ( github.com/DataDog/datadog-agent/comp/core/flare/builder => ./comp/core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ./comp/core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface => ./comp/core/hostname/hostnameinterface - github.com/DataDog/datadog-agent/comp/core/log => ./comp/core/log/ + github.com/DataDog/datadog-agent/comp/core/log/def => ./comp/core/log/def + github.com/DataDog/datadog-agent/comp/core/log/impl => ./comp/core/log/impl + github.com/DataDog/datadog-agent/comp/core/log/impl-trace => ./comp/core/log/impl-trace + github.com/DataDog/datadog-agent/comp/core/log/mock => ./comp/core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ./comp/core/secrets github.com/DataDog/datadog-agent/comp/core/status => ./comp/core/status github.com/DataDog/datadog-agent/comp/core/status/statusimpl => ./comp/core/status/statusimpl @@ -183,7 +186,7 @@ require ( github.com/coreos/go-semver v0.3.1 github.com/coreos/go-systemd v22.5.0+incompatible github.com/cri-o/ocicni v0.4.3 - github.com/cyphar/filepath-securejoin v0.3.0 + github.com/cyphar/filepath-securejoin v0.3.1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/docker/docker v25.0.5+incompatible github.com/docker/go-connections v0.5.0 @@ -304,7 +307,7 @@ require ( golang.org/x/tools v0.23.0 golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 google.golang.org/genproto v0.0.0-20240617180043-68d350f18fd4 // indirect - google.golang.org/grpc v1.64.1 + google.golang.org/grpc v1.65.0 google.golang.org/grpc/examples v0.0.0-20221020162917-9127159caf5a google.golang.org/protobuf v1.34.2 gopkg.in/DataDog/dd-trace-go.v1 v1.65.1 @@ -416,7 +419,7 @@ require ( github.com/go-openapi/validate v0.23.0 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/godbus/dbus/v5 v5.1.0 - github.com/golang/glog v1.2.0 // indirect + github.com/golang/glog v1.2.1 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/licenseclassifier/v2 v2.0.0 // indirect github.com/google/uuid v1.6.0 @@ -599,7 +602,10 @@ require ( github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface v0.56.0-rc.3 - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/core/log/impl v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/core/log/impl-trace v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/comp/core/log/mock v0.0.0-00010101000000-000000000000 github.com/DataDog/datadog-agent/comp/core/secrets v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/core/status v0.56.0-rc.3 github.com/DataDog/datadog-agent/comp/core/status/statusimpl v0.56.0-rc.3 @@ -634,7 +640,7 @@ require ( github.com/DataDog/datadog-agent/pkg/collector/check/defaults v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/env v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/logs v0.56.0-rc.3 - github.com/DataDog/datadog-agent/pkg/config/mock v0.0.0-00010101000000-000000000000 + github.com/DataDog/datadog-agent/pkg/config/mock v0.0.0-20240723160440-69ec7b21bb9c github.com/DataDog/datadog-agent/pkg/config/model v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/remote v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/config/setup v0.56.0-rc.3 @@ -787,7 +793,7 @@ require ( github.com/cheggaaa/pb/v3 v3.1.4 // indirect github.com/chrusty/protoc-gen-jsonschema v0.0.0-20240212064413-73d5723042b8 // indirect github.com/cloudflare/circl v1.3.7 // indirect - github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 // indirect + github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b // indirect github.com/containerd/errdefs v0.1.0 // indirect github.com/containerd/log v0.1.0 // indirect github.com/csaf-poc/csaf_distribution/v3 v3.0.0 // indirect diff --git a/go.sum b/go.sum index 287933bd75ea0..8d930d4de24ae 100644 --- a/go.sum +++ b/go.sum @@ -693,6 +693,8 @@ github.com/DataDog/aptly v1.5.3 h1:oLsRvjuXSVM4ia0N83dU3KiQeiJ6BaszYbTZOkSfDlw= github.com/DataDog/aptly v1.5.3/go.mod h1:ZL5TfCso+z4enH03N+s3z8tYUJHhL6DlxIvnnP2TbY4= github.com/DataDog/cast v1.3.1-0.20190301154711-1ee8c8bd14a3 h1:SobA9WYm4K/MUtWlbKaomWTmnuYp1KhIm8Wlx3vmpsg= github.com/DataDog/cast v1.3.1-0.20190301154711-1ee8c8bd14a3/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/DataDog/datadog-agent/comp/core/log v0.54.0 h1:wP3bJua8qmURqLXkmYxrbELMJQ2oO1MuVNfxHJT4wiQ= +github.com/DataDog/datadog-agent/comp/core/log v0.54.0/go.mod h1:mtMxZiwg13b4bHgDf8xE6FHgTcadzI5Cc0lx2MSY1mE= github.com/DataDog/datadog-api-client-go/v2 v2.26.0 h1:bZr0hu+hx8L91+yU5EGw8wK3FlCVEIashpx+cylWsf0= github.com/DataDog/datadog-api-client-go/v2 v2.26.0/go.mod h1:QKOu6vscsh87fMY1lHfLEmNSunyXImj8BUaUWJXOehc= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= @@ -1076,8 +1078,8 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20220314180256-7f1daf1720fc/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50 h1:DBmgJDC9dTfkVyGgipamEh2BpGYxScCH1TOF1LL1cXc= -github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50/go.mod h1:5e1+Vvlzido69INQaVO6d87Qn543Xr6nooe9Kz7oBFM= +github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b h1:ga8SEFjZ60pxLcmhnThWgvH2wg8376yUJmPhEH4H3kw= +github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE= github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4= github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 h1:sDMmm+q/3+BukdIpxwO365v/Rbspp2Nt5XntgQRXq8Q= @@ -1132,8 +1134,8 @@ github.com/cri-o/ocicni v0.4.3 h1:BfnrZrtr/F+o+b+yOguB1o6I4OzjieF3k3dN4MrsCJA= github.com/cri-o/ocicni v0.4.3/go.mod h1:RzIKSln5AT65hyyfGj3/gsfCpjiY1Y6rVK51Uc5YNzk= github.com/csaf-poc/csaf_distribution/v3 v3.0.0 h1:ob9+Fmpff0YWgTP3dYaw7G2hKQ9cegh9l3zksc+q3sM= github.com/csaf-poc/csaf_distribution/v3 v3.0.0/go.mod h1:uilCTiNKivq+6zrDvjtZaUeLk70oe21iwKivo6ILwlQ= -github.com/cyphar/filepath-securejoin v0.3.0 h1:tXpmbiaeBrS/K2US8nhgwdKYnfAOnVfkcLPKFgFHeA0= -github.com/cyphar/filepath-securejoin v0.3.0/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc= +github.com/cyphar/filepath-securejoin v0.3.1 h1:1V7cHiaW+C+39wEfpH6XlLBQo3j/PciWFrgfCLS8XrE= +github.com/cyphar/filepath-securejoin v0.3.1/go.mod h1:F7i41x/9cBF7lzCrVsYs9fuzwRZm4NQsGTBdpp6mETc= github.com/datadog/trivy-db v0.0.0-20240228172000-42caffdaee3f h1:IFB3J+f0m2e7nZjPTqvzLrrb6dVU6BQrsGx/7Tmm8Xk= github.com/datadog/trivy-db v0.0.0-20240228172000-42caffdaee3f/go.mod h1:cj9/QmD9N3OZnKQMp+/DvdV+ym3HyIkd4e+F0ZM3ZGs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1424,8 +1426,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGw github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ= -github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= -github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4= +github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -3647,8 +3649,8 @@ google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5v google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= google.golang.org/grpc v1.54.0/go.mod h1:PUSEXI6iWghWaB6lXM4knEgpJNu2qUcKfDtNci3EC2g= google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= -google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= -google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/grpc/examples v0.0.0-20221020162917-9127159caf5a h1:p51n6zkL483uumoZhCSGtHCem9kDeU05G5jX/wYI9gw= google.golang.org/grpc/examples v0.0.0-20221020162917-9127159caf5a/go.mod h1:gxndsbNG1n4TZcHGgsYEfVGnTxqfEdfiDv6/DADXX9o= diff --git a/pkg/aggregator/check_sampler_bench_test.go b/pkg/aggregator/check_sampler_bench_test.go index 199f11cc446aa..71a32170b8575 100644 --- a/pkg/aggregator/check_sampler_bench_test.go +++ b/pkg/aggregator/check_sampler_bench_test.go @@ -12,7 +12,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" diff --git a/pkg/aggregator/demultiplexer_agent.go b/pkg/aggregator/demultiplexer_agent.go index 1512c756d86fe..0b237ea3ce719 100644 --- a/pkg/aggregator/demultiplexer_agent.go +++ b/pkg/aggregator/demultiplexer_agent.go @@ -12,7 +12,7 @@ import ( "sync" "time" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" forwarder "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" orchestratorforwarder "github.com/DataDog/datadog-agent/comp/forwarder/orchestrator" diff --git a/pkg/aggregator/demultiplexer_mock.go b/pkg/aggregator/demultiplexer_mock.go index c62836d9237c0..9bdd3dec2334d 100644 --- a/pkg/aggregator/demultiplexer_mock.go +++ b/pkg/aggregator/demultiplexer_mock.go @@ -11,7 +11,7 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" diff --git a/pkg/aggregator/demultiplexer_serverless.go b/pkg/aggregator/demultiplexer_serverless.go index bff61bdb5fdde..ce0bc1914e87b 100644 --- a/pkg/aggregator/demultiplexer_serverless.go +++ b/pkg/aggregator/demultiplexer_serverless.go @@ -10,8 +10,8 @@ import ( "sync" "time" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logimpl "github.com/DataDog/datadog-agent/comp/core/log/impl" forwarder "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/aggregator/internal/tags" @@ -43,8 +43,8 @@ type ServerlessDemultiplexer struct { // InitAndStartServerlessDemultiplexer creates and starts new Demultiplexer for the serverless agent. func InitAndStartServerlessDemultiplexer(keysPerDomain map[string][]string, forwarderTimeout time.Duration) *ServerlessDemultiplexer { bufferSize := config.Datadog().GetInt("aggregator_buffer_size") - log := logimpl.NewTemporaryLoggerWithoutInit() - forwarder := forwarder.NewSyncForwarder(config.Datadog(), log, keysPerDomain, forwarderTimeout) + logger := logimpl.NewTemporaryLoggerWithoutInit() + forwarder := forwarder.NewSyncForwarder(config.Datadog(), logger, keysPerDomain, forwarderTimeout) h, _ := hostname.Get(context.Background()) serializer := serializer.NewSerializer(forwarder, nil, compressionimpl.NewCompressor(config.Datadog()), config.Datadog(), h) metricSamplePool := metrics.NewMetricSamplePool(MetricSamplePoolBatchSize, utils.IsTelemetryEnabled(config.Datadog())) @@ -55,7 +55,7 @@ func InitAndStartServerlessDemultiplexer(keysPerDomain map[string][]string, forw statsdWorker := newTimeSamplerWorker(statsdSampler, DefaultFlushInterval, bufferSize, metricSamplePool, flushAndSerializeInParallel, tagsStore) demux := &ServerlessDemultiplexer{ - log: log, + log: logger, forwarder: forwarder, statsdSampler: statsdSampler, statsdWorker: statsdWorker, diff --git a/pkg/aggregator/mocksender/mocksender.go b/pkg/aggregator/mocksender/mocksender.go index 29db0d9e8f9ad..41e7514787d3d 100644 --- a/pkg/aggregator/mocksender/mocksender.go +++ b/pkg/aggregator/mocksender/mocksender.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logimpl "github.com/DataDog/datadog-agent/comp/core/log/impl" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" diff --git a/pkg/aggregator/sender_test.go b/pkg/aggregator/sender_test.go index a5e756dfffb2d..d9617143798b9 100644 --- a/pkg/aggregator/sender_test.go +++ b/pkg/aggregator/sender_test.go @@ -18,7 +18,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/hostname" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform" "github.com/DataDog/datadog-agent/comp/forwarder/eventplatform/eventplatformimpl" diff --git a/pkg/aggregator/test_common.go b/pkg/aggregator/test_common.go index 1c9231acd89c4..c7bfba146a245 100644 --- a/pkg/aggregator/test_common.go +++ b/pkg/aggregator/test_common.go @@ -10,7 +10,7 @@ package aggregator import ( "errors" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" diff --git a/pkg/cli/subcommands/check/command.go b/pkg/cli/subcommands/check/command.go index 5265f59228812..87187a52ec458 100644 --- a/pkg/cli/subcommands/check/command.go +++ b/pkg/cli/subcommands/check/command.go @@ -39,7 +39,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery/autodiscoveryimpl" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/settings" "github.com/DataDog/datadog-agent/comp/core/settings/settingsimpl" @@ -158,7 +158,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithConfigName(globalParams.ConfigName), config.WithExtraConfFiles(globalParams.ExtraConfFilePaths)), SecretParams: secrets.NewEnabledParams(), SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.SysProbeConfFilePath)), - LogParams: logimpl.ForOneShot(globalParams.LoggerName, "off", true)}), + LogParams: log.ForOneShot(globalParams.LoggerName, "off", true)}), core.Bundle(), // workloadmeta setup diff --git a/pkg/cli/subcommands/clusterchecks/command.go b/pkg/cli/subcommands/clusterchecks/command.go index 7e8d8ac436a28..e9785b5f8ea60 100644 --- a/pkg/cli/subcommands/clusterchecks/command.go +++ b/pkg/cli/subcommands/clusterchecks/command.go @@ -17,8 +17,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/clusteragent/clusterchecks/types" @@ -113,7 +112,7 @@ func bundleParams(globalParams GlobalParams) core.BundleParams { return core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(loggerName, defaultLogLevel, true), + LogParams: log.ForOneShot(loggerName, defaultLogLevel, true), } } diff --git a/pkg/cli/subcommands/config/command.go b/pkg/cli/subcommands/config/command.go index 9726fd641d20b..43fddc6471b39 100644 --- a/pkg/cli/subcommands/config/command.go +++ b/pkg/cli/subcommands/config/command.go @@ -13,8 +13,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/util" "github.com/DataDog/datadog-agent/pkg/config/settings" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -61,7 +60,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithConfigName(globalParams.ConfigName), config.WithExtraConfFiles(globalParams.ExtraConfFilePaths)), - LogParams: logimpl.ForOneShot(globalParams.LoggerName, "off", true)}), + LogParams: log.ForOneShot(globalParams.LoggerName, "off", true)}), core.Bundle(), ) } diff --git a/pkg/cli/subcommands/dcaconfigcheck/command.go b/pkg/cli/subcommands/dcaconfigcheck/command.go index f12d067bdf211..78125f8be3d52 100644 --- a/pkg/cli/subcommands/dcaconfigcheck/command.go +++ b/pkg/cli/subcommands/dcaconfigcheck/command.go @@ -15,8 +15,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/flare" "github.com/DataDog/datadog-agent/pkg/util/fxutil" ) @@ -50,7 +49,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), - LogParams: logimpl.ForOneShot("CLUSTER", "off", true), + LogParams: log.ForOneShot("CLUSTER", "off", true), }), core.Bundle(), ) diff --git a/pkg/cli/subcommands/dcaflare/command.go b/pkg/cli/subcommands/dcaflare/command.go index c3c824b87771c..448a3847df4a5 100644 --- a/pkg/cli/subcommands/dcaflare/command.go +++ b/pkg/cli/subcommands/dcaflare/command.go @@ -19,7 +19,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/flare/helpers" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/api/util" @@ -85,7 +85,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { fx.Supply(core.BundleParams{ ConfigParams: config.NewClusterAgentParams(globalParams.ConfFilePath), SecretParams: secrets.NewEnabledParams(), - LogParams: logimpl.ForOneShot(LoggerName, DefaultLogLevel, true), + LogParams: log.ForOneShot(LoggerName, DefaultLogLevel, true), }), core.Bundle(), compressionimpl.Module(), diff --git a/pkg/cli/subcommands/health/command.go b/pkg/cli/subcommands/health/command.go index 6d14f7978eb48..ced2015237df1 100644 --- a/pkg/cli/subcommands/health/command.go +++ b/pkg/cli/subcommands/health/command.go @@ -21,8 +21,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/status/health" @@ -59,7 +58,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { fx.Supply(cliParams), fx.Supply(core.BundleParams{ ConfigParams: config.NewAgentParams(globalParams.ConfFilePath, config.WithConfigName(globalParams.ConfigName), config.WithExtraConfFiles(globalParams.ExtraConfFilePaths)), - LogParams: logimpl.ForOneShot(globalParams.LoggerName, "off", true)}), + LogParams: log.ForOneShot(globalParams.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/pkg/cli/subcommands/taggerlist/command.go b/pkg/cli/subcommands/taggerlist/command.go index 996446a149a8c..0c3e5058ac07f 100644 --- a/pkg/cli/subcommands/taggerlist/command.go +++ b/pkg/cli/subcommands/taggerlist/command.go @@ -13,8 +13,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl/api" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -62,7 +61,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { config.WithConfigName(globalParams.ConfigName), config.WithExtraConfFiles(globalParams.ExtraConfFilePaths), ), - LogParams: logimpl.ForOneShot(globalParams.LoggerName, "off", true)}), + LogParams: log.ForOneShot(globalParams.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/pkg/cli/subcommands/workloadlist/command.go b/pkg/cli/subcommands/workloadlist/command.go index 0055fa305e7f7..fdcef5ee8710e 100644 --- a/pkg/cli/subcommands/workloadlist/command.go +++ b/pkg/cli/subcommands/workloadlist/command.go @@ -14,8 +14,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -65,7 +64,7 @@ func MakeCommand(globalParamsGetter func() GlobalParams) *cobra.Command { config.WithConfigName(globalParams.ConfigName), config.WithExtraConfFiles(globalParams.ExtraConfFilePaths), ), - LogParams: logimpl.ForOneShot(globalParams.LoggerName, "off", true)}), + LogParams: log.ForOneShot(globalParams.LoggerName, "off", true)}), core.Bundle(), ) }, diff --git a/pkg/clusteragent/admission/controllers/webhook/controller_base.go b/pkg/clusteragent/admission/controllers/webhook/controller_base.go index b11ed21e51c64..a2ad2983482bb 100644 --- a/pkg/clusteragent/admission/controllers/webhook/controller_base.go +++ b/pkg/clusteragent/admission/controllers/webhook/controller_base.go @@ -86,14 +86,19 @@ type MutatingWebhook interface { // by the config webhook doesn't always work on Fargate (one of the envs where // we use an agent sidecar), and the agent sidecar webhook needs to remove it. func mutatingWebhooks(wmeta workloadmeta.Component, pa workload.PodPatcher) []MutatingWebhook { + // Note: the auto_instrumentation pod injection filter is used across + // multiple mutating webhooks, so we add it as a hard dependency to each + // of the components that use it via the injectionFilter parameter. + injectionFilter := autoinstrumentation.GetInjectionFilter() + webhooks := []MutatingWebhook{ - config.NewWebhook(wmeta), - tagsfromlabels.NewWebhook(wmeta), + config.NewWebhook(wmeta, injectionFilter), + tagsfromlabels.NewWebhook(wmeta, injectionFilter), agentsidecar.NewWebhook(), autoscaling.NewWebhook(pa), } - apm, err := autoinstrumentation.GetWebhook(wmeta) + apm, err := autoinstrumentation.NewWebhook(wmeta, injectionFilter) if err == nil { webhooks = append(webhooks, apm) } else { diff --git a/pkg/clusteragent/admission/controllers/webhook/controller_v1_test.go b/pkg/clusteragent/admission/controllers/webhook/controller_v1_test.go index acccb26e40858..41a5b17220fe5 100644 --- a/pkg/clusteragent/admission/controllers/webhook/controller_v1_test.go +++ b/pkg/clusteragent/admission/controllers/webhook/controller_v1_test.go @@ -29,7 +29,6 @@ import ( configComp "github.com/DataDog/datadog-agent/comp/core/config" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" - "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/autoinstrumentation" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/cwsinstrumentation" "github.com/DataDog/datadog-agent/pkg/config" @@ -960,8 +959,6 @@ func TestGenerateTemplatesV1(t *testing.T) { mockConfig := configmock.New(t) mockConfig.SetWithoutSource("kube_resources_namespace", "nsfoo") tt.setupConfig(mockConfig) - autoinstrumentation.UnsetWebhook() // Ensure that the webhook uses the config set above - defer autoinstrumentation.UnsetWebhook() // So other tests are not impacted c := &ControllerV1{} c.config = tt.configFunc() diff --git a/pkg/clusteragent/admission/controllers/webhook/controller_v1beta1_test.go b/pkg/clusteragent/admission/controllers/webhook/controller_v1beta1_test.go index 4acac5014a96f..c35e0a86ce6fe 100644 --- a/pkg/clusteragent/admission/controllers/webhook/controller_v1beta1_test.go +++ b/pkg/clusteragent/admission/controllers/webhook/controller_v1beta1_test.go @@ -29,7 +29,6 @@ import ( configComp "github.com/DataDog/datadog-agent/comp/core/config" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" - "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/autoinstrumentation" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/cwsinstrumentation" "github.com/DataDog/datadog-agent/pkg/config" @@ -952,10 +951,7 @@ func TestGenerateTemplatesV1beta1(t *testing.T) { t.Run(tt.name, func(t *testing.T) { mockConfig := configmock.New(t) mockConfig.SetWithoutSource("kube_resources_namespace", "nsfoo") - tt.setupConfig(mockConfig) - autoinstrumentation.UnsetWebhook() // Ensure that the webhook uses the config set above - defer autoinstrumentation.UnsetWebhook() // So other tests are not impacted c := &ControllerV1beta1{} c.config = tt.configFunc() diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go index 462c4396ee521..b261079454656 100644 --- a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation.go @@ -17,7 +17,6 @@ import ( "slices" "strconv" "strings" - "sync" admiv1 "k8s.io/api/admissionregistration/v1" corev1 "k8s.io/api/core/v1" @@ -31,9 +30,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/metrics" mutatecommon "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" "github.com/DataDog/datadog-agent/pkg/config" - "github.com/DataDog/datadog-agent/pkg/util/containers" "github.com/DataDog/datadog-agent/pkg/util/kubernetes" - apiServerCommon "github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver/common" "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/pointer" ) @@ -142,16 +139,6 @@ var ( Name: instrumentationInstallTypeEnvVarName, Value: localLibraryInstrumentationInstallType, } - - // We need a global variable to store the APMInstrumentationWebhook instance - // because other webhooks depend on it. The "config" and the "tags" webhooks - // depend on the "auto_instrumentation" webhook to decide if a pod should be - // injected. They first check if the pod has the label to enable mutations. - // If it doesn't, they mutate the pod if the option to mutate unlabeled is - // set to true or if APM SSI is enabled in the namespace. - apmInstrumentationWebhook *Webhook - errInitAPMInstrumentation error - initOnce sync.Once ) func (l language) defaultLibInfo(registry, ctrName string) libInfo { @@ -177,103 +164,37 @@ type Webhook struct { endpoint string resources []string operations []admiv1.OperationType - filter *containers.Filter containerRegistry string + injectionFilter mutatecommon.InjectionFilter pinnedLibraries []libInfo wmeta workloadmeta.Component } -// NewWebhook returns a new Webhook -func NewWebhook(wmeta workloadmeta.Component) (*Webhook, error) { - filter, err := apmSSINamespaceFilter() - if err != nil { +// NewWebhook returns a new Webhook dependent on the injection filter. +func NewWebhook(wmeta workloadmeta.Component, filter mutatecommon.InjectionFilter) (*Webhook, error) { + // Note: the webhook is not functional with the filter being disabled-- + // and the filter is _global_! so we need to make sure that it was + // initialized as it validates the configuration itself. + if filter.NSFilter == nil { + return nil, errors.New("filter required for auto_instrumentation webhook") + } else if err := filter.NSFilter.Err(); err != nil { return nil, err } containerRegistry := mutatecommon.ContainerRegistry("admission_controller.auto_instrumentation.container_registry") - return &Webhook{ name: webhookName, isEnabled: config.Datadog().GetBool("admission_controller.auto_instrumentation.enabled"), endpoint: config.Datadog().GetString("admission_controller.auto_instrumentation.endpoint"), resources: []string{"pods"}, operations: []admiv1.OperationType{admiv1.Create}, - filter: filter, containerRegistry: containerRegistry, + injectionFilter: filter, pinnedLibraries: getPinnedLibraries(containerRegistry), wmeta: wmeta, }, nil } -// GetWebhook returns the Webhook instance, creating it if it doesn't exist -func GetWebhook(wmeta workloadmeta.Component) (*Webhook, error) { - initOnce.Do(func() { - if apmInstrumentationWebhook == nil { - apmInstrumentationWebhook, errInitAPMInstrumentation = NewWebhook(wmeta) - } - }) - - return apmInstrumentationWebhook, errInitAPMInstrumentation -} - -// UnsetWebhook unsets the webhook. For testing only. -func UnsetWebhook() { - initOnce = sync.Once{} - apmInstrumentationWebhook = nil - errInitAPMInstrumentation = nil -} - -// apmSSINamespaceFilter returns the filter used by APM SSI to filter namespaces. -// The filter excludes two namespaces by default: "kube-system" and the -// namespace where datadog is installed. -// Cases: -// - No enabled namespaces and no disabled namespaces: inject in all namespaces -// except the 2 namespaces excluded by default. -// - Enabled namespaces and no disabled namespaces: inject only in the -// namespaces specified in the list of enabled namespaces. If one of the -// namespaces excluded by default is included in the list, it will be injected. -// - Disabled namespaces and no enabled namespaces: inject only in the -// namespaces that are not included in the list of disabled namespaces and that -// are not one of the ones disabled by default. -// - Enabled and disabled namespaces: return error. -func apmSSINamespaceFilter() (*containers.Filter, error) { - apmEnabledNamespaces := config.Datadog().GetStringSlice("apm_config.instrumentation.enabled_namespaces") - apmDisabledNamespaces := config.Datadog().GetStringSlice("apm_config.instrumentation.disabled_namespaces") - - if len(apmEnabledNamespaces) > 0 && len(apmDisabledNamespaces) > 0 { - return nil, fmt.Errorf("apm.instrumentation.enabled_namespaces and apm.instrumentation.disabled_namespaces configuration cannot be set together") - } - - // Prefix the namespaces as needed by the containers.Filter. - prefix := containers.KubeNamespaceFilterPrefix - apmEnabledNamespacesWithPrefix := make([]string, len(apmEnabledNamespaces)) - apmDisabledNamespacesWithPrefix := make([]string, len(apmDisabledNamespaces)) - - for i := range apmEnabledNamespaces { - apmEnabledNamespacesWithPrefix[i] = prefix + fmt.Sprintf("^%s$", apmEnabledNamespaces[i]) - } - for i := range apmDisabledNamespaces { - apmDisabledNamespacesWithPrefix[i] = prefix + fmt.Sprintf("^%s$", apmDisabledNamespaces[i]) - } - - disabledByDefault := []string{ - prefix + "^kube-system$", - prefix + fmt.Sprintf("^%s$", apiServerCommon.GetResourcesNamespace()), - } - - var filterExcludeList []string - if len(apmEnabledNamespacesWithPrefix) > 0 && len(apmDisabledNamespacesWithPrefix) == 0 { - // In this case, we want to include only the namespaces in the enabled list. - // In the containers.Filter, the include list is checked before the - // exclude list, that's why we set the exclude list to all namespaces. - filterExcludeList = []string{prefix + ".*"} - } else { - filterExcludeList = append(apmDisabledNamespacesWithPrefix, disabledByDefault...) - } - - return containers.NewFilter(containers.GlobalFilter, apmEnabledNamespacesWithPrefix, filterExcludeList) -} - // Name returns the name of the webhook func (w *Webhook) Name() string { return w.name @@ -327,18 +248,11 @@ func libImageName(registry string, lang language, tag string) string { } func (w *Webhook) isPodEligible(pod *corev1.Pod) bool { - if w.isEnabledInNamespace(pod.Namespace) { - // if Single Step Instrumentation is enabled, pods can still opt out using the label - if pod.GetLabels()[common.EnabledLabelKey] == "false" { - log.Debugf("Skipping single step instrumentation of pod %q due to label", mutatecommon.PodString(pod)) - return false - } - } else if !mutatecommon.ShouldMutatePod(pod) { - log.Debugf("Skipping auto instrumentation of pod %q because pod mutation is not allowed", mutatecommon.PodString(pod)) - return false - } + return w.injectionFilter.ShouldMutatePod(pod) +} - return true +func (w *Webhook) isEnabledInNamespace(namespace string) bool { + return w.injectionFilter.NSFilter.IsNamespaceEligible(namespace) } func (w *Webhook) inject(pod *corev1.Pod, ns string, _ dynamic.Interface) (bool, error) { @@ -353,9 +267,10 @@ func (w *Webhook) inject(pod *corev1.Pod, ns string, _ dynamic.Interface) (bool, if !w.isPodEligible(pod) { return false, nil } + for _, lang := range supportedLanguages { if containsInitContainer(pod, initContainerName(lang)) { - // The admission can be reinvocated for the same pod + // The admission can be re-run for the same pod // Fast return if we injected the library already log.Debugf("Init container %q already exists in pod %q", initContainerName(lang), mutatecommon.PodString(pod)) return false, nil @@ -500,7 +415,9 @@ type libInfo struct { // and a boolean indicating whether the library should be injected into the pod func (w *Webhook) extractLibInfo(pod *corev1.Pod) ([]libInfo, bool) { // If the pod is "injectable" and annotated with libraries to inject, use those. - if ShouldInject(pod, w.wmeta) { + if w.isPodEligible(pod) { + // The library version specified via annotation on the Pod takes precedence + // over libraries injected with Single Step Instrumentation libs := w.extractLibrariesFromAnnotations(pod) if len(libs) > 0 { return libs, false @@ -613,41 +530,6 @@ func (w *Webhook) extractLibrariesFromAnnotations(pod *corev1.Pod) []libInfo { return libList } -// ShouldInject returns true if Admission Controller should inject standard tags, APM configs and APM libraries -func ShouldInject(pod *corev1.Pod, wmeta workloadmeta.Component) bool { - // If a pod explicitly sets the label admission.datadoghq.com/enabled, make a decision based on its value - if val, found := pod.GetLabels()[common.EnabledLabelKey]; found { - switch val { - case "true": - return true - case "false": - return false - default: - log.Warnf("Invalid label value '%s=%s' on pod %s should be either 'true' or 'false', ignoring it", common.EnabledLabelKey, val, mutatecommon.PodString(pod)) - } - } - - apmWebhook, err := GetWebhook(wmeta) - if err != nil { - return config.Datadog().GetBool("admission_controller.mutate_unlabelled") - } - - return apmWebhook.isEnabledInNamespace(pod.Namespace) || config.Datadog().GetBool("admission_controller.mutate_unlabelled") -} - -// isEnabledInNamespace indicates if Single Step Instrumentation is enabled for -// the namespace in the cluster -func (w *Webhook) isEnabledInNamespace(namespace string) bool { - apmInstrumentationEnabled := config.Datadog().GetBool("apm_config.instrumentation.enabled") - - if !apmInstrumentationEnabled { - log.Debugf("APM Instrumentation is disabled") - return false - } - - return !w.filter.IsExcluded(nil, "", "", namespace) -} - func (w *Webhook) injectAutoInstruConfig(pod *corev1.Pod, libsToInject []libInfo, autoDetected bool, injectionType string) error { var lastError error diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go index 713811370845d..f521da70fee5a 100644 --- a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_test.go @@ -29,7 +29,7 @@ import ( workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" configmock "github.com/DataDog/datadog-agent/pkg/config/mock" - model "github.com/DataDog/datadog-agent/pkg/config/model" + "github.com/DataDog/datadog-agent/pkg/config/model" "github.com/DataDog/datadog-agent/pkg/languagedetection/util" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/pointer" @@ -246,19 +246,18 @@ func TestInjectAutoInstruConfig(t *testing.T) { wmeta := fxutil.Test[workloadmeta.Component](t, core.MockBundle(), workloadmetafxmock.MockModule(), fx.Supply(workloadmeta.NewParams())) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - webhook, err := GetWebhook(wmeta) - require.NoError(t, err) - - err = webhook.injectAutoInstruConfig(tt.pod, tt.libsToInject, false, "") + webhook := mustWebhook(t, wmeta) + err := webhook.injectAutoInstruConfig(tt.pod, tt.libsToInject, false, "") if tt.wantErr { - require.Error(t, err) + require.Error(t, err, "expected injectAutoInstruConfig to error") } else { - require.NoError(t, err) + require.NoError(t, err, "expected injectAutoInstruConfig to succeed") } if err != nil { return } + assertLibReq(t, tt.pod, tt.libsToInject[0].lang, tt.libsToInject[0].image, tt.expectedEnvKey, tt.expectedEnvVal) }) } @@ -543,6 +542,35 @@ func TestExtractLibInfo(t *testing.T) { mockConfig.SetWithoutSource("admission_controller.mutate_unlabelled", false) }, }, + { + name: "all with mutate_unlabelled off", + pod: common.FakePodWithAnnotation("admission.datadoghq.com/all-lib.version", "latest"), + containerRegistry: "registry", + expectedPodEligible: pointer.Ptr(false), + expectedLibsToInject: allLatestLibs, + setupConfig: func() { + mockConfig.SetWithoutSource("admission_controller.mutate_unlabelled", false) + }, + }, + { + name: "all with mutate_unlabelled off, but labelled admission enabled", + pod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + "admission.datadoghq.com/all-lib.version": "latest", + }, + Labels: map[string]string{ + "admission.datadoghq.com/enabled": "true", + }, + }, + }, + containerRegistry: "registry", + expectedPodEligible: pointer.Ptr(true), + expectedLibsToInject: allLatestLibs, + setupConfig: func() { + mockConfig.SetWithoutSource("admission_controller.mutate_unlabelled", false) + }, + }, { name: "java + all", pod: &corev1.Pod{ @@ -628,8 +656,8 @@ func TestExtractLibInfo(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // Fix me: since comp-config and pkg-config don't work together yet we have to set settings - // twice + // Fix me: since comp-config and pkg-config don't work together, + // we have to set settings twice overrides := map[string]interface{}{ "admission_controller.mutate_unlabelled": true, "admission_controller.container_registry": commonRegistry, @@ -653,17 +681,13 @@ func TestExtractLibInfo(t *testing.T) { tt.setupConfig() } - // Need to create a new instance of the webhook to take into account - // the config changes. - UnsetWebhook() - apmInstrumentationWebhook, errInitAPMInstrumentation := GetWebhook(wmeta) - require.NoError(t, errInitAPMInstrumentation) + webhook := mustWebhook(t, wmeta) if tt.expectedPodEligible != nil { - require.Equal(t, *tt.expectedPodEligible, apmInstrumentationWebhook.isPodEligible(tt.pod)) + require.Equal(t, *tt.expectedPodEligible, webhook.isPodEligible(tt.pod)) } - libsToInject, _ := apmInstrumentationWebhook.extractLibInfo(tt.pod) + libsToInject, _ := webhook.extractLibInfo(tt.pod) require.ElementsMatch(t, tt.expectedLibsToInject, libsToInject) }) } @@ -2159,13 +2183,9 @@ func TestInjectAutoInstrumentation(t *testing.T) { } } - // Need to create a new instance of the webhook to take into account - // the config changes. - UnsetWebhook() - apmInstrumentationWebhook, errInitAPMInstrumentation := GetWebhook(wmeta) - require.NoError(t, errInitAPMInstrumentation) + webhook := mustWebhook(t, wmeta) - _, err := apmInstrumentationWebhook.inject(tt.pod, "", fake.NewSimpleDynamicClient(scheme.Scheme)) + _, err := webhook.inject(tt.pod, "", fake.NewSimpleDynamicClient(scheme.Scheme)) require.False(t, (err != nil) != tt.wantErr) container := tt.pod.Spec.Containers[0] @@ -2407,18 +2427,18 @@ func TestShouldInject(t *testing.T) { mockConfig = configmock.New(t) tt.setupConfig() - // Need to create a new instance of the webhook to take into account - // the config changes. - UnsetWebhook() - webhook, errInitAPMInstrumentation := GetWebhook(wmeta) - require.NoError(t, errInitAPMInstrumentation) - - require.Equal(t, tt.want, ShouldInject(tt.pod, webhook.wmeta), "expected ShouldInject() to be %t", tt.want) + webhook := mustWebhook(t, wmeta) require.Equal(t, tt.want, webhook.isPodEligible(tt.pod), "expected webhook.isPodEligible() to be %t", tt.want) }) } } +func mustWebhook(t *testing.T, wmeta workloadmeta.Component) *Webhook { + webhook, err := NewWebhook(wmeta, GetInjectionFilter()) + require.NoError(t, err) + return webhook +} + func languageSetOf(languages ...string) util.LanguageSet { set := util.LanguageSet{} for _, l := range languages { diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_util_test.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_util_test.go index 772f67d91277d..4edd5cf713379 100644 --- a/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_util_test.go +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/auto_instrumentation_util_test.go @@ -16,7 +16,8 @@ import ( corev1 "k8s.io/api/core/v1" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -86,7 +87,7 @@ func assertEqualLibInjection(actualLibs []libInfo, expectedLibs []libInfo) bool func TestGetLibListFromDeploymentAnnotations(t *testing.T) { mockStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/injection_filter.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/injection_filter.go new file mode 100644 index 0000000000000..8f2c542e72705 --- /dev/null +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/injection_filter.go @@ -0,0 +1,123 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build kubeapiserver + +package autoinstrumentation + +import ( + "fmt" + + mutatecommon "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" + "github.com/DataDog/datadog-agent/pkg/config" + "github.com/DataDog/datadog-agent/pkg/util/containers" + apiServerCommon "github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver/common" + "github.com/DataDog/datadog-agent/pkg/util/log" +) + +// GetNamespaceInjectionFilter is an accessor for the NamespaceInjectionFilter +func GetNamespaceInjectionFilter() mutatecommon.NamespaceInjectionFilter { + filter, err := makeAPMSSINamespaceFilter() + return &injectionFilter{filter: filter, err: err} +} + +// GetInjectionFilter constructs an injection filter using the autoinstrumentation +// GetNamespaceInjectionFilter. +func GetInjectionFilter() mutatecommon.InjectionFilter { + return mutatecommon.InjectionFilter{ + NSFilter: GetNamespaceInjectionFilter(), + } +} + +type injectionFilter struct { + filter *containers.Filter + err error +} + +// IsNamespaceEligible returns true of APM Single Step Instrumentation +// is enabled and enabled for this namespace. +// +// There could be an error in configuration which would imply that +// APM is disabled. +// +// This DOES NOT respect `mutate_unlabelled` since it is a namespace +// specific check. +func (f *injectionFilter) IsNamespaceEligible(ns string) bool { + apmInstrumentationEnabled := config.Datadog().GetBool("apm_config.instrumentation.enabled") + + if !apmInstrumentationEnabled { + log.Debugf("APM Instrumentation is disabled") + return false + } + + if f.err != nil { + return false + } + + if f.filter == nil { + return false + } + + return !f.filter.IsExcluded(nil, "", "", ns) +} + +// Err returns an error if the namespace filter failed to initialize. +// +// This is safe to ignore for most uses, except for in auto_instrumentation itself. +func (f *injectionFilter) Err() error { + return f.err +} + +// makeAPMSSINamespaceFilter returns the filter used by APM SSI to filter namespaces. +// The filter excludes two namespaces by default: "kube-system" and the +// namespace where datadog is installed. +// +// Cases: +// - No enabled namespaces and no disabled namespaces: inject in all namespaces +// except the 2 namespaces excluded by default. +// - Enabled namespaces and no disabled namespaces: inject only in the +// namespaces specified in the list of enabled namespaces. If one of the +// namespaces excluded by default is included in the list, it will be injected. +// - Disabled namespaces and no enabled namespaces: inject only in the +// namespaces that are not included in the list of disabled namespaces and that +// are not one of the ones disabled by default. +// - Enabled and disabled namespaces: return error. +func makeAPMSSINamespaceFilter() (*containers.Filter, error) { + apmEnabledNamespaces := config.Datadog().GetStringSlice("apm_config.instrumentation.enabled_namespaces") + apmDisabledNamespaces := config.Datadog().GetStringSlice("apm_config.instrumentation.disabled_namespaces") + + if len(apmEnabledNamespaces) > 0 && len(apmDisabledNamespaces) > 0 { + return nil, fmt.Errorf("apm.instrumentation.enabled_namespaces and apm.instrumentation.disabled_namespaces configuration cannot be set together") + } + + // Prefix the namespaces as needed by the containers.Filter. + prefix := containers.KubeNamespaceFilterPrefix + apmEnabledNamespacesWithPrefix := make([]string, len(apmEnabledNamespaces)) + apmDisabledNamespacesWithPrefix := make([]string, len(apmDisabledNamespaces)) + + for i := range apmEnabledNamespaces { + apmEnabledNamespacesWithPrefix[i] = prefix + fmt.Sprintf("^%s$", apmEnabledNamespaces[i]) + } + for i := range apmDisabledNamespaces { + apmDisabledNamespacesWithPrefix[i] = prefix + fmt.Sprintf("^%s$", apmDisabledNamespaces[i]) + } + + disabledByDefault := []string{ + prefix + "^kube-system$", + prefix + fmt.Sprintf("^%s$", apiServerCommon.GetResourcesNamespace()), + } + + var filterExcludeList []string + if len(apmEnabledNamespacesWithPrefix) > 0 && len(apmDisabledNamespacesWithPrefix) == 0 { + // In this case, we want to include only the namespaces in the enabled list. + // In the containers.Filter, the include list is checked before the + // exclude list, that's why we set the exclude list to all namespaces. + filterExcludeList = []string{prefix + ".*"} + } else { + filterExcludeList = append(apmDisabledNamespacesWithPrefix, disabledByDefault...) + } + + return containers.NewFilter(containers.GlobalFilter, apmEnabledNamespacesWithPrefix, filterExcludeList) +} diff --git a/pkg/clusteragent/admission/mutate/autoinstrumentation/injection_filter_test.go b/pkg/clusteragent/admission/mutate/autoinstrumentation/injection_filter_test.go new file mode 100644 index 0000000000000..85b0ad4a06be1 --- /dev/null +++ b/pkg/clusteragent/admission/mutate/autoinstrumentation/injection_filter_test.go @@ -0,0 +1,108 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build kubeapiserver + +package autoinstrumentation + +import ( + "testing" + + "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" + mockconfig "github.com/DataDog/datadog-agent/pkg/config/mock" + "github.com/stretchr/testify/require" +) + +func TestFailingInjectionConfig(t *testing.T) { + tests := []struct { + name string + + instrumentationEnabled bool + enabledNamespaces, disabledNamespaces []string + + expectedFilterError, expectedWebhookError bool + expectedNamespaces map[string]bool + }{ + { + name: "disabled", + expectedNamespaces: map[string]bool{ + "enabled-ns": false, + "disabled-ns": false, + "any-other-ns": false, + }, + }, + { + name: "enabled no namespaces", + instrumentationEnabled: true, + expectedNamespaces: map[string]bool{ + "enabled-ns": true, + "disabled-ns": true, + "any-other-ns": true, + }, + }, + { + name: "enabled with enabled namespace", + instrumentationEnabled: true, + enabledNamespaces: []string{"enabled-ns"}, + expectedNamespaces: map[string]bool{ + "enabled-ns": true, + "disabled-ns": false, + "any-other-ns": false, + }, + }, + { + name: "enabled with disabled namespace", + instrumentationEnabled: true, + disabledNamespaces: []string{"disabled-ns"}, + expectedNamespaces: map[string]bool{ + "enabled-ns": true, + "disabled-ns": false, + "any-other-ns": true, + }, + }, + { + name: "both enabled and disabled errors, fail closed", + instrumentationEnabled: true, + enabledNamespaces: []string{"enabled-ns"}, + disabledNamespaces: []string{"disabled-ns"}, + expectedFilterError: true, + expectedWebhookError: true, + expectedNamespaces: map[string]bool{ + "enabled-ns": false, + "disabled-ns": false, + "any-other-ns": false, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + + wmeta := common.FakeStoreWithDeployment(t, nil) + + c := mockconfig.New(t) + c.SetWithoutSource("apm_config.instrumentation.enabled", tt.instrumentationEnabled) + c.SetWithoutSource("apm_config.instrumentation.enabled_namespaces", tt.enabledNamespaces) + c.SetWithoutSource("apm_config.instrumentation.disabled_namespaces", tt.disabledNamespaces) + + nsFilter := GetNamespaceInjectionFilter() + require.NotNil(t, nsFilter, "we should always get a filter") + + _, err := NewWebhook(wmeta, common.InjectionFilter{NSFilter: nsFilter}) + if tt.expectedWebhookError { + require.Error(t, err) + } else { + require.NoError(t, err) + } + + checkedNamespaces := map[string]bool{} + for ns := range tt.expectedNamespaces { + checkedNamespaces[ns] = nsFilter.IsNamespaceEligible(ns) + } + + require.Equal(t, tt.expectedNamespaces, checkedNamespaces) + }) + } +} diff --git a/pkg/clusteragent/admission/mutate/common/common.go b/pkg/clusteragent/admission/mutate/common/common.go index 2279ac9c44f6d..7ecdab49ab2ec 100644 --- a/pkg/clusteragent/admission/mutate/common/common.go +++ b/pkg/clusteragent/admission/mutate/common/common.go @@ -164,27 +164,34 @@ func containsVolumeMount(volumeMounts []corev1.VolumeMount, element corev1.Volum return false } -// ShouldMutatePod returns true if Admission Controller is allowed to mutate the pod -// via pod label or mutateUnlabelled configuration -func ShouldMutatePod(pod *corev1.Pod) bool { - // If a pod explicitly sets the label admission.datadoghq.com/enabled, make a decision based on its value +// ShouldMutateUnlabelledPods returns true if we should mutate unlabelled pods. +func ShouldMutateUnlabelledPods() bool { + return config.Datadog().GetBool("admission_controller.mutate_unlabelled") +} + +// IsExplicitPodMutationEnabled returns true if the pod mutation is opted into +// by a pod label. It returns a second bool to show whether or not the value was +// specified or not in the first place. +func IsExplicitPodMutationEnabled(pod *corev1.Pod) (bool, bool) { + // If a pod explicitly sets the label admission.datadoghq.com/enabled, + // make a decision based on its value. if val, found := pod.GetLabels()[admCommon.EnabledLabelKey]; found { switch val { case "true": - return true + return true, true case "false": - return false + return false, true default: log.Warnf("Invalid label value '%s=%s' on pod %s should be either 'true' or 'false', ignoring it", admCommon.EnabledLabelKey, val, PodString(pod)) } } - return config.Datadog().GetBool("admission_controller.mutate_unlabelled") + return false, false } // ContainerRegistry gets the container registry config using the specified -// config option, and falls back to the default container registry if no webhook- -// specific container registry is set. +// config option, and falls back to the default container registry if no +// webhook-specific container registry is set. func ContainerRegistry(specificConfigOpt string) string { if config.Datadog().IsSet(specificConfigOpt) { return config.Datadog().GetString(specificConfigOpt) diff --git a/pkg/clusteragent/admission/mutate/common/ns_injection_filter.go b/pkg/clusteragent/admission/mutate/common/ns_injection_filter.go new file mode 100644 index 0000000000000..5925e79708abc --- /dev/null +++ b/pkg/clusteragent/admission/mutate/common/ns_injection_filter.go @@ -0,0 +1,47 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//go:build kubeapiserver + +package common + +import ( + corev1 "k8s.io/api/core/v1" +) + +// InjectionFilter encapsulates the logic for deciding whether +// we can do pod mutation based on a NSFilter (NamespaceInjectionFilter). +// See: InjectionFilter.ShouldMutatePod. +type InjectionFilter struct { + NSFilter NamespaceInjectionFilter +} + +// ShouldMutatePod checks if a pod is mutable per explicit rules and +// the NSFilter if InjectionFilter has one. +func (f InjectionFilter) ShouldMutatePod(pod *corev1.Pod) bool { + if val, ok := IsExplicitPodMutationEnabled(pod); ok { + return val + } + + if f.NSFilter != nil && f.NSFilter.IsNamespaceEligible(pod.Namespace) { + return true + } + + return ShouldMutateUnlabelledPods() +} + +// NamespaceInjectionFilter represents a contract to be able to filter out which pods are +// eligible for mutation/injection. +// +// This exists to separate the direct implementation in the autoinstrumentation package and +// its dependencies in other webhooks. +// +// See autoinstrumentation.GetInjectionFilter. +type NamespaceInjectionFilter interface { + // IsNamespaceEligible returns true if a namespace is eligible for injection/mutation. + IsNamespaceEligible(ns string) bool + // Err returns an error if creation of the NamespaceInjectionFilter failed. + Err() error +} diff --git a/pkg/clusteragent/admission/mutate/common/test_utils.go b/pkg/clusteragent/admission/mutate/common/test_utils.go index 62f66d16762bf..25c17414abeb6 100644 --- a/pkg/clusteragent/admission/mutate/common/test_utils.go +++ b/pkg/clusteragent/admission/mutate/common/test_utils.go @@ -19,7 +19,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" coreconfig "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -234,7 +235,7 @@ type MockDeployment struct { // deployments func FakeStoreWithDeployment(t *testing.T, deployments []MockDeployment) workloadmeta.Component { mockStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), coreconfig.MockModule(), fx.Supply(workloadmeta.NewParams()), fx.Supply(context.Background()), diff --git a/pkg/clusteragent/admission/mutate/config/config.go b/pkg/clusteragent/admission/mutate/config/config.go index c8b4fce9461c5..f8a6843478fa7 100644 --- a/pkg/clusteragent/admission/mutate/config/config.go +++ b/pkg/clusteragent/admission/mutate/config/config.go @@ -24,7 +24,6 @@ import ( workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" admCommon "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/common" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/metrics" - "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/autoinstrumentation" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" "github.com/DataDog/datadog-agent/pkg/config" apiCommon "github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver/common" @@ -102,29 +101,31 @@ type conf struct { // Webhook is the webhook that injects DD_AGENT_HOST and DD_ENTITY_ID into a pod type Webhook struct { - name string - config conf - isEnabled bool - endpoint string - resources []string - operations []admiv1.OperationType - mode string - wmeta workloadmeta.Component + name string + config conf + isEnabled bool + endpoint string + resources []string + operations []admiv1.OperationType + mode string + wmeta workloadmeta.Component + injectionFilter common.InjectionFilter } // NewWebhook returns a new Webhook -func NewWebhook(wmeta workloadmeta.Component) *Webhook { +func NewWebhook(wmeta workloadmeta.Component, injectionFilter common.InjectionFilter) *Webhook { return &Webhook{ name: webhookName, config: conf{ injectContName: config.Datadog().GetBool("admission_controller.inject_config.inject_container_name"), }, - isEnabled: config.Datadog().GetBool("admission_controller.inject_config.enabled"), - endpoint: config.Datadog().GetString("admission_controller.inject_config.endpoint"), - resources: []string{"pods"}, - operations: []admiv1.OperationType{admiv1.Create}, - mode: config.Datadog().GetString("admission_controller.inject_config.mode"), - wmeta: wmeta, + isEnabled: config.Datadog().GetBool("admission_controller.inject_config.enabled"), + endpoint: config.Datadog().GetString("admission_controller.inject_config.endpoint"), + resources: []string{"pods"}, + operations: []admiv1.OperationType{admiv1.Create}, + mode: config.Datadog().GetString("admission_controller.inject_config.mode"), + wmeta: wmeta, + injectionFilter: injectionFilter, } } @@ -182,7 +183,7 @@ func (w *Webhook) inject(pod *corev1.Pod, _ string, _ dynamic.Interface) (bool, return false, errors.New(metrics.InvalidInput) } - if !autoinstrumentation.ShouldInject(pod, w.wmeta) { + if !w.injectionFilter.ShouldMutatePod(pod) { return false, nil } diff --git a/pkg/clusteragent/admission/mutate/config/config_test.go b/pkg/clusteragent/admission/mutate/config/config_test.go index 6c965101737ca..adca611abf7eb 100644 --- a/pkg/clusteragent/admission/mutate/config/config_test.go +++ b/pkg/clusteragent/admission/mutate/config/config_test.go @@ -26,6 +26,7 @@ import ( workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" admCommon "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/common" + "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/autoinstrumentation" mutatecommon "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" "github.com/DataDog/datadog-agent/pkg/util/fxutil" "github.com/DataDog/datadog-agent/pkg/util/kubernetes/apiserver/common" @@ -75,7 +76,7 @@ func TestInjectHostIP(t *testing.T) { pod := mutatecommon.FakePodWithContainer("foo-pod", corev1.Container{}) pod = mutatecommon.WithLabels(pod, map[string]string{"admission.datadoghq.com/enabled": "true"}) wmeta := fxutil.Test[workloadmeta.Component](t, core.MockBundle(), workloadmetafxmock.MockModule(), fx.Supply(workloadmeta.NewParams())) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) injected, err := webhook.inject(pod, "", nil) assert.Nil(t, err) assert.True(t, injected) @@ -86,7 +87,7 @@ func TestInjectService(t *testing.T) { pod := mutatecommon.FakePodWithContainer("foo-pod", corev1.Container{}) pod = mutatecommon.WithLabels(pod, map[string]string{"admission.datadoghq.com/enabled": "true", "admission.datadoghq.com/config.mode": "service"}) wmeta := fxutil.Test[workloadmeta.Component](t, core.MockBundle(), workloadmetafxmock.MockModule(), fx.Supply(workloadmeta.NewParams())) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) injected, err := webhook.inject(pod, "", nil) assert.Nil(t, err) assert.True(t, injected) @@ -123,7 +124,7 @@ func TestInjectEntityID(t *testing.T) { fx.Supply(workloadmeta.NewParams()), fx.Replace(config.MockParams{Overrides: tt.configOverrides}), ) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) injected, err := webhook.inject(pod, "", nil) assert.Nil(t, err) assert.True(t, injected) @@ -404,7 +405,7 @@ func TestInjectSocket(t *testing.T) { pod := mutatecommon.FakePodWithContainer("foo-pod", corev1.Container{}) pod = mutatecommon.WithLabels(pod, map[string]string{"admission.datadoghq.com/enabled": "true", "admission.datadoghq.com/config.mode": "socket"}) wmeta := fxutil.Test[workloadmeta.Component](t, core.MockBundle(), workloadmetafxmock.MockModule(), fx.Supply(workloadmeta.NewParams())) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) injected, err := webhook.inject(pod, "", nil) assert.Nil(t, err) assert.True(t, injected) @@ -459,7 +460,7 @@ func TestInjectSocketWithConflictingVolumeAndInitContainer(t *testing.T) { } wmeta := fxutil.Test[workloadmeta.Component](t, core.MockBundle(), workloadmetafxmock.MockModule(), fx.Supply(workloadmeta.NewParams())) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) injected, err := webhook.inject(pod, "", nil) assert.True(t, injected) assert.Nil(t, err) @@ -502,7 +503,7 @@ func TestJSONPatchCorrectness(t *testing.T) { fx.Supply(workloadmeta.NewParams()), fx.Replace(config.MockParams{Overrides: tt.overrides}), ) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) request := admission.MutateRequest{ Raw: podJSON, Namespace: "bar", @@ -533,7 +534,7 @@ func BenchmarkJSONPatch(b *testing.B) { } wmeta := fxutil.Test[workloadmeta.Component](b, core.MockBundle()) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) podJSON := obj.(*admiv1.AdmissionReview).Request.Object.Raw b.ResetTimer() diff --git a/pkg/clusteragent/admission/mutate/tagsfromlabels/tags.go b/pkg/clusteragent/admission/mutate/tagsfromlabels/tags.go index aeeaed6187fb7..b48138d2d2ed0 100644 --- a/pkg/clusteragent/admission/mutate/tagsfromlabels/tags.go +++ b/pkg/clusteragent/admission/mutate/tagsfromlabels/tags.go @@ -25,7 +25,6 @@ import ( "github.com/DataDog/datadog-agent/cmd/cluster-agent/admission" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/metrics" - "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/autoinstrumentation" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/util/cache" @@ -43,25 +42,27 @@ const webhookName = "standard_tags" // Webhook is the webhook that injects DD_ENV, DD_VERSION, DD_SERVICE env vars type Webhook struct { - name string - isEnabled bool - endpoint string - resources []string - operations []admiv1.OperationType - ownerCacheTTL time.Duration - wmeta workloadmeta.Component + name string + isEnabled bool + endpoint string + resources []string + operations []admiv1.OperationType + ownerCacheTTL time.Duration + wmeta workloadmeta.Component + injectionFilter common.InjectionFilter } // NewWebhook returns a new Webhook -func NewWebhook(wmeta workloadmeta.Component) *Webhook { +func NewWebhook(wmeta workloadmeta.Component, injectionFilter common.InjectionFilter) *Webhook { return &Webhook{ - name: webhookName, - isEnabled: config.Datadog().GetBool("admission_controller.inject_tags.enabled"), - endpoint: config.Datadog().GetString("admission_controller.inject_tags.endpoint"), - resources: []string{"pods"}, - operations: []admiv1.OperationType{admiv1.Create}, - ownerCacheTTL: ownerCacheTTL(), - wmeta: wmeta, + name: webhookName, + isEnabled: config.Datadog().GetBool("admission_controller.inject_tags.enabled"), + endpoint: config.Datadog().GetString("admission_controller.inject_tags.endpoint"), + resources: []string{"pods"}, + operations: []admiv1.OperationType{admiv1.Create}, + ownerCacheTTL: ownerCacheTTL(), + wmeta: wmeta, + injectionFilter: injectionFilter, } } @@ -139,8 +140,9 @@ func (w *Webhook) injectTags(pod *corev1.Pod, ns string, dc dynamic.Interface) ( return false, errors.New(metrics.InvalidInput) } - if !autoinstrumentation.ShouldInject(pod, w.wmeta) { - // Ignore pod if it has the label admission.datadoghq.com/enabled=false or Single step configuration is disabled + if !w.injectionFilter.ShouldMutatePod(pod) { + // Ignore pod if it has the label admission.datadoghq.com/enabled=false + // or Single step configuration is disabled return false, nil } diff --git a/pkg/clusteragent/admission/mutate/tagsfromlabels/tags_test.go b/pkg/clusteragent/admission/mutate/tagsfromlabels/tags_test.go index a84f03157090b..40b75c805e533 100644 --- a/pkg/clusteragent/admission/mutate/tagsfromlabels/tags_test.go +++ b/pkg/clusteragent/admission/mutate/tagsfromlabels/tags_test.go @@ -23,6 +23,7 @@ import ( "github.com/DataDog/datadog-agent/comp/core" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" + "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/autoinstrumentation" "github.com/DataDog/datadog-agent/pkg/clusteragent/admission/mutate/common" "github.com/DataDog/datadog-agent/pkg/util/cache" "github.com/DataDog/datadog-agent/pkg/util/fxutil" @@ -173,7 +174,7 @@ func Test_injectTags(t *testing.T) { wmeta := fxutil.Test[workloadmeta.Component](t, core.MockBundle(), workloadmetafxmock.MockModule(), fx.Supply(workloadmeta.NewParams())) for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) _, err := webhook.injectTags(tt.pod, "ns", nil) assert.NoError(t, err) assert.Len(t, tt.pod.Spec.Containers, 1) @@ -273,7 +274,7 @@ func TestGetAndCacheOwner(t *testing.T) { kubeObj := newUnstructuredWithSpec(map[string]interface{}{"foo": "bar"}) owner := newOwner(kubeObj) wmeta := fxutil.Test[workloadmeta.Component](t, core.MockBundle(), workloadmetafxmock.MockModule(), fx.Supply(workloadmeta.NewParams())) - webhook := NewWebhook(wmeta) + webhook := NewWebhook(wmeta, autoinstrumentation.GetInjectionFilter()) // Cache hit cache.Cache.Set(ownerInfo.buildID(testNamespace), owner, webhook.ownerCacheTTL) diff --git a/pkg/clusteragent/autoscaling/workload/pod_watcher_test.go b/pkg/clusteragent/autoscaling/workload/pod_watcher_test.go index 03d9f725f6437..5139cb8b1ac9e 100644 --- a/pkg/clusteragent/autoscaling/workload/pod_watcher_test.go +++ b/pkg/clusteragent/autoscaling/workload/pod_watcher_test.go @@ -13,7 +13,8 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -91,7 +92,7 @@ func TestHandleUnsetEvent(t *testing.T) { func TestPodWatcherStartStop(t *testing.T) { wlm := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/clusteragent/languagedetection/patcher.go b/pkg/clusteragent/languagedetection/patcher.go index f68c1dc61c489..c18c1c13c4217 100644 --- a/pkg/clusteragent/languagedetection/patcher.go +++ b/pkg/clusteragent/languagedetection/patcher.go @@ -24,7 +24,7 @@ import ( "k8s.io/client-go/util/retry" "k8s.io/client-go/util/workqueue" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" "github.com/DataDog/datadog-agent/pkg/config" langUtil "github.com/DataDog/datadog-agent/pkg/languagedetection/util" diff --git a/pkg/clusteragent/languagedetection/patcher_test.go b/pkg/clusteragent/languagedetection/patcher_test.go index d2375b8e22703..b4f3feeacd396 100644 --- a/pkg/clusteragent/languagedetection/patcher_test.go +++ b/pkg/clusteragent/languagedetection/patcher_test.go @@ -26,8 +26,8 @@ import ( "k8s.io/client-go/util/workqueue" "github.com/DataDog/datadog-agent/comp/core" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -40,7 +40,7 @@ const ( eventuallyTestTick = 100 * time.Millisecond ) -func newMockLanguagePatcher(ctx context.Context, mockClient dynamic.Interface, mockStore workloadmetamock.Mock, mockLogger log.Mock) languagePatcher { +func newMockLanguagePatcher(ctx context.Context, mockClient dynamic.Interface, mockStore workloadmetamock.Mock, mockLogger log.Component) languagePatcher { ctx, cancel := context.WithCancel(ctx) return languagePatcher{ @@ -67,7 +67,7 @@ func TestRun(t *testing.T) { fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), )) - mocklogger := fxutil.Test[log.Component](t, logimpl.MockModule()) + mocklogger := logmock.New(t) ctx := context.Background() lp := newMockLanguagePatcher(ctx, mockK8sClient, mockStore, mocklogger) @@ -302,7 +302,7 @@ func TestPatcherRetriesFailedPatches(t *testing.T) { fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), )) - mocklogger := fxutil.Test[log.Component](t, logimpl.MockModule()) + mocklogger := logmock.New(t) ctx := context.Background() lp := newMockLanguagePatcher(ctx, mockK8sClient, mockStore, mocklogger) diff --git a/pkg/collector/corechecks/containers/kubelet/provider/summary/provider_test.go b/pkg/collector/corechecks/containers/kubelet/provider/summary/provider_test.go index 2bd9d058fb62f..62d3df1c6f3be 100644 --- a/pkg/collector/corechecks/containers/kubelet/provider/summary/provider_test.go +++ b/pkg/collector/corechecks/containers/kubelet/provider/summary/provider_test.go @@ -19,7 +19,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery/common/types" configcomp "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" @@ -382,7 +383,7 @@ func TestProvider_Provide(t *testing.T) { func creatFakeStore(t *testing.T) workloadmetamock.Mock { store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), configcomp.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client.go index c2956fe725d6b..29f334aaa24f3 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client.go @@ -326,6 +326,25 @@ func (client *Client) GetHardwareStates() ([]HardwareEnvironment, error) { return hardwareStates.Data, nil } +// GetCloudExpressMetrics gets cloud applications metrics +func (client *Client) GetCloudExpressMetrics() ([]CloudXStatistics, error) { + startDate, endDate := client.statisticsTimeRange() + + params := map[string]string{ + "startDate": startDate, + "endDate": endDate, + "timeZone": "UTC", + "count": client.maxCount, + } + + cloudApplications, err := getAllEntries[CloudXStatistics](client, "/dataservice/data/device/statistics/cloudxstatistics", params) + if err != nil { + return nil, err + } + + return cloudApplications.Data, nil +} + func (client *Client) statisticsTimeRange() (string, string) { endDate := timeNow().UTC() startDate := endDate.Add(-client.lookback) diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client_test.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client_test.go index 93fb9b181eedb..635afa8bd446f 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client_test.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/client_test.go @@ -538,3 +538,52 @@ func TestGetHardwareStates(t *testing.T) { // Ensure endpoint has been called 1 times require.Equal(t, 1, handler.numberOfCalls()) } + +func TestGetCloudExpressMetrics(t *testing.T) { + timeNow = mockTimeNow + mux := setupCommonServerMux() + + handler := newHandler(func(w http.ResponseWriter, r *http.Request, calls int32) { + query := r.URL.Query() + count := query.Get("count") + timeZone := query.Get("timeZone") + startDate := query.Get("startDate") + endDate := query.Get("endDate") + + require.Equal(t, "2000", count) + require.Equal(t, "UTC", timeZone) + require.Equal(t, "1999-12-31T23:50:00", startDate) + require.Equal(t, "2000-01-01T00:00:00", endDate) + + w.WriteHeader(http.StatusOK) + w.Write([]byte(fixtures.FakePayload(fixtures.GetCloudExpressMetrics))) + }) + + mux.HandleFunc("/dataservice/data/device/statistics/cloudxstatistics", handler.Func) + + server := httptest.NewServer(mux) + defer server.Close() + + client, err := testClient(server) + require.NoError(t, err) + + devices, err := client.GetCloudExpressMetrics() + require.NoError(t, err) + + require.Equal(t, "10.10.1.13", devices[0].VmanageSystemIP) + require.Equal(t, "10.10.1.13", devices[0].LocalSystemIP) + require.Equal(t, "10.10.1.11", devices[0].GatewaySystemIP) + require.Equal(t, "mpls", devices[0].LocalColor) + require.Equal(t, "mpls", devices[0].RemoteColor) + require.Equal(t, "FALSE", devices[0].BestPath) + require.Equal(t, "amazon_aws", devices[0].Application) + require.Equal(t, "amazon-group", devices[0].NbarAppGroupName) + require.Equal(t, float64(1), devices[0].VpnID) + require.Equal(t, float64(1721819993833), devices[0].EntryTime) + require.Equal(t, float64(404), devices[0].Latency) + require.Equal(t, float64(0), devices[0].Loss) + require.Equal(t, "5.0", devices[0].VqeScore) + + // Ensure endpoint has been called 1 times + require.Equal(t, 1, handler.numberOfCalls()) +} diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/fixtures/payloads.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/fixtures/payloads.go index 8cbc941b19f9e..9bfe96aa2337e 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/fixtures/payloads.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/fixtures/payloads.go @@ -149,11 +149,11 @@ const GetCEdgeInterfaces = ` "createTimeStamp": 1707919153393, "vpn-id": "0", "vdevice-host-name": "Site3-cEdge01", - "ipv4-subnet-mask": "0.0.0.0", + "ipv4-subnet-mask": "255.255.255.0", "tx-drops": 0, "mtu": "1500", "rx-drops": 0, - "ip-address": "0.0.0.0", + "ip-address": "10.0.0.1", "speed-mbps": "1000", "hwaddr": "52:54:00:0b:6e:90", "vdevice-dataKey": "10.10.1.17-0-GigabitEthernet4-0.0.0.0-52:54:00:0b:6e:90", @@ -400,3 +400,39 @@ const GetHardwareStates = ` } ] ` + +// GetCloudExpressMetrics /dataservice/data/device/statistics/cloudxstatistics +const GetCloudExpressMetrics = ` +[ + { + "remote_color": "mpls", + "device_model": "vedge-C8000V", + "latency": 404, + "interface": "-", + "local_color": "mpls", + "loss": 0, + "gateway_system_ip": "10.10.1.11", + "source_public_ip": "-", + "statcycletime": 1721820600114, + "local_system_ip": "10.10.1.13", + "tenant": "default", + "entry_time": 1721819993833, + "vqe_status": "averageSites", + "exit_type": "Remote", + "vip_time": 1721819993833, + "vmanage_system_ip": "10.10.1.13", + "nbar_app_group_name": "amazon-group", + "application": "amazon_aws", + "vdevice_name": "10.10.1.13", + "best_path": "FALSE", + "vip_idx": 9789, + "site_id": 1001, + "vqe_score": "5.0", + "service_area": "-", + "host_name": "Site1-cEdge01", + "vpn_id": 1, + "app_url_host_ip": "-", + "id": "1DKB5JAB5928XahrV_c7" + } +] +` diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/test_utils.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/test_utils.go index 048094feccdd3..77131e55f7108 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/test_utils.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/test_utils.go @@ -107,6 +107,7 @@ func SetupMockAPIServer() *httptest.Server { mux.HandleFunc("/dataservice/data/device/state/OMPPeer", fixtureHandler(fixtures.GetOMPPeersState)) mux.HandleFunc("/dataservice/data/device/state/BFDSessions", fixtureHandler(fixtures.GetBFDSessionsState)) mux.HandleFunc("/dataservice/data/device/state/HardwareEnvironment", fixtureHandler(fixtures.GetHardwareStates)) + mux.HandleFunc("/dataservice/data/device/statistics/cloudxstatistics", fixtureHandler(fixtures.GetCloudExpressMetrics)) return httptest.NewServer(mux) } diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/types.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/types.go index 4763741d378c4..d0ec6b67ded03 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/client/types.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/client/types.go @@ -59,7 +59,8 @@ type Content interface { ControlConnections | OMPPeer | BFDSession | - HardwareEnvironment + HardwareEnvironment | + CloudXStatistics } // Response is a generic struct for API responses @@ -406,3 +407,35 @@ type HardwareEnvironment struct { Lastupdated int64 `json:"lastupdated"` Status string `json:"status"` } + +// CloudXStatistics /dataservice/data/device/statistics/cloudxstatistics +type CloudXStatistics struct { + RemoteColor string `json:"remote_color"` + DeviceModel string `json:"device_model"` + Latency float64 `json:"latency"` + Interface string `json:"interface"` + LocalColor string `json:"local_color"` + Loss float64 `json:"loss"` + GatewaySystemIP string `json:"gateway_system_ip"` + SourcePublicIP string `json:"source_public_ip"` + Statcycletime float64 `json:"statcycletime"` + LocalSystemIP string `json:"local_system_ip"` + Tenant string `json:"tenant"` + EntryTime float64 `json:"entry_time"` + VqeStatus string `json:"vqe_status"` + ExitType string `json:"exit_type"` + VipTime float64 `json:"vip_time"` + VmanageSystemIP string `json:"vmanage_system_ip"` + NbarAppGroupName string `json:"nbar_app_group_name"` + Application string `json:"application"` + VdeviceName string `json:"vdevice_name"` + BestPath string `json:"best_path"` + VipIdx float64 `json:"vip_idx"` + SiteID float64 `json:"site_id"` + VqeScore string `json:"vqe_score"` + ServiceArea string `json:"service_area"` + HostName string `json:"host_name"` + VpnID float64 `json:"vpn_id"` + AppURLHostIP string `json:"app_url_host_ip"` + ID string `json:"id"` +} diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface.go index 4b159c1ad931e..ab6ac11187aee 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface.go @@ -150,7 +150,7 @@ func isEmptyCEdgeIP(ip string) bool { func parseCEdgeIP(ip string) (string, error) { ipAddr := net.ParseIP(ip) - if ipAddr == nil { + if ipAddr == nil || ipAddr.IsUnspecified() { return "", fmt.Errorf("invalid ip address") } return ipAddr.String(), nil diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface_test.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface_test.go index c790b499b73bb..88c2d7f9a8424 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface_test.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/cedge_interface_test.go @@ -171,6 +171,39 @@ func TestCEdgeInterface(t *testing.T) { expectedIPV4Address: nil, expectedIPV4AddressError: "invalid mask", }, + { + name: "unspecified ip address", + namespace: "test-ns", + itf: client.CEdgeInterfaceState{ + VmanageSystemIP: "10.0.0.1", + Ifname: "test-interface", + Ifindex: "10", + SpeedMbps: "0.1", + IfOperStatus: "if-oper-state-ready", + IfAdminStatus: "if-state-down", + Description: "Description", + Hwaddr: "00:01:02:03", + IPAddress: "0.0.0.0", + Ipv4SubnetMask: "255.255.255.0", + }, + expectedID: "10.0.0.1:test-interface", + expectedIndex: 10, + expectedSpeed: 0.1, + expectedOperStatus: devicemetadata.OperStatusUp, + expectedAdminStatus: devicemetadata.AdminStatusDown, + expectedMetadata: devicemetadata.InterfaceMetadata{ + DeviceID: "test-ns:10.0.0.1", + IDTags: []string{"interface:test-interface"}, + Index: 10, + Name: "test-interface", + Description: "Description", + MacAddress: "00:01:02:03", + OperStatus: devicemetadata.OperStatusUp, + AdminStatus: devicemetadata.AdminStatusDown, + }, + expectedIPV4Address: nil, + expectedIPV4AddressError: "invalid ip address", + }, } for _, tt := range tests { diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface.go index 5e9c7579cf6f1..7f8d5e3463582 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface.go @@ -106,6 +106,11 @@ func parseVEdgeIP(ip string) (string, int32, error) { if err != nil { return "", 0, err } + + if ipaddr.IsUnspecified() { + return "", 0, fmt.Errorf("IP address is unspecified") + } + prefixLen, _ := ipv4Net.Mask.Size() return ipaddr.String(), int32(prefixLen), nil diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface_test.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface_test.go index 5e16bca90ae6e..b276ea47cecc5 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface_test.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/payload/vedge_interface_test.go @@ -164,6 +164,38 @@ func TestVEdgeInterface(t *testing.T) { expectedIPV6Address: nil, expectedIPV6Error: "invalid CIDR address", }, + { + name: "unspecified ip address", + namespace: "test-ns", + itf: client.InterfaceState{ + VmanageSystemIP: "10.0.0.1", + Ifname: "test-interface", + Ifindex: 10, + SpeedMbps: "0.1", + IfOperStatus: "Up", + IfAdminStatus: "Down", + Desc: "Description", + Hwaddr: "00:01:02:03", + IPAddress: "0.0.0.0/24", + }, + expectedID: "10.0.0.1:test-interface", + expectedIndex: 10, + expectedSpeed: 0.1, + expectedOperStatus: devicemetadata.OperStatusUp, + expectedAdminStatus: devicemetadata.AdminStatusDown, + expectedMetadata: devicemetadata.InterfaceMetadata{ + DeviceID: "test-ns:10.0.0.1", + IDTags: []string{"interface:test-interface"}, + Index: 10, + Name: "test-interface", + Description: "Description", + MacAddress: "00:01:02:03", + OperStatus: devicemetadata.OperStatusUp, + AdminStatus: devicemetadata.AdminStatusDown, + }, + expectedIPV4Address: nil, + expectedIPV4Error: "IP address is unspecified", + }, } for _, tt := range tests { diff --git a/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go b/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go index 4158bdaff162a..d5d590961b269 100644 --- a/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go +++ b/pkg/collector/corechecks/network-devices/cisco-sdwan/sdwan_test.go @@ -235,7 +235,8 @@ collect_hardware_status: true "ip_addresses": [ { "interface_id": "test:10.10.1.17:4", - "ip_address": "0.0.0.0" + "ip_address": "10.0.0.1", + "prefixlen": 24 } ], "collect_timestamp": 1708942920 diff --git a/pkg/collector/corechecks/sbom/processor_test.go b/pkg/collector/corechecks/sbom/processor_test.go index d8b3a08684109..9a410b8508b95 100644 --- a/pkg/collector/corechecks/sbom/processor_test.go +++ b/pkg/collector/corechecks/sbom/processor_test.go @@ -25,7 +25,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core" configcomp "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -614,7 +615,7 @@ func TestProcessEvents(t *testing.T) { SBOMsSent := atomic.NewInt32(0) workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), configcomp.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/collector/python/init.go b/pkg/collector/python/init.go index bd7416f7b0ed3..de57c3d841f83 100644 --- a/pkg/collector/python/init.go +++ b/pkg/collector/python/init.go @@ -13,6 +13,7 @@ import ( "os" "path/filepath" "runtime" + "slices" "strings" "sync" "time" @@ -245,10 +246,7 @@ func expvarPythonInitErrors() interface{} { pyInitLock.RLock() defer pyInitLock.RUnlock() - pyInitErrorsCopy := []string{} - pyInitErrorsCopy = append(pyInitErrorsCopy, pyInitErrors...) - - return pyInitErrorsCopy + return slices.Clone(pyInitErrors) } func addExpvarPythonInitErrors(msg string) error { diff --git a/pkg/collector/python/loader.go b/pkg/collector/python/loader.go index a1bbd8aa8eed4..4a565fceb2699 100644 --- a/pkg/collector/python/loader.go +++ b/pkg/collector/python/loader.go @@ -15,21 +15,20 @@ import ( "sync" "unsafe" + "github.com/mohae/deepcopy" + "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" - "github.com/DataDog/datadog-agent/comp/logs/integrations/def" + integrations "github.com/DataDog/datadog-agent/comp/logs/integrations/def" "github.com/DataDog/datadog-agent/pkg/aggregator" "github.com/DataDog/datadog-agent/pkg/aggregator/sender" "github.com/DataDog/datadog-agent/pkg/collector/check" "github.com/DataDog/datadog-agent/pkg/collector/loaders" - - //nolint:revive // TODO(AML) Fix revive linter agentConfig "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/metrics" "github.com/DataDog/datadog-agent/pkg/tagset" - "github.com/DataDog/datadog-agent/pkg/version" - "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/optional" + "github.com/DataDog/datadog-agent/pkg/version" ) /* @@ -237,14 +236,7 @@ func expvarConfigureErrors() interface{} { statsLock.RLock() defer statsLock.RUnlock() - configureErrorsCopy := map[string][]string{} - for k, v := range configureErrors { - errors := []string{} - errors = append(errors, v...) - configureErrorsCopy[k] = errors - } - - return configureErrorsCopy + return deepcopy.Copy(configureErrors) } func addExpvarConfigureError(check string, errMsg string) { @@ -264,14 +256,7 @@ func expvarPy3Warnings() interface{} { statsLock.RLock() defer statsLock.RUnlock() - py3WarningsCopy := map[string][]string{} - for k, v := range py3Warnings { - warnings := []string{} - warnings = append(warnings, v...) - py3WarningsCopy[k] = warnings - } - - return py3WarningsCopy + return deepcopy.Copy(py3Warnings) } // reportPy3Warnings runs the a7 linter and exports the result in both expvar diff --git a/pkg/collector/runner/expvars/expvars.go b/pkg/collector/runner/expvars/expvars.go index b5aa9cf686620..e3ca2b3f8482a 100644 --- a/pkg/collector/runner/expvars/expvars.go +++ b/pkg/collector/runner/expvars/expvars.go @@ -11,6 +11,8 @@ import ( "sync" "time" + "github.com/mohae/deepcopy" + "github.com/DataDog/datadog-agent/pkg/collector/check" checkid "github.com/DataDog/datadog-agent/pkg/collector/check/id" checkstats "github.com/DataDog/datadog-agent/pkg/collector/check/stats" @@ -98,19 +100,8 @@ func GetCheckStats() map[string]map[checkid.ID]*checkstats.Stats { defer checkStats.statsLock.RUnlock() // Because the returned maps will be used after the lock is released, and - // thus when they might be further modified, we must clone them here. The - // map values (`stats.Stats`) are threadsafe and need not be cloned. - - cloned := make(map[string]map[checkid.ID]*checkstats.Stats) - for k, v := range checkStats.stats { - innerCloned := make(map[checkid.ID]*checkstats.Stats) - for innerK, innerV := range v { - innerCloned[innerK] = innerV - } - cloned[k] = innerCloned - } - - return cloned + // thus when they might be further modified, we must clone them here. + return deepcopy.Copy(checkStats.stats).(map[string]map[checkid.ID]*checkstats.Stats) } // AddCheckStats adds runtime stats to the check's expvars diff --git a/pkg/collector/runner/expvars/expvars_test.go b/pkg/collector/runner/expvars/expvars_test.go index 1c2b431d7a80d..df3fda6c9b35f 100644 --- a/pkg/collector/runner/expvars/expvars_test.go +++ b/pkg/collector/runner/expvars/expvars_test.go @@ -6,6 +6,8 @@ package expvars import ( + "encoding/json" + "errors" "expvar" "fmt" "sort" @@ -398,3 +400,41 @@ func TestExpvarsToplevelKeys(t *testing.T) { changeAndAssertExpvarValue(t, keyName, setter, getters[keyName], 3, 4) } } + +func TestGetCheckStatsRace(t *testing.T) { + Reset() + t.Cleanup(Reset) + + numCheckNames := 3 + numCheckInstances := 5 + numCheckRuns := 7 + + var wg sync.WaitGroup + + for i := 0; i < 10; i++ { + wg.Add(1) + go func() { + defer wg.Done() + + for checkNameIdx := 0; checkNameIdx < numCheckNames; checkNameIdx++ { + for checkIDIdx := 0; checkIDIdx < numCheckInstances; checkIDIdx++ { + checkName := fmt.Sprintf("testcheck%d", checkNameIdx) + checkID := fmt.Sprintf("%s:%d", checkName, checkIDIdx) + testCheck := newTestCheck(checkID) + + warnings := []error{errors.New("error1"), errors.New("error2"), errors.New("error3")} + for runIdx := 0; runIdx < numCheckRuns; runIdx++ { + AddCheckStats(testCheck, 12345, nil, warnings, stats.SenderStats{}) + } + } + } + }() + } + + for i := 0; i < 10; i++ { + stats := GetCheckStats() + _, _ = json.Marshal(stats) + } + + wg.Wait() +} diff --git a/pkg/config/aliases.go b/pkg/config/aliases.go index 2dc1a564d8039..134df60c250bc 100644 --- a/pkg/config/aliases.go +++ b/pkg/config/aliases.go @@ -48,7 +48,6 @@ var ( IsServerless = env.IsServerless IsContainerized = env.IsContainerized IsDockerRuntime = env.IsDockerRuntime - GetEnvDefault = env.GetEnvDefault IsHostProcAvailable = env.IsHostProcAvailable IsHostSysAvailable = env.IsHostSysAvailable IsAnyContainerFeaturePresent = env.IsAnyContainerFeaturePresent diff --git a/pkg/config/config_template.yaml b/pkg/config/config_template.yaml index 19121139bdf6c..d93b4d3af428b 100644 --- a/pkg/config/config_template.yaml +++ b/pkg/config/config_template.yaml @@ -1637,6 +1637,39 @@ api_key: # enabled: false {{ end }} + +{{- if .NetworkPath }} +{{- if (ne .OS "darwin")}} + +######################################## +## Network Path Configuration ## +######################################## + +# network_path: + ## @param connections_monitoring - custom object - optional + ## Specific configurations for monitoring network connections via Network Path. + # + # connections_monitoring: + + ## @param enabled - bool - optional - default: false + ## @env DD_NETWORK_PATH_CONNECTIONS_MONITORING_ENABLED - bool - optional - default: false + ## [Beta] Enables monitoring network connections via Network Path. + # + # enabled: false + + ## @param collector - custom object - optional + ## Configuration related to Network Path Collector. + # + # collector: + + ## @param workers - integer - optional - default: 4 + ## @env DD_WORKERS - integer - optional - default: 4 + ## The `workers` refers to the number of concurrent workers available for network path execution. + # + # workers: 4 + +{{ end -}} +{{ end -}} {{ end -}} {{- if .Compliance }} ############################################# @@ -1828,6 +1861,21 @@ api_key: {{ end -}} +{{- if .TracerouteModule }} + +########################################### +## System Probe Traceroute Configuration ## +########################################### + +# traceroute: + ## @param enabled - boolean - optional - default: false + ## Set to true to enable the Traceroute Module of the System Probe + # + # enabled: false + +{{ end -}} + + {{- if .SecurityModule }} ########################################## diff --git a/pkg/config/env/environment.go b/pkg/config/env/environment.go index bdd2f7637de17..5fa7623794e1f 100644 --- a/pkg/config/env/environment.go +++ b/pkg/config/env/environment.go @@ -11,15 +11,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/filesystem" ) -// GetEnvDefault retrieves a value from the environment named by the key or return def if not set. -func GetEnvDefault(key, def string) string { - value, found := os.LookupEnv(key) - if !found { - return def - } - return value -} - // IsContainerized returns whether the Agent is running on a Docker container // DOCKER_DD_AGENT is set in our official Dockerfile func IsContainerized() bool { diff --git a/pkg/config/render_config.go b/pkg/config/render_config.go index 7d7c86878c12a..7d2412e8a9ac1 100644 --- a/pkg/config/render_config.go +++ b/pkg/config/render_config.go @@ -54,9 +54,11 @@ type context struct { UniversalServiceMonitoringModule bool // Sub-module of System Probe DataStreamsModule bool // Sub-module of System Probe PingModule bool // Sub-module of System Probe + TracerouteModule bool // Sub-module of System Probe PrometheusScrape bool OTLP bool APMInjection bool + NetworkPath bool } func mkContext(buildType string) context { @@ -88,6 +90,7 @@ func mkContext(buildType string) context { SNMP: true, PrometheusScrape: true, OTLP: true, + NetworkPath: true, } switch buildType { @@ -115,6 +118,7 @@ func mkContext(buildType string) context { DataStreamsModule: true, SecurityModule: true, PingModule: true, + TracerouteModule: true, } case "dogstatsd": return context{ diff --git a/pkg/config/setup/config.go b/pkg/config/setup/config.go index 419f074550a22..dc692642a7c33 100644 --- a/pkg/config/setup/config.go +++ b/pkg/config/setup/config.go @@ -1441,6 +1441,7 @@ func logsagent(config pkgconfigmodel.Setup) { // maximum time that the windows tailer will hold a log file open, while waiting for // the downstream logs pipeline to be ready to accept more data config.BindEnvAndSetDefault("logs_config.windows_open_file_timeout", 5) + config.BindEnvAndSetDefault("logs_config.experimental_auto_multi_line_detection", false) config.BindEnvAndSetDefault("logs_config.auto_multi_line_detection", false) config.BindEnvAndSetDefault("logs_config.auto_multi_line_extra_patterns", []string{}) // The following auto_multi_line settings are experimental and may change diff --git a/pkg/fleet/installer/service/docker.go b/pkg/fleet/installer/service/docker.go index 2c6a487ccf538..acbd6c4166247 100644 --- a/pkg/fleet/installer/service/docker.go +++ b/pkg/fleet/installer/service/docker.go @@ -17,9 +17,11 @@ import ( "os/exec" "path" "strings" + "syscall" "time" "github.com/DataDog/datadog-agent/pkg/util/log" + "github.com/shirou/gopsutil/v3/process" "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" ) @@ -176,22 +178,27 @@ func reloadDockerConfig(ctx context.Context) (err error) { log.Warn("docker is inactive, skipping docker reload") return nil } - cmdPids := exec.CommandContext(ctx, "pidof", "dockerd") - buf := new(bytes.Buffer) - bufErr := new(bytes.Buffer) - cmdPids.Stdout = buf - cmdPids.Stderr = bufErr - err = cmdPids.Run() - if err != nil { - return fmt.Errorf("failed to get docker daemon pid (%s): %s", err.Error(), bufErr.String()) - } - cmd := exec.CommandContext(ctx, "kill", "-1", strings.TrimSpace(buf.String())) // Send SIGHUP to the docker daemon - bufErr = new(bytes.Buffer) - cmd.Stderr = bufErr - err = cmd.Run() + pids := []int32{} + processes, err := process.Processes() if err != nil { - return fmt.Errorf("failed to reload docker (%s): %s", err.Error(), bufErr.String()) + return fmt.Errorf("couldn't get running processes: %s", err.Error()) + } + for _, process := range processes { + name, err := process.NameWithContext(ctx) + if err != nil { + continue // Don't pollute with warning logs + } + if name == "dockerd" { + pids = append(pids, process.Pid) + } + } + span.SetTag("dockerd_count", len(pids)) + for _, pid := range pids { + err = syscall.Kill(int(pid), syscall.SIGHUP) + if err != nil { + return fmt.Errorf("failed to reload docker daemon (pid %d): %s", pid, err.Error()) + } } return nil } diff --git a/pkg/logs/internal/decoder/auto_multiline_detection/aggregator.go b/pkg/logs/internal/decoder/auto_multiline_detection/aggregator.go new file mode 100644 index 0000000000000..92d607a6cecf3 --- /dev/null +++ b/pkg/logs/internal/decoder/auto_multiline_detection/aggregator.go @@ -0,0 +1,144 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package automultilinedetection contains auto multiline detection and aggregation logic. +package automultilinedetection + +import ( + "bytes" + "time" + + "github.com/DataDog/datadog-agent/pkg/logs/message" +) + +type bucket struct { + message *message.Message + buffer *bytes.Buffer + lineCount int +} + +func (b *bucket) add(msg *message.Message) { + if b.message == nil { + b.message = msg + } + if b.buffer.Len() > 0 { + b.buffer.Write(message.EscapedLineFeed) + } + b.buffer.Write(msg.GetContent()) + b.lineCount++ +} + +func (b *bucket) isEmpty() bool { + return b.buffer.Len() == 0 +} + +func (b *bucket) flush() *message.Message { + defer func() { + b.buffer.Reset() + b.message = nil + b.lineCount = 0 + }() + + originalLen := b.buffer.Len() + data := bytes.TrimSpace(b.buffer.Bytes()) + content := make([]byte, len(data)) + copy(content, data) + + if b.lineCount > 1 { + return message.NewRawMultiLineMessage(content, b.message.Status, originalLen, b.message.ParsingExtra.Timestamp) + } + return message.NewRawMessage(content, b.message.Status, originalLen, b.message.ParsingExtra.Timestamp) +} + +// Aggregator aggregates multiline logs with a given label. +type Aggregator struct { + outputFn func(m *message.Message) + bucket *bucket + maxContentSize int + flushTimeout time.Duration + flushTimer *time.Timer +} + +// NewAggregator creates a new aggregator. +func NewAggregator(outputFn func(m *message.Message), maxContentSize int, flushTimeout time.Duration) *Aggregator { + return &Aggregator{ + outputFn: outputFn, + bucket: &bucket{buffer: bytes.NewBuffer(nil)}, + maxContentSize: maxContentSize, + flushTimeout: flushTimeout, + } +} + +// Aggregate aggregates a multiline log using a label. +func (a *Aggregator) Aggregate(msg *message.Message, label Label) { + + a.stopFlushTimerIfNeeded() + defer a.startFlushTimerIfNeeded() + + // If `noAggregate` - flush the bucket immediately and then flush the next message. + if label == noAggregate { + a.Flush() + a.outputFn(msg) + return + } + + // If `aggregate` and the bucket is empty - flush the next message. + if label == aggregate && a.bucket.isEmpty() { + a.outputFn(msg) + return + } + + // If `startGroup` - flush the bucket. + if label == startGroup { + a.Flush() + } + + // At this point we either have `startGroup` with an empty bucket or `aggregate` with a non-empty bucket + // so we add the message to the bucket or flush if the bucket will overflow the max content size. + + if msg.RawDataLen+a.bucket.buffer.Len() > a.maxContentSize { + a.bucket.flush() + } + + a.bucket.add(msg) +} + +func (a *Aggregator) stopFlushTimerIfNeeded() { + if a.flushTimer == nil || a.bucket.isEmpty() { + return + } + // stop the flush timer, as we now have data + if !a.flushTimer.Stop() { + <-a.flushTimer.C + } +} + +func (a *Aggregator) startFlushTimerIfNeeded() { + if a.bucket.isEmpty() { + return + } + // since there's buffered data, start the flush timer to flush it + if a.flushTimer == nil { + a.flushTimer = time.NewTimer(a.flushTimeout) + } else { + a.flushTimer.Reset(a.flushTimeout) + } +} + +// FlushChan returns the flush timer channel. +func (a *Aggregator) FlushChan() <-chan time.Time { + if a.flushTimer != nil { + return a.flushTimer.C + } + return nil +} + +// Flush flushes the aggregator. +func (a *Aggregator) Flush() { + if a.bucket.isEmpty() { + return + } + a.outputFn(a.bucket.flush()) +} diff --git a/pkg/logs/internal/decoder/auto_multiline_detection/aggregator_test.go b/pkg/logs/internal/decoder/auto_multiline_detection/aggregator_test.go new file mode 100644 index 0000000000000..2d25b7cf8c1ca --- /dev/null +++ b/pkg/logs/internal/decoder/auto_multiline_detection/aggregator_test.go @@ -0,0 +1,128 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package automultilinedetection contains auto multiline detection and aggregation logic. +package automultilinedetection + +import ( + "strings" + "testing" + "time" + + "github.com/stretchr/testify/assert" + + "github.com/DataDog/datadog-agent/pkg/logs/message" +) + +func makeHandler() (chan *message.Message, func(*message.Message)) { + ch := make(chan *message.Message, 20) + return ch, func(m *message.Message) { + ch <- m + } +} + +func newMessage(content string) *message.Message { + return message.NewRawMessage([]byte(content), message.StatusInfo, len([]byte(content)), "") +} + +func assertMessageContent(t *testing.T, m *message.Message, content string) { + isMultiLine := len(strings.Split(content, "\\n")) > 1 + assert.Equal(t, content, string(m.GetContent())) + assert.Equal(t, m.IsMultiLine, isMultiLine) +} + +func TestNoAggregate(t *testing.T) { + + outputChan, outputFn := makeHandler() + ag := NewAggregator(outputFn, 100, time.Duration(1*time.Second)) + + ag.Aggregate(newMessage("1"), noAggregate) + ag.Aggregate(newMessage("2"), noAggregate) + ag.Aggregate(newMessage("3"), noAggregate) + + assertMessageContent(t, <-outputChan, "1") + assertMessageContent(t, <-outputChan, "2") + assertMessageContent(t, <-outputChan, "3") +} + +func TestNoAggregateEndsGroup(t *testing.T) { + + outputChan, outputFn := makeHandler() + ag := NewAggregator(outputFn, 100, time.Duration(1*time.Second)) + + ag.Aggregate(newMessage("1"), startGroup) + ag.Aggregate(newMessage("2"), startGroup) + ag.Aggregate(newMessage("3"), noAggregate) // Causes flush or last group, and flush of noAggregate message + + assertMessageContent(t, <-outputChan, "1") + assertMessageContent(t, <-outputChan, "2") + assertMessageContent(t, <-outputChan, "3") +} + +func TestAggregateGroups(t *testing.T) { + + outputChan, outputFn := makeHandler() + ag := NewAggregator(outputFn, 100, time.Duration(1*time.Second)) + + // Aggregated log + ag.Aggregate(newMessage("1"), startGroup) + ag.Aggregate(newMessage("2"), aggregate) + ag.Aggregate(newMessage("3"), aggregate) + + // Aggregated log + ag.Aggregate(newMessage("4"), startGroup) + + // Aggregated log + ag.Aggregate(newMessage("5"), noAggregate) + + assertMessageContent(t, <-outputChan, "1\\n2\\n3") + assertMessageContent(t, <-outputChan, "4") + assertMessageContent(t, <-outputChan, "5") +} + +func TestAggregateDoesntStartGroup(t *testing.T) { + + outputChan, outputFn := makeHandler() + ag := NewAggregator(outputFn, 100, time.Duration(1*time.Second)) + + ag.Aggregate(newMessage("1"), aggregate) + ag.Aggregate(newMessage("2"), aggregate) + ag.Aggregate(newMessage("3"), aggregate) + + assertMessageContent(t, <-outputChan, "1") + assertMessageContent(t, <-outputChan, "2") + assertMessageContent(t, <-outputChan, "3") +} + +func TestForceFlush(t *testing.T) { + + outputChan, outputFn := makeHandler() + ag := NewAggregator(outputFn, 100, time.Duration(1*time.Second)) + + ag.Aggregate(newMessage("1"), startGroup) + ag.Aggregate(newMessage("2"), aggregate) + ag.Aggregate(newMessage("3"), aggregate) + ag.Flush() + + assertMessageContent(t, <-outputChan, "1\\n2\\n3") +} + +func TestAggregationTimer(t *testing.T) { + + outputChan, outputFn := makeHandler() + ag := NewAggregator(outputFn, 100, time.Duration(1*time.Second)) + + assert.Nil(t, ag.FlushChan()) + ag.Aggregate(newMessage("1"), startGroup) + assert.NotNil(t, ag.FlushChan()) + + ag.Aggregate(newMessage("2"), startGroup) + assert.NotNil(t, ag.FlushChan()) + + ag.Flush() + + assertMessageContent(t, <-outputChan, "1") + assertMessageContent(t, <-outputChan, "2") +} diff --git a/pkg/logs/internal/decoder/auto_multiline_detection/json_detector.go b/pkg/logs/internal/decoder/auto_multiline_detection/json_detector.go new file mode 100644 index 0000000000000..b58e2267c4f2c --- /dev/null +++ b/pkg/logs/internal/decoder/auto_multiline_detection/json_detector.go @@ -0,0 +1,29 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package automultilinedetection contains auto multiline detection and aggregation logic. +package automultilinedetection + +import "regexp" + +var jsonRegexp = regexp.MustCompile(`^\s*\{\s*["}]`) + +// JSONDetector is a heuristic to detect JSON messages. +type JSONDetector struct{} + +// NewJSONDetector returns a new JSON detection heuristic. +func NewJSONDetector() *JSONDetector { + return &JSONDetector{} +} + +// Process checks if a message is a JSON message. +// This implements the Herustic interface - so we should stop processing if we detect a JSON message by returning false. +func (j *JSONDetector) Process(context *messageContext) bool { + if jsonRegexp.Match(context.rawMessage) { + context.label = noAggregate + return false + } + return true +} diff --git a/pkg/logs/internal/decoder/auto_multiline_detection/json_detector_test.go b/pkg/logs/internal/decoder/auto_multiline_detection/json_detector_test.go new file mode 100644 index 0000000000000..a22fbdd1386e5 --- /dev/null +++ b/pkg/logs/internal/decoder/auto_multiline_detection/json_detector_test.go @@ -0,0 +1,50 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package automultilinedetection contains auto multiline detection and aggregation logic. +package automultilinedetection + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestJsonDetector(t *testing.T) { + jsonDetector := NewJSONDetector() + testCases := []struct { + rawMessage string + expectedLabel Label + expectedResult bool + }{ + {`{"key": "value"}`, noAggregate, false}, + {` {"key": "value"}`, noAggregate, false}, + {` { "key": "value"}`, noAggregate, false}, + {` {."key": "value"}`, aggregate, true}, + {`.{"key": "value"}`, aggregate, true}, + {`{"another_key": "another_value"}`, noAggregate, false}, + {`{"key": 12345}`, noAggregate, false}, + {`{"array": [1,2,3]}`, noAggregate, false}, + {`not json`, aggregate, true}, + {`{foo}`, aggregate, true}, + {`{bar"}`, aggregate, true}, + {`"FOO"}`, aggregate, true}, + {`{}`, noAggregate, false}, + {` {}`, noAggregate, false}, + {` { }`, noAggregate, false}, + {`{ }`, noAggregate, false}, + } + + for _, tc := range testCases { + t.Run(string(tc.rawMessage), func(t *testing.T) { + messageContext := &messageContext{ + rawMessage: []byte(tc.rawMessage), + label: aggregate, + } + assert.Equal(t, tc.expectedResult, jsonDetector.Process(messageContext)) + assert.Equal(t, tc.expectedLabel, messageContext.label) + }) + } +} diff --git a/pkg/logs/internal/decoder/auto_multiline_detection/labeler.go b/pkg/logs/internal/decoder/auto_multiline_detection/labeler.go new file mode 100644 index 0000000000000..4256bab486d3d --- /dev/null +++ b/pkg/logs/internal/decoder/auto_multiline_detection/labeler.go @@ -0,0 +1,63 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package automultilinedetection contains auto multiline detection and aggregation logic. +package automultilinedetection + +// TODO: (brian) - This will be implemented in a future PR when the tokenizer is added +type token uint + +// Label is a label for a log message. +type Label uint32 + +const ( + startGroup Label = iota + noAggregate + aggregate +) + +type messageContext struct { + rawMessage []byte + // NOTE: tokens can be nil if the heuristic runs before the tokenizer. + // Heuristic implementations must check if tokens is nil before using it. + tokens []token + label Label +} + +// Heuristic is an interface representing a strategy to label log messages. +type Heuristic interface { + // Process processes a log message and annotates the context with a label. It returns false if the message should be done processing. + // Heuristic implementations may mutate the message context but must do so synchronously. + Process(*messageContext) bool +} + +// Labeler labels log messages based on a set of heuristics. +// Each Heuristic operates on the output of the previous heuristic - mutating the message context. +// A label is chosen when a herusitc signals the labeler to stop or when all herustics have been processed. +type Labeler struct { + heuristics []Heuristic +} + +// NewLabeler creates a new labeler with the given heuristics. +func NewLabeler(heuristics []Heuristic) *Labeler { + return &Labeler{ + heuristics: heuristics, + } +} + +// Label labels a log message. +func (l *Labeler) Label(rawMessage []byte) Label { + context := &messageContext{ + rawMessage: rawMessage, + tokens: nil, + label: aggregate, + } + for _, h := range l.heuristics { + if !h.Process(context) { + return context.label + } + } + return context.label +} diff --git a/pkg/logs/internal/decoder/auto_multiline_detection/labeler_test.go b/pkg/logs/internal/decoder/auto_multiline_detection/labeler_test.go new file mode 100644 index 0000000000000..13bb5b77a17a3 --- /dev/null +++ b/pkg/logs/internal/decoder/auto_multiline_detection/labeler_test.go @@ -0,0 +1,88 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package automultilinedetection contains auto multiline detection and aggregation logic. +package automultilinedetection + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +type mockHeuristic struct { + processFunc func(*messageContext) bool +} + +func (m *mockHeuristic) Process(context *messageContext) bool { + return m.processFunc(context) +} + +func TestLabelerProceedNextHeuristic(t *testing.T) { + + labeler := NewLabeler([]Heuristic{ + &mockHeuristic{ + processFunc: func(context *messageContext) bool { + context.label = startGroup + return true + }, + }, + &mockHeuristic{ + processFunc: func(context *messageContext) bool { + context.label = noAggregate + return true + }, + }, + }) + + assert.Equal(t, noAggregate, labeler.Label([]byte("test 123"))) +} + +func TestLabelerProceedFirstHeuristicWins(t *testing.T) { + + labeler := NewLabeler([]Heuristic{ + &mockHeuristic{ + processFunc: func(context *messageContext) bool { + context.label = startGroup + return false + }, + }, + &mockHeuristic{ + processFunc: func(context *messageContext) bool { + context.label = noAggregate + return true + }, + }, + }) + + assert.Equal(t, startGroup, labeler.Label([]byte("test 123"))) +} + +func TestLabelerDefaultLabel(t *testing.T) { + + labeler := NewLabeler([]Heuristic{ + &mockHeuristic{ + processFunc: func(context *messageContext) bool { + return false + }, + }, + }) + + assert.Equal(t, aggregate, labeler.Label([]byte("test 123"))) +} + +func TestLabelerPassesAlongMessageContext(t *testing.T) { + + labeler := NewLabeler([]Heuristic{ + &mockHeuristic{ + processFunc: func(context *messageContext) bool { + assert.Equal(t, "test 123", string(context.rawMessage)) + return false + }, + }, + }) + + labeler.Label([]byte("test 123")) +} diff --git a/pkg/logs/internal/decoder/auto_multiline_handler.go b/pkg/logs/internal/decoder/auto_multiline_handler.go index 894561f12289a..2dc72d0f84c4d 100644 --- a/pkg/logs/internal/decoder/auto_multiline_handler.go +++ b/pkg/logs/internal/decoder/auto_multiline_handler.go @@ -3,247 +3,44 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016-present Datadog, Inc. -//nolint:revive // TODO(AML) Fix revive linter package decoder import ( - "fmt" - "regexp" - "sort" - "sync" "time" - "github.com/benbjohnson/clock" - + automultilinedetection "github.com/DataDog/datadog-agent/pkg/logs/internal/decoder/auto_multiline_detection" "github.com/DataDog/datadog-agent/pkg/logs/message" - "github.com/DataDog/datadog-agent/pkg/logs/sources" - status "github.com/DataDog/datadog-agent/pkg/logs/status/utils" - "github.com/DataDog/datadog-agent/pkg/telemetry" - "github.com/DataDog/datadog-agent/pkg/util/log" ) -const autoMultiLineTelemetryMetricName = "datadog.logs_agent.auto_multi_line" - -type scoredPattern struct { - score int - regexp *regexp.Regexp -} - -// DetectedPattern is a container to safely access a detected multiline pattern -type DetectedPattern struct { - sync.Mutex - pattern *regexp.Regexp -} - -// Set sets the pattern -func (d *DetectedPattern) Set(pattern *regexp.Regexp) { - d.Lock() - defer d.Unlock() - d.pattern = pattern -} - -// Get gets the pattern -func (d *DetectedPattern) Get() *regexp.Regexp { - d.Lock() - defer d.Unlock() - return d.pattern -} - -// AutoMultilineHandler can attempts to detect a known/commob pattern (a timestamp) in the logs -// and will switch to a MultiLine handler if one is detected and the thresholds are met. +// AutoMultilineHandler aggreagates multiline logs. type AutoMultilineHandler struct { - multiLineHandler *MultiLineHandler - singleLineHandler *SingleLineHandler - outputFn func(*message.Message) - isRunning bool - linesToAssess int - linesTested int - lineLimit int - matchThreshold float64 - scoredMatches []*scoredPattern - processFunc func(message *message.Message) - flushTimeout time.Duration - source *sources.ReplaceableSource - matchTimeout time.Duration - timeoutTimer *clock.Timer - detectedPattern *DetectedPattern - clk clock.Clock - autoMultiLineStatus *status.MappedInfo - tailerInfo *status.InfoRegistry + labeler *automultilinedetection.Labeler + aggregator *automultilinedetection.Aggregator } -// NewAutoMultilineHandler returns a new AutoMultilineHandler. -func NewAutoMultilineHandler( - outputFn func(*message.Message), - lineLimit, linesToAssess int, - matchThreshold float64, - matchTimeout time.Duration, - flushTimeout time.Duration, - source *sources.ReplaceableSource, - additionalPatterns []*regexp.Regexp, - detectedPattern *DetectedPattern, - tailerInfo *status.InfoRegistry, -) *AutoMultilineHandler { - - // Put the user patterns at the beginning of the list so we prioritize them if there is a conflicting match. - patterns := append(additionalPatterns, formatsToTry...) +// NewAutoMultilineHandler creates a new auto multiline handler. +func NewAutoMultilineHandler(outputFn func(m *message.Message), maxContentSize int, flushTimeout time.Duration) *AutoMultilineHandler { - scoredMatches := make([]*scoredPattern, len(patterns)) - for i, v := range patterns { - scoredMatches[i] = &scoredPattern{ - score: 0, - regexp: v, - } - } - h := &AutoMultilineHandler{ - outputFn: outputFn, - isRunning: true, - lineLimit: lineLimit, - matchThreshold: matchThreshold, - scoredMatches: scoredMatches, - linesToAssess: linesToAssess, - flushTimeout: flushTimeout, - source: source, - matchTimeout: matchTimeout, - timeoutTimer: nil, - detectedPattern: detectedPattern, - clk: clock.New(), - autoMultiLineStatus: status.NewMappedInfo("Auto Multi-line"), - tailerInfo: tailerInfo, + // Order is important + heuristics := []automultilinedetection.Heuristic{ + automultilinedetection.NewJSONDetector(), } - h.singleLineHandler = NewSingleLineHandler(outputFn, lineLimit) - h.processFunc = h.processAndTry - tailerInfo.Register(h.autoMultiLineStatus) - h.autoMultiLineStatus.SetMessage("state", "Waiting for logs") - - return h -} - -func (h *AutoMultilineHandler) process(message *message.Message) { - h.processFunc(message) -} - -func (h *AutoMultilineHandler) flushChan() <-chan time.Time { - if h.singleLineHandler != nil { - return h.singleLineHandler.flushChan() + return &AutoMultilineHandler{ + labeler: automultilinedetection.NewLabeler(heuristics), + aggregator: automultilinedetection.NewAggregator(outputFn, maxContentSize, flushTimeout), } - return h.multiLineHandler.flushChan() } -func (h *AutoMultilineHandler) flush() { - if h.singleLineHandler != nil { - h.singleLineHandler.flush() - } else { - h.multiLineHandler.flush() - } +func (a *AutoMultilineHandler) process(msg *message.Message) { + label := a.labeler.Label(msg.GetContent()) + a.aggregator.Aggregate(msg, label) } -func (h *AutoMultilineHandler) processAndTry(message *message.Message) { - // Process message before anything else - h.singleLineHandler.process(message) - - for i, scoredPattern := range h.scoredMatches { - match := scoredPattern.regexp.Match(message.GetContent()) - if match { - scoredPattern.score++ - - // By keeping the scored matches sorted, the best match always comes first. Since we expect one timestamp to match overwhelmingly - // it should match most often causing few re-sorts. - if i != 0 { - sort.Slice(h.scoredMatches, func(i, j int) bool { - return h.scoredMatches[i].score > h.scoredMatches[j].score - }) - } - break - } - } - - if h.timeoutTimer == nil { - h.timeoutTimer = h.clk.Timer(h.matchTimeout) - } - - h.linesTested++ - - timeout := false - select { - case <-h.timeoutTimer.C: - log.Debug("Multiline auto detect timed out before reaching line test threshold") - h.autoMultiLineStatus.SetMessage("message2", fmt.Sprintf("Timeout reached. Processed (%d of %d) logs during detection", h.linesTested, h.linesToAssess)) - timeout = true - break - default: - } - - h.autoMultiLineStatus.SetMessage("state", "State: Using auto multi-line handler") - h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("Detecting (%d of %d)", h.linesTested, h.linesToAssess)) - - if h.linesTested >= h.linesToAssess || timeout { - topMatch := h.scoredMatches[0] - matchRatio := float64(topMatch.score) / float64(h.linesTested) - - if matchRatio >= h.matchThreshold { - h.autoMultiLineStatus.SetMessage("state", "State: Using multi-line handler") - h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("Pattern %v matched %d lines with a ratio of %f", topMatch.regexp.String(), topMatch.score, matchRatio)) - log.Debug(fmt.Sprintf("Pattern %v matched %d lines with a ratio of %f - using multi-line handler", topMatch.regexp.String(), topMatch.score, matchRatio)) - telemetry.GetStatsTelemetryProvider().Count(autoMultiLineTelemetryMetricName, 1, []string{"success:true"}) - - h.detectedPattern.Set(topMatch.regexp) - h.switchToMultilineHandler(topMatch.regexp) - } else { - h.autoMultiLineStatus.SetMessage("state", "State: Using single-line handler") - h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("No pattern met the line match threshold: %f during multiline auto detection. Top match was %v with a match ratio of: %f", h.matchThreshold, topMatch.regexp.String(), matchRatio)) - log.Debugf(fmt.Sprintf("No pattern met the line match threshold: %f during multiline auto detection. Top match was %v with a match ratio of: %f - using single-line handler", h.matchThreshold, topMatch.regexp.String(), matchRatio)) - telemetry.GetStatsTelemetryProvider().Count(autoMultiLineTelemetryMetricName, 1, []string{"success:false"}) - - // Stay with the single line handler and no longer attempt to detect multiline matches. - h.processFunc = h.singleLineHandler.process - } - } -} - -func (h *AutoMultilineHandler) switchToMultilineHandler(r *regexp.Regexp) { - h.isRunning = false - h.singleLineHandler = nil - - // Build and start a multiline-handler - h.multiLineHandler = NewMultiLineHandler(h.outputFn, r, h.flushTimeout, h.lineLimit, true, h.tailerInfo) - h.source.RegisterInfo(h.multiLineHandler.countInfo) - h.source.RegisterInfo(h.multiLineHandler.linesCombinedInfo) - // stay with the multiline handler - h.processFunc = h.multiLineHandler.process +func (a *AutoMultilineHandler) flushChan() <-chan time.Time { + return a.aggregator.FlushChan() } -// Originally referenced from https://github.com/egnyte/ax/blob/master/pkg/heuristic/timestamp.go -// All line matching rules must only match the beginning of a line, so when adding new expressions -// make sure to prepend it with `^` -var formatsToTry = []*regexp.Regexp{ - // time.RFC3339, - regexp.MustCompile(`^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?(Z\d*:?\d*)?`), - // time.ANSIC, - regexp.MustCompile(`^[A-Za-z_]+ [A-Za-z_]+ +\d+ \d+:\d+:\d+ \d+`), - // time.UnixDate, - regexp.MustCompile(`^[A-Za-z_]+ [A-Za-z_]+ +\d+ \d+:\d+:\d+( [A-Za-z_]+ \d+)?`), - // time.RubyDate, - regexp.MustCompile(`^[A-Za-z_]+ [A-Za-z_]+ \d+ \d+:\d+:\d+ [\-\+]\d+ \d+`), - // time.RFC822, - regexp.MustCompile(`^\d+ [A-Za-z_]+ \d+ \d+:\d+ [A-Za-z_]+`), - // time.RFC822Z, - regexp.MustCompile(`^\d+ [A-Za-z_]+ \d+ \d+:\d+ -\d+`), - // time.RFC850, - regexp.MustCompile(`^[A-Za-z_]+, \d+-[A-Za-z_]+-\d+ \d+:\d+:\d+ [A-Za-z_]+`), - // time.RFC1123, - regexp.MustCompile(`^[A-Za-z_]+, \d+ [A-Za-z_]+ \d+ \d+:\d+:\d+ [A-Za-z_]+`), - // time.RFC1123Z, - regexp.MustCompile(`^[A-Za-z_]+, \d+ [A-Za-z_]+ \d+ \d+:\d+:\d+ -\d+`), - // time.RFC3339Nano, - regexp.MustCompile(`^\d+-\d+-\d+[A-Za-z_]+\d+:\d+:\d+\.\d+[A-Za-z_]+\d+:\d+`), - // 2021-07-08 05:08:19,214 - regexp.MustCompile(`^\d+-\d+-\d+ \d+:\d+:\d+(,\d+)?`), - // Default java logging SimpleFormatter date format - regexp.MustCompile(`^[A-Za-z_]+ \d+, \d+ \d+:\d+:\d+ (AM|PM)`), - // 2021-01-31 - with stricter matching around the months/days - regexp.MustCompile(`^\d{4}-(1[012]|0?[1-9])-([12][0-9]|3[01]|0?[1-9])`), - // 2023/02/20 14:33:24 - regexp.MustCompile(`^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}`), +func (a *AutoMultilineHandler) flush() { + a.aggregator.Flush() } diff --git a/pkg/logs/internal/decoder/decoder.go b/pkg/logs/internal/decoder/decoder.go index 4b4bd26578734..d3fceec44caa5 100644 --- a/pkg/logs/internal/decoder/decoder.go +++ b/pkg/logs/internal/decoder/decoder.go @@ -29,23 +29,6 @@ func NewInput(content []byte) *message.Message { return message.NewMessage(content, nil, "", time.Now().UnixNano()) } -// NewMessage returns a new encoded message. -func NewMessage(content []byte, status string, rawDataLen int, readTimestamp string) *message.Message { - msg := message.Message{ - MessageContent: message.MessageContent{ - State: message.StateEncoded, - }, - Status: status, - RawDataLen: rawDataLen, - IngestionTimestamp: time.Now().UnixNano(), - ParsingExtra: message.ParsingExtra{ - Timestamp: readTimestamp, - }, - } - msg.SetContent(content) - return &msg -} - // Decoder translates a sequence of byte buffers (such as from a file or a // network socket) into log messages. // @@ -100,7 +83,7 @@ func syncSourceInfo(source *sources.ReplaceableSource, lh *MultiLineHandler) { func NewDecoderWithFraming(source *sources.ReplaceableSource, parser parsers.Parser, framing framer.Framing, multiLinePattern *regexp.Regexp, tailerInfo *status.InfoRegistry) *Decoder { inputChan := make(chan *message.Message) outputChan := make(chan *message.Message) - lineLimit := config.MaxMessageSizeBytes(pkgConfig.Datadog()) + maxContentSize := config.MaxMessageSizeBytes(pkgConfig.Datadog()) detectedPattern := &DetectedPattern{} outputFn := func(m *message.Message) { outputChan <- m } @@ -109,13 +92,16 @@ func NewDecoderWithFraming(source *sources.ReplaceableSource, parser parsers.Par var lineHandler LineHandler for _, rule := range source.Config().ProcessingRules { if rule.Type == config.MultiLine { - lh := NewMultiLineHandler(outputFn, rule.Regex, config.AggregationTimeout(pkgConfig.Datadog()), lineLimit, false, tailerInfo) + lh := NewMultiLineHandler(outputFn, rule.Regex, config.AggregationTimeout(pkgConfig.Datadog()), maxContentSize, false, tailerInfo) syncSourceInfo(source, lh) lineHandler = lh } } if lineHandler == nil { - if source.Config().AutoMultiLineEnabled(pkgConfig.Datadog()) { + if pkgConfig.Datadog().GetBool("logs_config.experimental_auto_multi_line_detection") { + lineHandler = NewAutoMultilineHandler(outputFn, maxContentSize, config.AggregationTimeout(pkgConfig.Datadog())) + + } else if source.Config().AutoMultiLineEnabled(pkgConfig.Datadog()) { log.Infof("Auto multi line log detection enabled") if multiLinePattern != nil { @@ -124,32 +110,32 @@ func NewDecoderWithFraming(source *sources.ReplaceableSource, parser parsers.Par // Save the pattern again for the next rotation detectedPattern.Set(multiLinePattern) - lh := NewMultiLineHandler(outputFn, multiLinePattern, config.AggregationTimeout(pkgConfig.Datadog()), lineLimit, true, tailerInfo) + lh := NewMultiLineHandler(outputFn, multiLinePattern, config.AggregationTimeout(pkgConfig.Datadog()), maxContentSize, true, tailerInfo) syncSourceInfo(source, lh) lineHandler = lh } else { - lineHandler = buildAutoMultilineHandlerFromConfig(outputFn, lineLimit, source, detectedPattern, tailerInfo) + lineHandler = buildLegacyAutoMultilineHandlerFromConfig(outputFn, maxContentSize, source, detectedPattern, tailerInfo) } } else { - lineHandler = NewSingleLineHandler(outputFn, lineLimit) + lineHandler = NewSingleLineHandler(outputFn, maxContentSize) } } // construct the lineParser, wrapping the parser var lineParser LineParser if parser.SupportsPartialLine() { - lineParser = NewMultiLineParser(lineHandler.process, config.AggregationTimeout(pkgConfig.Datadog()), parser, lineLimit) + lineParser = NewMultiLineParser(lineHandler, config.AggregationTimeout(pkgConfig.Datadog()), parser, maxContentSize) } else { - lineParser = NewSingleLineParser(lineHandler.process, parser) + lineParser = NewSingleLineParser(lineHandler, parser) } // construct the framer - framer := framer.NewFramer(lineParser.process, framing, lineLimit) + framer := framer.NewFramer(lineParser.process, framing, maxContentSize) return New(inputChan, outputChan, framer, lineParser, lineHandler, detectedPattern) } -func buildAutoMultilineHandlerFromConfig(outputFn func(*message.Message), lineLimit int, source *sources.ReplaceableSource, detectedPattern *DetectedPattern, tailerInfo *status.InfoRegistry) *AutoMultilineHandler { +func buildLegacyAutoMultilineHandlerFromConfig(outputFn func(*message.Message), maxContentSize int, source *sources.ReplaceableSource, detectedPattern *DetectedPattern, tailerInfo *status.InfoRegistry) *LegacyAutoMultilineHandler { linesToSample := source.Config().AutoMultiLineSampleSize if linesToSample <= 0 { linesToSample = pkgConfig.Datadog().GetInt("logs_config.auto_multi_line_default_sample_size") @@ -171,9 +157,9 @@ func buildAutoMultilineHandlerFromConfig(outputFn func(*message.Message), lineLi } matchTimeout := time.Second * pkgConfig.Datadog().GetDuration("logs_config.auto_multi_line_default_match_timeout") - return NewAutoMultilineHandler( + return NewLegacyAutoMultilineHandler( outputFn, - lineLimit, + maxContentSize, linesToSample, matchThreshold, matchTimeout, diff --git a/pkg/logs/internal/decoder/legacy_auto_multiline_handler.go b/pkg/logs/internal/decoder/legacy_auto_multiline_handler.go new file mode 100644 index 0000000000000..61d9011103463 --- /dev/null +++ b/pkg/logs/internal/decoder/legacy_auto_multiline_handler.go @@ -0,0 +1,249 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +//nolint:revive // TODO(AML) Fix revive linter +package decoder + +import ( + "fmt" + "regexp" + "sort" + "sync" + "time" + + "github.com/benbjohnson/clock" + + "github.com/DataDog/datadog-agent/pkg/logs/message" + "github.com/DataDog/datadog-agent/pkg/logs/sources" + status "github.com/DataDog/datadog-agent/pkg/logs/status/utils" + "github.com/DataDog/datadog-agent/pkg/telemetry" + "github.com/DataDog/datadog-agent/pkg/util/log" +) + +const autoMultiLineTelemetryMetricName = "datadog.logs_agent.auto_multi_line" + +type scoredPattern struct { + score int + regexp *regexp.Regexp +} + +// DetectedPattern is a container to safely access a detected multiline pattern +type DetectedPattern struct { + sync.Mutex + pattern *regexp.Regexp +} + +// Set sets the pattern +func (d *DetectedPattern) Set(pattern *regexp.Regexp) { + d.Lock() + defer d.Unlock() + d.pattern = pattern +} + +// Get gets the pattern +func (d *DetectedPattern) Get() *regexp.Regexp { + d.Lock() + defer d.Unlock() + return d.pattern +} + +// LegacyAutoMultilineHandler can attempts to detect a known/commob pattern (a timestamp) in the logs +// and will switch to a MultiLine handler if one is detected and the thresholds are met. +type LegacyAutoMultilineHandler struct { + multiLineHandler *MultiLineHandler + singleLineHandler *SingleLineHandler + outputFn func(*message.Message) + isRunning bool + linesToAssess int + linesTested int + lineLimit int + matchThreshold float64 + scoredMatches []*scoredPattern + processFunc func(message *message.Message) + flushTimeout time.Duration + source *sources.ReplaceableSource + matchTimeout time.Duration + timeoutTimer *clock.Timer + detectedPattern *DetectedPattern + clk clock.Clock + autoMultiLineStatus *status.MappedInfo + tailerInfo *status.InfoRegistry +} + +// NewLegacyAutoMultilineHandler returns a new LegacyAutoMultilineHandler. +func NewLegacyAutoMultilineHandler( + outputFn func(*message.Message), + lineLimit, linesToAssess int, + matchThreshold float64, + matchTimeout time.Duration, + flushTimeout time.Duration, + source *sources.ReplaceableSource, + additionalPatterns []*regexp.Regexp, + detectedPattern *DetectedPattern, + tailerInfo *status.InfoRegistry, +) *LegacyAutoMultilineHandler { + + // Put the user patterns at the beginning of the list so we prioritize them if there is a conflicting match. + patterns := append(additionalPatterns, formatsToTry...) + + scoredMatches := make([]*scoredPattern, len(patterns)) + for i, v := range patterns { + scoredMatches[i] = &scoredPattern{ + score: 0, + regexp: v, + } + } + h := &LegacyAutoMultilineHandler{ + outputFn: outputFn, + isRunning: true, + lineLimit: lineLimit, + matchThreshold: matchThreshold, + scoredMatches: scoredMatches, + linesToAssess: linesToAssess, + flushTimeout: flushTimeout, + source: source, + matchTimeout: matchTimeout, + timeoutTimer: nil, + detectedPattern: detectedPattern, + clk: clock.New(), + autoMultiLineStatus: status.NewMappedInfo("Auto Multi-line"), + tailerInfo: tailerInfo, + } + + h.singleLineHandler = NewSingleLineHandler(outputFn, lineLimit) + h.processFunc = h.processAndTry + tailerInfo.Register(h.autoMultiLineStatus) + h.autoMultiLineStatus.SetMessage("state", "Waiting for logs") + + return h +} + +func (h *LegacyAutoMultilineHandler) process(message *message.Message) { + h.processFunc(message) +} + +func (h *LegacyAutoMultilineHandler) flushChan() <-chan time.Time { + if h.singleLineHandler != nil { + return h.singleLineHandler.flushChan() + } + return h.multiLineHandler.flushChan() +} + +func (h *LegacyAutoMultilineHandler) flush() { + if h.singleLineHandler != nil { + h.singleLineHandler.flush() + } else { + h.multiLineHandler.flush() + } +} + +func (h *LegacyAutoMultilineHandler) processAndTry(message *message.Message) { + // Process message before anything else + h.singleLineHandler.process(message) + + for i, scoredPattern := range h.scoredMatches { + match := scoredPattern.regexp.Match(message.GetContent()) + if match { + scoredPattern.score++ + + // By keeping the scored matches sorted, the best match always comes first. Since we expect one timestamp to match overwhelmingly + // it should match most often causing few re-sorts. + if i != 0 { + sort.Slice(h.scoredMatches, func(i, j int) bool { + return h.scoredMatches[i].score > h.scoredMatches[j].score + }) + } + break + } + } + + if h.timeoutTimer == nil { + h.timeoutTimer = h.clk.Timer(h.matchTimeout) + } + + h.linesTested++ + + timeout := false + select { + case <-h.timeoutTimer.C: + log.Debug("Multiline auto detect timed out before reaching line test threshold") + h.autoMultiLineStatus.SetMessage("message2", fmt.Sprintf("Timeout reached. Processed (%d of %d) logs during detection", h.linesTested, h.linesToAssess)) + timeout = true + break + default: + } + + h.autoMultiLineStatus.SetMessage("state", "State: Using auto multi-line handler") + h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("Detecting (%d of %d)", h.linesTested, h.linesToAssess)) + + if h.linesTested >= h.linesToAssess || timeout { + topMatch := h.scoredMatches[0] + matchRatio := float64(topMatch.score) / float64(h.linesTested) + + if matchRatio >= h.matchThreshold { + h.autoMultiLineStatus.SetMessage("state", "State: Using multi-line handler") + h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("Pattern %v matched %d lines with a ratio of %f", topMatch.regexp.String(), topMatch.score, matchRatio)) + log.Debug(fmt.Sprintf("Pattern %v matched %d lines with a ratio of %f - using multi-line handler", topMatch.regexp.String(), topMatch.score, matchRatio)) + telemetry.GetStatsTelemetryProvider().Count(autoMultiLineTelemetryMetricName, 1, []string{"success:true"}) + + h.detectedPattern.Set(topMatch.regexp) + h.switchToMultilineHandler(topMatch.regexp) + } else { + h.autoMultiLineStatus.SetMessage("state", "State: Using single-line handler") + h.autoMultiLineStatus.SetMessage("message", fmt.Sprintf("No pattern met the line match threshold: %f during multiline auto detection. Top match was %v with a match ratio of: %f", h.matchThreshold, topMatch.regexp.String(), matchRatio)) + log.Debugf(fmt.Sprintf("No pattern met the line match threshold: %f during multiline auto detection. Top match was %v with a match ratio of: %f - using single-line handler", h.matchThreshold, topMatch.regexp.String(), matchRatio)) + telemetry.GetStatsTelemetryProvider().Count(autoMultiLineTelemetryMetricName, 1, []string{"success:false"}) + + // Stay with the single line handler and no longer attempt to detect multiline matches. + h.processFunc = h.singleLineHandler.process + } + } +} + +func (h *LegacyAutoMultilineHandler) switchToMultilineHandler(r *regexp.Regexp) { + h.isRunning = false + h.singleLineHandler = nil + + // Build and start a multiline-handler + h.multiLineHandler = NewMultiLineHandler(h.outputFn, r, h.flushTimeout, h.lineLimit, true, h.tailerInfo) + h.source.RegisterInfo(h.multiLineHandler.countInfo) + h.source.RegisterInfo(h.multiLineHandler.linesCombinedInfo) + // stay with the multiline handler + h.processFunc = h.multiLineHandler.process +} + +// Originally referenced from https://github.com/egnyte/ax/blob/master/pkg/heuristic/timestamp.go +// All line matching rules must only match the beginning of a line, so when adding new expressions +// make sure to prepend it with `^` +var formatsToTry = []*regexp.Regexp{ + // time.RFC3339, + regexp.MustCompile(`^\d+-\d+-\d+T\d+:\d+:\d+(\.\d+)?(Z\d*:?\d*)?`), + // time.ANSIC, + regexp.MustCompile(`^[A-Za-z_]+ [A-Za-z_]+ +\d+ \d+:\d+:\d+ \d+`), + // time.UnixDate, + regexp.MustCompile(`^[A-Za-z_]+ [A-Za-z_]+ +\d+ \d+:\d+:\d+( [A-Za-z_]+ \d+)?`), + // time.RubyDate, + regexp.MustCompile(`^[A-Za-z_]+ [A-Za-z_]+ \d+ \d+:\d+:\d+ [\-\+]\d+ \d+`), + // time.RFC822, + regexp.MustCompile(`^\d+ [A-Za-z_]+ \d+ \d+:\d+ [A-Za-z_]+`), + // time.RFC822Z, + regexp.MustCompile(`^\d+ [A-Za-z_]+ \d+ \d+:\d+ -\d+`), + // time.RFC850, + regexp.MustCompile(`^[A-Za-z_]+, \d+-[A-Za-z_]+-\d+ \d+:\d+:\d+ [A-Za-z_]+`), + // time.RFC1123, + regexp.MustCompile(`^[A-Za-z_]+, \d+ [A-Za-z_]+ \d+ \d+:\d+:\d+ [A-Za-z_]+`), + // time.RFC1123Z, + regexp.MustCompile(`^[A-Za-z_]+, \d+ [A-Za-z_]+ \d+ \d+:\d+:\d+ -\d+`), + // time.RFC3339Nano, + regexp.MustCompile(`^\d+-\d+-\d+[A-Za-z_]+\d+:\d+:\d+\.\d+[A-Za-z_]+\d+:\d+`), + // 2021-07-08 05:08:19,214 + regexp.MustCompile(`^\d+-\d+-\d+ \d+:\d+:\d+(,\d+)?`), + // Default java logging SimpleFormatter date format + regexp.MustCompile(`^[A-Za-z_]+ \d+, \d+ \d+:\d+:\d+ (AM|PM)`), + // 2021-01-31 - with stricter matching around the months/days + regexp.MustCompile(`^\d{4}-(1[012]|0?[1-9])-([12][0-9]|3[01]|0?[1-9])`), + // 2023/02/20 14:33:24 + regexp.MustCompile(`^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}`), +} diff --git a/pkg/logs/internal/decoder/line_handler.go b/pkg/logs/internal/decoder/line_handler.go index a3db6e5b451dc..5834ce1d2ea75 100644 --- a/pkg/logs/internal/decoder/line_handler.go +++ b/pkg/logs/internal/decoder/line_handler.go @@ -11,16 +11,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/logs/message" ) -// truncatedFlag is the flag that is added at the beginning -// or/and at the end of every trucated lines. -var truncatedFlag = []byte("...TRUNCATED...") - -// escapedLineFeed is used to escape new line character -// for multiline message. -// New line character needs to be escaped because they are used -// as delimiter for transport. -var escapedLineFeed = []byte(`\n`) - // LineHandler handles raw lines to form structured lines. type LineHandler interface { // process handles a new line (message) diff --git a/pkg/logs/internal/decoder/line_handler_benchmark_test.go b/pkg/logs/internal/decoder/line_handler_benchmark_test.go index 63d8ccf934d1c..85d3266c920f4 100644 --- a/pkg/logs/internal/decoder/line_handler_benchmark_test.go +++ b/pkg/logs/internal/decoder/line_handler_benchmark_test.go @@ -41,7 +41,7 @@ func benchmarkAutoMultiLineHandler(b *testing.B, logs int, line string) { } source := sources.NewReplaceableSource(sources.NewLogSource("config", &config.LogsConfig{})) - h := NewAutoMultilineHandler(func(*message.Message) {}, coreConfig.DefaultMaxMessageSizeBytes, 1000, 0.9, 30*time.Second, 1000*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) + h := NewLegacyAutoMultilineHandler(func(*message.Message) {}, coreConfig.DefaultMaxMessageSizeBytes, 1000, 0.9, 30*time.Second, 1000*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) b.ResetTimer() for n := 0; n < b.N; n++ { diff --git a/pkg/logs/internal/decoder/line_handler_test.go b/pkg/logs/internal/decoder/line_handler_test.go index fea5e6676a5bd..e7de9ba2fb9fb 100644 --- a/pkg/logs/internal/decoder/line_handler_test.go +++ b/pkg/logs/internal/decoder/line_handler_test.go @@ -25,11 +25,11 @@ const whitespace = "\t\n\v\f\r\u0085\u00a0 " const contentLenLimit = 100 func getDummyMessage(content string) *message.Message { - return NewMessage([]byte(content), "info", len(content), "2018-06-14T18:27:03.246999277Z") + return message.NewRawMessage([]byte(content), "info", len(content), "2018-06-14T18:27:03.246999277Z") } func getDummyMessageWithLF(content string) *message.Message { - return NewMessage([]byte(content), "info", len(content)+1, "2018-06-14T18:27:03.246999277Z") + return message.NewRawMessage([]byte(content), "info", len(content)+1, "2018-06-14T18:27:03.246999277Z") } func lineHandlerChans() (func(*message.Message), chan *message.Message) { @@ -63,19 +63,19 @@ func TestSingleLineHandler(t *testing.T) { line = strings.Repeat("a", contentLenLimit+10) h.process(getDummyMessage(line)) output = <-outputChan - assert.Equal(t, len(line)+len(truncatedFlag), len(output.GetContent())) + assert.Equal(t, len(line)+len(message.TruncatedFlag), len(output.GetContent())) assert.Equal(t, len(line), output.RawDataLen) line = strings.Repeat("a", contentLenLimit+10) h.process(getDummyMessage(line)) output = <-outputChan - assert.Equal(t, len(truncatedFlag)+len(line)+len(truncatedFlag), len(output.GetContent())) + assert.Equal(t, len(message.TruncatedFlag)+len(line)+len(message.TruncatedFlag), len(output.GetContent())) assert.Equal(t, len(line), output.RawDataLen) line = strings.Repeat("a", 10) h.process(getDummyMessageWithLF(line)) output = <-outputChan - assert.Equal(t, string(truncatedFlag)+line, string(output.GetContent())) + assert.Equal(t, string(message.TruncatedFlag)+line, string(output.GetContent())) assert.Equal(t, len(line)+1, output.RawDataLen) } @@ -257,7 +257,7 @@ func TestAutoMultiLineHandlerStaysSingleLineMode(t *testing.T) { outputFn, outputChan := lineHandlerChans() source := sources.NewReplaceableSource(sources.NewLogSource("config", &config.LogsConfig{})) detectedPattern := &DetectedPattern{} - h := NewAutoMultilineHandler(outputFn, 100, 5, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, detectedPattern, status.NewInfoRegistry()) + h := NewLegacyAutoMultilineHandler(outputFn, 100, 5, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, detectedPattern, status.NewInfoRegistry()) for i := 0; i < 6; i++ { h.process(getDummyMessageWithLF("blah")) @@ -272,7 +272,7 @@ func TestAutoMultiLineHandlerSwitchesToMultiLineMode(t *testing.T) { outputFn, outputChan := lineHandlerChans() source := sources.NewReplaceableSource(sources.NewLogSource("config", &config.LogsConfig{})) detectedPattern := &DetectedPattern{} - h := NewAutoMultilineHandler(outputFn, 100, 5, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, detectedPattern, status.NewInfoRegistry()) + h := NewLegacyAutoMultilineHandler(outputFn, 100, 5, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, detectedPattern, status.NewInfoRegistry()) for i := 0; i < 6; i++ { h.process(getDummyMessageWithLF("Jul 12, 2021 12:55:15 PM test message")) @@ -287,7 +287,7 @@ func TestAutoMultiLineHandlerSwitchesToMultiLineMode(t *testing.T) { func TestAutoMultiLineHandlerHandelsMessage(t *testing.T) { outputFn, outputChan := lineHandlerChans() source := sources.NewReplaceableSource(sources.NewLogSource("config", &config.LogsConfig{})) - h := NewAutoMultilineHandler(outputFn, 500, 1, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) + h := NewLegacyAutoMultilineHandler(outputFn, 500, 1, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) h.process(getDummyMessageWithLF("Jul 12, 2021 12:55:15 PM test message 1")) <-outputChan @@ -305,7 +305,7 @@ func TestAutoMultiLineHandlerHandelsMessage(t *testing.T) { func TestAutoMultiLineHandlerHandelsMessageConflictingPatterns(t *testing.T) { outputFn, outputChan := lineHandlerChans() source := sources.NewReplaceableSource(sources.NewLogSource("config", &config.LogsConfig{})) - h := NewAutoMultilineHandler(outputFn, 500, 4, 0.75, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) + h := NewLegacyAutoMultilineHandler(outputFn, 500, 4, 0.75, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) // we will match both patterns, but one will win with a threshold of 0.75 h.process(getDummyMessageWithLF("Jul 12, 2021 12:55:15 PM test message 1")) @@ -330,7 +330,7 @@ func TestAutoMultiLineHandlerHandelsMessageConflictingPatterns(t *testing.T) { func TestAutoMultiLineHandlerHandelsMessageConflictingPatternsNoWinner(t *testing.T) { outputFn, outputChan := lineHandlerChans() source := sources.NewReplaceableSource(sources.NewLogSource("config", &config.LogsConfig{})) - h := NewAutoMultilineHandler(outputFn, 500, 4, 0.75, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) + h := NewLegacyAutoMultilineHandler(outputFn, 500, 4, 0.75, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, &DetectedPattern{}, status.NewInfoRegistry()) // we will match both patterns, but neither will win because it doesn't meet the threshold h.process(getDummyMessageWithLF("Jul 12, 2021 12:55:15 PM test message 1")) @@ -355,7 +355,7 @@ func TestAutoMultiLineHandlerSwitchesToMultiLineModeWithDelay(t *testing.T) { source := sources.NewReplaceableSource(sources.NewLogSource("config", &config.LogsConfig{})) detectedPattern := &DetectedPattern{} - h := NewAutoMultilineHandler(outputFn, 100, 5, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, detectedPattern, status.NewInfoRegistry()) + h := NewLegacyAutoMultilineHandler(outputFn, 100, 5, 1.0, 250*time.Millisecond, 250*time.Millisecond, source, []*regexp.Regexp{}, detectedPattern, status.NewInfoRegistry()) clock := clock.NewMock() h.clk = clock diff --git a/pkg/logs/internal/decoder/line_parser.go b/pkg/logs/internal/decoder/line_parser.go index 28d8c53c765e6..e6da2dd50c9a0 100644 --- a/pkg/logs/internal/decoder/line_parser.go +++ b/pkg/logs/internal/decoder/line_parser.go @@ -31,17 +31,17 @@ type LineParser interface { // SingleLineParser makes sure that multiple lines from a same content // are properly put together. type SingleLineParser struct { - outputFn func(*message.Message) - parser parsers.Parser + lineHandler LineHandler + parser parsers.Parser } // NewSingleLineParser returns a new SingleLineParser. func NewSingleLineParser( - outputFn func(*message.Message), + lineHandler LineHandler, parser parsers.Parser) *SingleLineParser { return &SingleLineParser{ - outputFn: outputFn, - parser: parser, + lineHandler: lineHandler, + parser: parser, } } @@ -60,12 +60,12 @@ func (p *SingleLineParser) process(input *message.Message, rawDataLen int) { log.Debug(err) } input.RawDataLen = rawDataLen - p.outputFn(input) + p.lineHandler.process(input) } // MultiLineParser makes sure that chunked lines are properly put together. type MultiLineParser struct { - outputFn func(*message.Message) + lineHandler LineHandler // used to reconstruct the message @@ -83,13 +83,13 @@ type MultiLineParser struct { // NewMultiLineParser returns a new MultiLineParser. func NewMultiLineParser( - outputFn func(*message.Message), + lineHandler LineHandler, flushTimeout time.Duration, parser parsers.Parser, lineLimit int, ) *MultiLineParser { return &MultiLineParser{ - outputFn: outputFn, + lineHandler: lineHandler, buffer: bytes.NewBuffer(nil), bufferedMsg: nil, flushTimeout: flushTimeout, @@ -159,6 +159,6 @@ func (p *MultiLineParser) sendLine() { if len(content) > 0 || p.rawDataLen > 0 { p.bufferedMsg.RawDataLen = p.rawDataLen p.bufferedMsg.SetContent(content) - p.outputFn(p.bufferedMsg) + p.lineHandler.process(p.bufferedMsg) } } diff --git a/pkg/logs/internal/decoder/line_parser_test.go b/pkg/logs/internal/decoder/line_parser_test.go index 564ec3e35a648..fba313e4ee627 100644 --- a/pkg/logs/internal/decoder/line_parser_test.go +++ b/pkg/logs/internal/decoder/line_parser_test.go @@ -20,11 +20,25 @@ import ( const header = "HEADER" -func lineParserChans() (func(*message.Message), chan *message.Message) { - ch := make(chan *message.Message, 20) - return func(m *message.Message) { ch <- m }, ch +type MockLineHandler struct { + ch chan *message.Message } +func NewMockLineHandler() *MockLineHandler { + return &MockLineHandler{ + ch: make(chan *message.Message, 20), + } +} + +func (m *MockLineHandler) process(msg *message.Message) { + m.ch <- msg +} + +func (m *MockLineHandler) flushChan() <-chan time.Time { + return nil +} +func (m *MockLineHandler) flush() {} + type MockFailingParser struct { header []byte } @@ -60,22 +74,22 @@ func (u *MockFailingParser) SupportsPartialLine() bool { func TestSingleLineParser(t *testing.T) { p := NewMockFailingParser(header) - outputFn, outputChan := lineParserChans() - lineParser := NewSingleLineParser(outputFn, p) + lineHandler := NewMockLineHandler() + lineParser := NewSingleLineParser(lineHandler, p) line := header logMessage := message.NewMessage([]byte(line), nil, "", 0) inputLen := len(logMessage.GetContent()) + 1 lineParser.process(logMessage, inputLen) - message := <-outputChan + message := <-lineHandler.ch assert.Equal(t, "", string(message.GetContent())) assert.Equal(t, inputLen, message.RawDataLen) logMessage.SetContent([]byte(line + "one message")) inputLen = len(logMessage.GetContent()) + 1 lineParser.process(logMessage, inputLen) - message = <-outputChan + message = <-lineHandler.ch assert.Equal(t, []byte("one message"), message.GetContent()) assert.Equal(t, inputLen, message.RawDataLen) } @@ -83,13 +97,13 @@ func TestSingleLineParser(t *testing.T) { func TestSingleLineParserSendsRawInvalidMessages(t *testing.T) { p := NewMockFailingParser(header) - outputFn, outputChan := lineParserChans() - lineParser := NewSingleLineParser(outputFn, p) + lineHandler := NewMockLineHandler() + lineParser := NewSingleLineParser(lineHandler, p) logMessage := message.NewMessage([]byte("one message"), nil, "", 0) lineParser.process(logMessage, 12) - message := <-outputChan + message := <-lineHandler.ch assert.Equal(t, "one message", string(message.GetContent())) } @@ -98,8 +112,8 @@ func TestMultilineParser(t *testing.T) { timeout := 1000 * time.Millisecond contentLenLimit := 256 * 100 - outputFn, outputChan := lineParserChans() - lineParser := NewMultiLineParser(outputFn, timeout, p, contentLenLimit) + lineHandler := NewMockLineHandler() + lineParser := NewMultiLineParser(lineHandler, timeout, p, contentLenLimit) logMessage := message.NewMessage([]byte(header+"one "), nil, "", 0) @@ -111,7 +125,7 @@ func TestMultilineParser(t *testing.T) { logMessage.SetContent([]byte(header + "line\\n")) lineParser.process(logMessage, 14) - message := <-outputChan + message := <-lineHandler.ch assert.Equal(t, "one long line", string(message.GetContent())) assert.Equal(t, message.RawDataLen, 11+12+14) @@ -122,8 +136,8 @@ func TestMultilineParserTimeout(t *testing.T) { timeout := 100 * time.Millisecond contentLenLimit := 256 * 100 - outputFn, outputChan := lineParserChans() - lineParser := NewMultiLineParser(outputFn, timeout, p, contentLenLimit) + lineHandler := NewMockLineHandler() + lineParser := NewMultiLineParser(lineHandler, timeout, p, contentLenLimit) logMessage := message.NewMessage([]byte(header+"message"), nil, "", 0) @@ -131,14 +145,14 @@ func TestMultilineParserTimeout(t *testing.T) { // shouldn't be anything here yet select { - case <-outputChan: + case <-lineHandler.ch: panic("shouldn't be a message") default: } lineParser.flush() - message := <-outputChan + message := <-lineHandler.ch assert.Equal(t, "message", string(message.GetContent())) assert.Equal(t, message.RawDataLen, 14) @@ -151,8 +165,8 @@ func TestMultilineParserLimit(t *testing.T) { contentLenLimit := 64 line := strings.Repeat("a", contentLenLimit) - outputFn, outputChan := lineParserChans() - lineParser := NewMultiLineParser(outputFn, timeout, p, contentLenLimit) + lineHandler := NewMockLineHandler() + lineParser := NewMultiLineParser(lineHandler, timeout, p, contentLenLimit) for i := 0; i < 10; i++ { logMessage := message.NewMessage([]byte(header+line), nil, "", 0) @@ -163,12 +177,12 @@ func TestMultilineParserLimit(t *testing.T) { lineParser.process(logMessage, 13) for i := 0; i < 10; i++ { - message := <-outputChan + message := <-lineHandler.ch assert.Equal(t, line, string(message.GetContent())) assert.Equal(t, message.RawDataLen, 7+len(line)) } - message := <-outputChan + message := <-lineHandler.ch assert.Equal(t, "aaaa", string(message.GetContent())) assert.Equal(t, message.RawDataLen, 13) } diff --git a/pkg/logs/internal/decoder/multiline_handler.go b/pkg/logs/internal/decoder/multiline_handler.go index 394073d24f899..dc36002561215 100644 --- a/pkg/logs/internal/decoder/multiline_handler.go +++ b/pkg/logs/internal/decoder/multiline_handler.go @@ -75,7 +75,7 @@ func (h *MultiLineHandler) flush() { // It also makes sure that the content will never exceed the limit // and that the length of the lines is properly tracked // so that the agent restarts tailing from the right place. -func (h *MultiLineHandler) process(message *message.Message) { +func (h *MultiLineHandler) process(msg *message.Message) { if h.flushTimer != nil && h.buffer.Len() > 0 { // stop the flush timer, as we now have data if !h.flushTimer.Stop() { @@ -83,7 +83,7 @@ func (h *MultiLineHandler) process(message *message.Message) { } } - if h.newContentRe.Match(message.GetContent()) { + if h.newContentRe.Match(msg.GetContent()) { h.countInfo.Add(1) // the current line is part of a new message, // send the buffer @@ -95,30 +95,30 @@ func (h *MultiLineHandler) process(message *message.Message) { // track the raw data length and the timestamp so that the agent tails // from the right place at restart - h.linesLen += message.RawDataLen - h.timestamp = message.ParsingExtra.Timestamp - h.status = message.Status + h.linesLen += msg.RawDataLen + h.timestamp = msg.ParsingExtra.Timestamp + h.status = msg.Status h.linesCombined++ if h.buffer.Len() > 0 { // the buffer already contains some data which means that // the current line is not the first line of the message - h.buffer.Write(escapedLineFeed) + h.buffer.Write(message.EscapedLineFeed) } if isTruncated { // the previous line has been truncated because it was too long, // the new line is just a remainder, // adding the truncated flag at the beginning of the content - h.buffer.Write(truncatedFlag) + h.buffer.Write(message.TruncatedFlag) } - h.buffer.Write(message.GetContent()) + h.buffer.Write(msg.GetContent()) if h.buffer.Len() >= h.lineLimit { // the multiline message is too long, it needs to be cut off and send, // adding the truncated flag the end of the content - h.buffer.Write(truncatedFlag) + h.buffer.Write(message.TruncatedFlag) h.sendBuffer() h.shouldTruncate = true } @@ -157,6 +157,6 @@ func (h *MultiLineHandler) sendBuffer() { } } - h.outputFn(NewMessage(content, h.status, h.linesLen, h.timestamp)) + h.outputFn(message.NewRawMessage(content, h.status, h.linesLen, h.timestamp)) } } diff --git a/pkg/logs/internal/decoder/single_line_handler.go b/pkg/logs/internal/decoder/single_line_handler.go index 593e5bbbf191d..e3192474fe04e 100644 --- a/pkg/logs/internal/decoder/single_line_handler.go +++ b/pkg/logs/internal/decoder/single_line_handler.go @@ -40,30 +40,30 @@ func (h *SingleLineHandler) flush() { // it guarantees that the content of the line won't exceed // the limit and that the length of the line is properly tracked // so that the agent restarts tailing from the right place. -func (h *SingleLineHandler) process(message *message.Message) { +func (h *SingleLineHandler) process(msg *message.Message) { isTruncated := h.shouldTruncate h.shouldTruncate = false - content := message.GetContent() + content := msg.GetContent() content = bytes.TrimSpace(content) if isTruncated { // the previous line has been truncated because it was too long, // the new line is just a remainder, // adding the truncated flag at the beginning of the content - content = append(truncatedFlag, content...) + content = append(message.TruncatedFlag, content...) } // how should we detect logs which are too long before rendering them? if len(content) < h.lineLimit { - message.SetContent(content) // refresh the content in the message - h.outputFn(message) + msg.SetContent(content) // refresh the content in the message + h.outputFn(msg) } else { // the line is too long, it needs to be cut off and send, // adding the truncated flag the end of the content - content = append(content, truncatedFlag...) - message.SetContent(content) // refresh the content in the message - h.outputFn(message) + content = append(content, message.TruncatedFlag...) + msg.SetContent(content) // refresh the content in the message + h.outputFn(msg) // make sure the following part of the line will be cut off as well h.shouldTruncate = true } diff --git a/pkg/logs/launchers/container/tailerfactory/file_test.go b/pkg/logs/launchers/container/tailerfactory/file_test.go index 394d941f3ff8d..cc336dc04a41e 100644 --- a/pkg/logs/launchers/container/tailerfactory/file_test.go +++ b/pkg/logs/launchers/container/tailerfactory/file_test.go @@ -18,7 +18,8 @@ import ( "go.uber.org/fx" compConfig "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -243,7 +244,7 @@ func TestMakeK8sSource(t *testing.T) { wildcard := filepath.Join(dir, "*.log") store := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), compConfig.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), @@ -300,7 +301,7 @@ func TestMakeK8sSource_pod_not_found(t *testing.T) { require.NoError(t, os.WriteFile(p, []byte("{}"), 0o666)) workloadmetaStore := fxutil.Test[optional.Option[workloadmeta.Component]](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), compConfig.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/logs/message/message.go b/pkg/logs/message/message.go index 71e45c1bed68f..e8084b49eec53 100644 --- a/pkg/logs/message/message.go +++ b/pkg/logs/message/message.go @@ -15,6 +15,16 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/log" ) +// TruncatedFlag is the flag that is added at the beginning +// or/and at the end of every trucated lines. +var TruncatedFlag = []byte("...TRUNCATED...") + +// EscapedLineFeed is used to escape new line character +// for multiline message. +// New line character needs to be escaped because they are used +// as delimiter for transport. +var EscapedLineFeed = []byte(`\n`) + // Payload represents an encoded collection of messages ready to be sent to the intake type Payload struct { // The slice of sources messages encoded in the payload @@ -34,7 +44,10 @@ type Message struct { Origin *Origin Status string IngestionTimestamp int64 - RawDataLen int + // RawDataLen tracks the original size of the message content before any trimming/transformation. + // This is used when calculating the tailer offset - so this will NOT always be equal to `len(Content)`. + RawDataLen int + IsMultiLine bool // Tags added on processing ProcessingTags []string // Extra information from the parsers @@ -193,6 +206,40 @@ func NewMessage(content []byte, origin *Origin, status string, ingestionTimestam } } +// NewRawMessage returns a new encoded message. +func NewRawMessage(content []byte, status string, rawDataLen int, readTimestamp string) *Message { + return &Message{ + MessageContent: MessageContent{ + content: content, + State: StateUnstructured, + }, + Status: status, + RawDataLen: rawDataLen, + IngestionTimestamp: time.Now().UnixNano(), + ParsingExtra: ParsingExtra{ + Timestamp: readTimestamp, + }, + IsMultiLine: false, + } +} + +// NewRawMultiLineMessage returns a new encoded message. +func NewRawMultiLineMessage(content []byte, status string, rawDataLen int, readTimestamp string) *Message { + return &Message{ + MessageContent: MessageContent{ + content: content, + State: StateUnstructured, + }, + Status: status, + RawDataLen: rawDataLen, + IngestionTimestamp: time.Now().UnixNano(), + ParsingExtra: ParsingExtra{ + Timestamp: readTimestamp, + }, + IsMultiLine: true, + } +} + // NewStructuredMessage creates a new message that had some structure the moment // it has been captured through a tailer. // e.g. a journald message which is a JSON object containing extra information, including diff --git a/pkg/network/dns/types.go b/pkg/network/dns/types.go index 43cb305298fdd..e14b36d676484 100644 --- a/pkg/network/dns/types.go +++ b/pkg/network/dns/types.go @@ -7,8 +7,6 @@ package dns import ( - "github.com/google/gopacket/layers" - "github.com/DataDog/datadog-agent/pkg/process/util" "github.com/DataDog/datadog-agent/pkg/util/intern" ) @@ -34,7 +32,7 @@ func ToHostname(s string) Hostname { } // QueryType is the DNS record type -type QueryType layers.DNSType +type QueryType int // DNSType known values. const ( diff --git a/pkg/process/runner/submitter.go b/pkg/process/runner/submitter.go index fa6610380d5a8..a2ee141a960a7 100644 --- a/pkg/process/runner/submitter.go +++ b/pkg/process/runner/submitter.go @@ -19,7 +19,7 @@ import ( model "github.com/DataDog/agent-payload/v5/process" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/forwarder/defaultforwarder" //nolint:revive // TODO(PROC) Fix revive linter diff --git a/pkg/process/runner/submitter_test.go b/pkg/process/runner/submitter_test.go index cfefe07be0887..81da4347a1473 100644 --- a/pkg/process/runner/submitter_test.go +++ b/pkg/process/runner/submitter_test.go @@ -17,8 +17,8 @@ import ( model "github.com/DataDog/agent-payload/v5/process" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/process/forwarders" "github.com/DataDog/datadog-agent/comp/process/forwarders/forwardersimpl" ddconfig "github.com/DataDog/datadog-agent/pkg/config" @@ -387,14 +387,14 @@ type submitterDeps struct { } func newSubmitterDeps(t *testing.T) submitterDeps { - return fxutil.Test[submitterDeps](t, getForwardersMockModules(nil)) + return fxutil.Test[submitterDeps](t, getForwardersMockModules(t, nil)) } func newSubmitterDepsWithConfig(t *testing.T, config ddconfig.Config) submitterDeps { overrides := config.AllSettings() - return fxutil.Test[submitterDeps](t, getForwardersMockModules(overrides)) + return fxutil.Test[submitterDeps](t, getForwardersMockModules(t, overrides)) } -func getForwardersMockModules(configOverrides map[string]interface{}) fx.Option { - return fx.Options(config.MockModule(), fx.Replace(config.MockParams{Overrides: configOverrides}), forwardersimpl.MockModule(), logimpl.MockModule()) +func getForwardersMockModules(t *testing.T, configOverrides map[string]interface{}) fx.Option { + return fx.Options(config.MockModule(), fx.Replace(config.MockParams{Overrides: configOverrides}), forwardersimpl.MockModule(), fx.Provide(func() log.Component { return logmock.New(t) })) } diff --git a/pkg/process/status/expvars.go b/pkg/process/status/expvars.go index 11e2ac58ae53b..2b40adf3735a6 100644 --- a/pkg/process/status/expvars.go +++ b/pkg/process/status/expvars.go @@ -12,6 +12,7 @@ import ( "bufio" "expvar" "os" + "slices" "strings" "sync" "time" @@ -242,7 +243,7 @@ func publishDropCheckPayloads() interface{} { infoMutex.RLock() defer infoMutex.RUnlock() - return infoDropCheckPayloads + return slices.Clone(infoDropCheckPayloads) } // InitExpvars initializes expvars diff --git a/pkg/sbom/scanner/scanner_test.go b/pkg/sbom/scanner/scanner_test.go index 52c384a283d11..3a877e5a3f4a4 100644 --- a/pkg/sbom/scanner/scanner_test.go +++ b/pkg/sbom/scanner/scanner_test.go @@ -16,7 +16,8 @@ import ( "time" compConfig "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -76,7 +77,7 @@ var _ sbom.Report = mockReport{} func TestRetryLogic_Error(t *testing.T) { // Create a workload meta global store workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), compConfig.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), @@ -158,7 +159,7 @@ func TestRetryLogic_Error(t *testing.T) { func TestRetryLogic_ImageDeleted(t *testing.T) { // Create a workload meta global store workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), compConfig.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), @@ -225,7 +226,7 @@ func TestRetryLogic_ImageDeleted(t *testing.T) { func TestRetryChannelFull(t *testing.T) { // Create a workload meta global store workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), compConfig.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/security/ebpf/c/include/hooks/open.h b/pkg/security/ebpf/c/include/hooks/open.h index 3d747cd1cba7b..abc2981d5900f 100644 --- a/pkg/security/ebpf/c/include/hooks/open.h +++ b/pkg/security/ebpf/c/include/hooks/open.h @@ -56,6 +56,13 @@ HOOK_SYSCALL_COMPAT_ENTRY1(truncate, const char *, filename) { return trace__sys_openat(filename, SYNC_SYSCALL, flags, mode); } +HOOK_SYSCALL_COMPAT_ENTRY0(ftruncate) { + int flags = O_CREAT | O_WRONLY | O_TRUNC; + umode_t mode = 0; + char filename[1] = ""; + return trace__sys_openat(&filename[0], SYNC_SYSCALL, flags, mode); +} + HOOK_SYSCALL_COMPAT_ENTRY3(open, const char *, filename, int, flags, umode_t, mode) { return trace__sys_openat(filename, SYNC_SYSCALL, flags, mode); } @@ -89,8 +96,7 @@ int __attribute__((always_inline)) handle_open_event(struct syscall_cache_t *sys return 0; } -HOOK_ENTRY("vfs_truncate") -int hook_vfs_truncate(ctx_t *ctx) { +int __attribute__((always_inline)) handle_truncate_path_dentry(struct path *path, struct dentry *dentry) { struct syscall_cache_t *syscall = peek_syscall(EVENT_OPEN); if (!syscall) { return 0; @@ -100,9 +106,6 @@ int hook_vfs_truncate(ctx_t *ctx) { return 0; } - struct path *path = (struct path *)CTX_PARM1(ctx); - struct dentry *dentry = get_path_dentry(path); - if (is_non_mountable_dentry(dentry)) { pop_syscall(EVENT_OPEN); return 0; @@ -120,6 +123,47 @@ int hook_vfs_truncate(ctx_t *ctx) { return 0; } +int __attribute__((always_inline)) handle_truncate_path(struct path *path) { + if (path == NULL) { + return 0; + } + + struct dentry *dentry = get_path_dentry(path); + return handle_truncate_path_dentry(path, dentry); +} + +HOOK_ENTRY("do_truncate") +int hook_do_truncate(ctx_t *ctx) { + struct dentry *dentry = (struct dentry *)CTX_PARM1(ctx); + struct file *f = (struct file *)CTX_PARM4(ctx); + if (f == NULL) { + return 0; + } + struct path *path = get_file_f_path_addr(f); + return handle_truncate_path_dentry(path, dentry); +} + +HOOK_ENTRY("vfs_truncate") +int hook_vfs_truncate(ctx_t *ctx) { + struct path *path = (struct path *)CTX_PARM1(ctx); + return handle_truncate_path(path); +} + +HOOK_ENTRY("security_file_truncate") +int hook_security_file_truncate(ctx_t *ctx) { + struct file *f = (struct file *)CTX_PARM1(ctx); + if (f == NULL) { + return 0; + } + return handle_truncate_path(get_file_f_path_addr(f)); +} + +HOOK_ENTRY("security_path_truncate") +int hook_security_path_truncate(ctx_t *ctx) { + struct path *path = (struct path *)CTX_PARM1(ctx); + return handle_truncate_path(path); +} + HOOK_ENTRY("vfs_open") int hook_vfs_open(ctx_t *ctx) { struct syscall_cache_t *syscall = peek_syscall(EVENT_OPEN); @@ -233,6 +277,11 @@ HOOK_SYSCALL_COMPAT_EXIT(truncate) { return sys_open_ret(ctx, retval, DR_KPROBE_OR_FENTRY); } +HOOK_SYSCALL_COMPAT_EXIT(ftruncate) { + int retval = SYSCALL_PARMRET(ctx); + return sys_open_ret(ctx, retval, DR_KPROBE_OR_FENTRY); +} + HOOK_SYSCALL_COMPAT_EXIT(open) { int retval = SYSCALL_PARMRET(ctx); return sys_open_ret(ctx, retval, DR_KPROBE_OR_FENTRY); diff --git a/pkg/security/ebpf/probes/event_types.go b/pkg/security/ebpf/probes/event_types.go index 552c5f2568f29..63254c7c17631 100644 --- a/pkg/security/ebpf/probes/event_types.go +++ b/pkg/security/ebpf/probes/event_types.go @@ -147,12 +147,16 @@ func GetSelectorsPerEventType(fentry bool) map[eval.EventType][]manager.ProbesSe kprobeOrFentry("security_inode_setattr"), // Open probes - &manager.AllOf{Selectors: []manager.ProbesSelector{ + &manager.OneOf{Selectors: []manager.ProbesSelector{ + kprobeOrFentry("security_path_truncate"), + kprobeOrFentry("security_file_truncate"), kprobeOrFentry("vfs_truncate"), + kprobeOrFentry("do_truncate"), }}, &manager.OneOf{Selectors: ExpandSyscallProbesSelector(SecurityAgentUID, "open", fentry, EntryAndExit, true)}, &manager.OneOf{Selectors: ExpandSyscallProbesSelector(SecurityAgentUID, "creat", fentry, EntryAndExit)}, &manager.OneOf{Selectors: ExpandSyscallProbesSelector(SecurityAgentUID, "truncate", fentry, EntryAndExit, true)}, + &manager.OneOf{Selectors: ExpandSyscallProbesSelector(SecurityAgentUID, "ftruncate", fentry, EntryAndExit, true)}, &manager.OneOf{Selectors: ExpandSyscallProbesSelector(SecurityAgentUID, "openat", fentry, EntryAndExit, true)}, &manager.BestEffort{Selectors: ExpandSyscallProbesSelector(SecurityAgentUID, "openat2", fentry, EntryAndExit)}, &manager.BestEffort{Selectors: ExpandSyscallProbesSelector(SecurityAgentUID, "open_by_handle_at", fentry, EntryAndExit, true)}, diff --git a/pkg/security/ebpf/probes/open.go b/pkg/security/ebpf/probes/open.go index 97ba7c485414c..e64252ca13c9d 100644 --- a/pkg/security/ebpf/probes/open.go +++ b/pkg/security/ebpf/probes/open.go @@ -12,12 +12,30 @@ import manager "github.com/DataDog/ebpf-manager" func getOpenProbes(fentry bool) []*manager.Probe { var openProbes = []*manager.Probe{ + { + ProbeIdentificationPair: manager.ProbeIdentificationPair{ + UID: SecurityAgentUID, + EBPFFuncName: "hook_security_path_truncate", + }, + }, + { + ProbeIdentificationPair: manager.ProbeIdentificationPair{ + UID: SecurityAgentUID, + EBPFFuncName: "hook_security_file_truncate", + }, + }, { ProbeIdentificationPair: manager.ProbeIdentificationPair{ UID: SecurityAgentUID, EBPFFuncName: "hook_vfs_truncate", }, }, + { + ProbeIdentificationPair: manager.ProbeIdentificationPair{ + UID: SecurityAgentUID, + EBPFFuncName: "hook_do_truncate", + }, + }, { ProbeIdentificationPair: manager.ProbeIdentificationPair{ UID: SecurityAgentUID, @@ -80,6 +98,12 @@ func getOpenProbes(fentry bool) []*manager.Probe { }, SyscallFuncName: "truncate", }, fentry, EntryAndExit, true)...) + openProbes = append(openProbes, ExpandSyscallProbes(&manager.Probe{ + ProbeIdentificationPair: manager.ProbeIdentificationPair{ + UID: SecurityAgentUID, + }, + SyscallFuncName: "ftruncate", + }, fentry, EntryAndExit, true)...) openProbes = append(openProbes, ExpandSyscallProbes(&manager.Probe{ ProbeIdentificationPair: manager.ProbeIdentificationPair{ UID: SecurityAgentUID, diff --git a/pkg/security/tests/main_linux.go b/pkg/security/tests/main_linux.go index c8e59693c02c1..9be9126f1ccb8 100644 --- a/pkg/security/tests/main_linux.go +++ b/pkg/security/tests/main_linux.go @@ -82,6 +82,7 @@ func SkipIfNotAvailable(t *testing.T) { "TestOpenDiscarded", "TestOpenDiscarded/pipefs", "TestOpen/truncate", + "TestOpen/ftruncate", "TestOpen/io_uring", "TestProcessContext/inode", "TestProcessContext/pid1", diff --git a/pkg/security/tests/open_test.go b/pkg/security/tests/open_test.go index f0ece6845de36..3509168fa021f 100644 --- a/pkg/security/tests/open_test.go +++ b/pkg/security/tests/open_test.go @@ -32,12 +32,18 @@ import ( func TestOpen(t *testing.T) { SkipIfNotAvailable(t) - rule := &rules.RuleDefinition{ - ID: "test_rule", - Expression: `open.file.path == "{{.Root}}/test-open" && open.flags & O_CREAT != 0`, + ruleDefs := []*rules.RuleDefinition{ + { + ID: "test_rule", + Expression: `open.file.path == "{{.Root}}/test-open" && open.flags & O_CREAT != 0`, + }, + { + ID: "test_rule_truncate", + Expression: `open.file.path == "{{.Root}}/test-truncate" && open.flags & O_TRUNC != 0`, + }, } - test, err := newTestModule(t, nil, []*rules.RuleDefinition{rule}) + test, err := newTestModule(t, nil, ruleDefs) if err != nil { t.Fatal(err) } @@ -48,6 +54,11 @@ func TestOpen(t *testing.T) { t.Fatal(err) } + testFileTrunc, testFileTruncPtr, err := test.Path("test-truncate") + if err != nil { + t.Fatal(err) + } + t.Run("open", ifSyscallSupported("SYS_OPEN", func(t *testing.T, syscallNB uintptr) { defer os.Remove(testFile) @@ -142,33 +153,72 @@ func TestOpen(t *testing.T) { t.Run("truncate", func(t *testing.T) { SkipIfNotAvailable(t) + f, err := os.OpenFile(testFileTrunc, os.O_RDWR|os.O_CREATE, 0755) + if err != nil { + t.Fatal(err) + } + + if _, err := f.Write([]byte("this data will soon be truncated\n")); err != nil { + t.Fatal(err) + } + + if err := f.Close(); err != nil { + t.Fatal(err) + } + defer os.Remove(testFile) test.WaitSignal(t, func() error { - f, err := os.OpenFile(testFile, os.O_RDWR|os.O_CREATE, 0755) - if err != nil { - return err + // truncate + _, _, errno := syscall.Syscall(syscall.SYS_TRUNCATE, uintptr(testFileTruncPtr), 4, 0) + if errno != 0 { + return error(errno) } + return nil + }, func(event *model.Event, r *rules.Rule) { + assert.Equal(t, "open", event.GetType(), "wrong event type") + assert.Equal(t, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, int(event.Open.Flags), "wrong flags") + assert.Equal(t, getInode(t, testFileTrunc), event.Open.File.Inode, "wrong inode") - _, err = syscall.Write(int(f.Fd()), []byte("this data will soon be truncated\n")) - if err != nil { - return err - } + value, _ := event.GetFieldValue("event.async") + assert.Equal(t, value.(bool), false) + }) + }) - return f.Close() - }, func(event *model.Event, r *rules.Rule) {}) + t.Run("ftruncate", func(t *testing.T) { + SkipIfNotAvailable(t) + + f, err := os.OpenFile(testFileTrunc, os.O_RDWR|os.O_CREATE, 0755) + if err != nil { + t.Fatal(err) + } + + if _, err := f.Write([]byte("this data will soon be truncated\n")); err != nil { + t.Fatal(err) + } + + if err := f.Sync(); err != nil { + t.Fatal(err) + } + + defer os.Remove(testFile) + defer f.Close() test.WaitSignal(t, func() error { - // truncate - _, _, errno := syscall.Syscall(syscall.SYS_TRUNCATE, uintptr(testFilePtr), 4, 0) + if f == nil { + return fmt.Errorf("failed to open test file") + } + // ftruncate + _, _, errno := syscall.Syscall(syscall.SYS_FTRUNCATE, f.Fd(), uintptr(4), 0) if errno != 0 { return error(errno) } + return nil }, func(event *model.Event, r *rules.Rule) { assert.Equal(t, "open", event.GetType(), "wrong event type") assert.Equal(t, syscall.O_CREAT|syscall.O_WRONLY|syscall.O_TRUNC, int(event.Open.Flags), "wrong flags") - assert.Equal(t, getInode(t, testFile), event.Open.File.Inode, "wrong inode") + assert.Equal(t, getInode(t, testFileTrunc), event.Open.File.Inode, "wrong inode") value, _ := event.GetFieldValue("event.async") assert.Equal(t, value.(bool), false) diff --git a/pkg/serializer/go.mod b/pkg/serializer/go.mod index c91ee7a044f13..78ccf3d856e9b 100644 --- a/pkg/serializer/go.mod +++ b/pkg/serializer/go.mod @@ -8,7 +8,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/config => ../../comp/core/config github.com/DataDog/datadog-agent/comp/core/flare/builder => ../../comp/core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ../../comp/core/flare/types - github.com/DataDog/datadog-agent/comp/core/log => ../../comp/core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ../../comp/core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ../../comp/core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ../../comp/core/secrets github.com/DataDog/datadog-agent/comp/core/status => ../../comp/core/status github.com/DataDog/datadog-agent/comp/core/telemetry => ../../comp/core/telemetry @@ -84,7 +85,7 @@ require ( require ( github.com/DataDog/datadog-agent/comp/core/flare/builder v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/flare/types v0.56.0-rc.3 // indirect - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.3 // indirect + github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 // indirect github.com/DataDog/datadog-agent/comp/core/secrets v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/status v0.56.0-rc.3 // indirect github.com/DataDog/datadog-agent/comp/core/telemetry v0.56.0-rc.3 // indirect diff --git a/pkg/serverless/invocationlifecycle/lifecycle_test.go b/pkg/serverless/invocationlifecycle/lifecycle_test.go index b7ee5aaa3057d..1eceb0d9ccf19 100644 --- a/pkg/serverless/invocationlifecycle/lifecycle_test.go +++ b/pkg/serverless/invocationlifecycle/lifecycle_test.go @@ -14,7 +14,8 @@ import ( "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/metrics" pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace" @@ -23,6 +24,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/trace/api" "github.com/DataDog/datadog-agent/pkg/trace/sampler" "github.com/DataDog/datadog-agent/pkg/util/fxutil" + "go.uber.org/fx" "github.com/stretchr/testify/assert" ) @@ -1174,5 +1176,5 @@ func getEventFromFile(filename string) []byte { } func createDemultiplexer(t *testing.T) demultiplexer.FakeSamplerMock { - return fxutil.Test[demultiplexer.FakeSamplerMock](t, logimpl.MockModule(), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) + return fxutil.Test[demultiplexer.FakeSamplerMock](t, fx.Provide(func() log.Component { return logmock.New(t) }), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) } diff --git a/pkg/serverless/logs/logs_test.go b/pkg/serverless/logs/logs_test.go index 9612f24b01352..ed0e48336020a 100644 --- a/pkg/serverless/logs/logs_test.go +++ b/pkg/serverless/logs/logs_test.go @@ -18,11 +18,13 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/logs/agent/config" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/metrics" @@ -1471,5 +1473,5 @@ func TestMultipleStartLogCollection(t *testing.T) { } func createDemultiplexer(t *testing.T) demultiplexer.FakeSamplerMock { - return fxutil.Test[demultiplexer.FakeSamplerMock](t, logimpl.MockModule(), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) + return fxutil.Test[demultiplexer.FakeSamplerMock](t, fx.Provide(func() log.Component { return logmock.New(t) }), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) } diff --git a/pkg/serverless/metrics/enhanced_metrics_test.go b/pkg/serverless/metrics/enhanced_metrics_test.go index b2aac2ad0fa8a..6281b1326180f 100644 --- a/pkg/serverless/metrics/enhanced_metrics_test.go +++ b/pkg/serverless/metrics/enhanced_metrics_test.go @@ -11,11 +11,13 @@ import ( "github.com/DataDog/datadog-agent/pkg/serverless/proc" "github.com/stretchr/testify/assert" + "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer" "github.com/DataDog/datadog-agent/comp/aggregator/demultiplexer/demultiplexerimpl" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" "github.com/DataDog/datadog-agent/comp/serializer/compression/compressionimpl" "github.com/DataDog/datadog-agent/pkg/metrics" serverlessTags "github.com/DataDog/datadog-agent/pkg/serverless/tags" @@ -737,5 +739,5 @@ func TestSendFailoverReasonMetric(t *testing.T) { } func createDemultiplexer(t *testing.T) demultiplexer.FakeSamplerMock { - return fxutil.Test[demultiplexer.FakeSamplerMock](t, logimpl.MockModule(), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) + return fxutil.Test[demultiplexer.FakeSamplerMock](t, fx.Provide(func() log.Component { return logmock.New(t) }), compressionimpl.MockModule(), demultiplexerimpl.FakeSamplerMockModule(), hostnameimpl.MockModule()) } diff --git a/pkg/trace/info/info.go b/pkg/trace/info/info.go index 7711630d34a64..df86c40587fdc 100644 --- a/pkg/trace/info/info.go +++ b/pkg/trace/info/info.go @@ -15,6 +15,7 @@ import ( "net/http" "os" "regexp" + "slices" "strings" "sync" "text/template" @@ -137,7 +138,7 @@ func Languages() []string { func publishReceiverStats() interface{} { infoMu.RLock() defer infoMu.RUnlock() - return receiverStats + return slices.Clone(receiverStats) } // UpdateRateByService updates the RateByService map and the filtered RateByServiceFiltered map. diff --git a/pkg/util/cloudproviders/cloudproviders.go b/pkg/util/cloudproviders/cloudproviders.go index 5a0bda2efcdeb..10c1bd7395351 100644 --- a/pkg/util/cloudproviders/cloudproviders.go +++ b/pkg/util/cloudproviders/cloudproviders.go @@ -11,7 +11,7 @@ import ( "errors" "sync" - logComp "github.com/DataDog/datadog-agent/comp/core/log" + logcomp "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/pkg/config" "github.com/DataDog/datadog-agent/pkg/util" "github.com/DataDog/datadog-agent/pkg/util/kubelet" @@ -46,7 +46,7 @@ var cloudProviderDetectors = []cloudProviderDetector{ } // DetectCloudProvider detects the cloud provider where the agent is running in order: -func DetectCloudProvider(ctx context.Context, collectAccountID bool, l logComp.Component) (string, string) { +func DetectCloudProvider(ctx context.Context, collectAccountID bool, l logcomp.Component) (string, string) { for _, cloudDetector := range cloudProviderDetectors { if cloudDetector.callback(ctx) { l.Infof("Cloud provider %s detected", cloudDetector.name) diff --git a/pkg/util/containers/metrics/containerd/collector_linux_test.go b/pkg/util/containers/metrics/containerd/collector_linux_test.go index 0bcd379ac542d..d127c330bdc4c 100644 --- a/pkg/util/containers/metrics/containerd/collector_linux_test.go +++ b/pkg/util/containers/metrics/containerd/collector_linux_test.go @@ -25,7 +25,8 @@ import ( "google.golang.org/protobuf/types/known/anypb" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -283,7 +284,7 @@ func TestGetContainerStats_Containerd(t *testing.T) { // The container needs to exist in the workloadmeta store and have a // namespace. workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), @@ -382,7 +383,7 @@ func TestGetContainerNetworkStats_Containerd(t *testing.T) { // The container needs to exist in the workloadmeta store and have a // namespace. workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/util/containers/metrics/containerd/collector_windows_test.go b/pkg/util/containers/metrics/containerd/collector_windows_test.go index 992d8706cd230..86a18cfe25fd6 100644 --- a/pkg/util/containers/metrics/containerd/collector_windows_test.go +++ b/pkg/util/containers/metrics/containerd/collector_windows_test.go @@ -14,7 +14,8 @@ import ( "github.com/opencontainers/runtime-spec/specs-go" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -106,7 +107,7 @@ func TestGetContainerStats_Containerd(t *testing.T) { // The container needs to exist in the workloadmeta store and have a // namespace. workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), @@ -172,7 +173,7 @@ func TestGetContainerNetworkStats_Containerd(t *testing.T) { // The container needs to exist in the workloadmeta store and have a // namespace. workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), diff --git a/pkg/util/containers/metrics/docker/collector_test.go b/pkg/util/containers/metrics/docker/collector_test.go index 8fafd42d3476d..43bd1a14107a2 100644 --- a/pkg/util/containers/metrics/docker/collector_test.go +++ b/pkg/util/containers/metrics/docker/collector_test.go @@ -18,7 +18,8 @@ import ( "go.uber.org/fx" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -87,7 +88,7 @@ func TestGetContainerIDForPID(t *testing.T) { // TODO(components): this test needs to rely on a workloadmeta.Component mock mockStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( config.MockModule(), - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), )) diff --git a/pkg/util/containers/metrics/system/filter_container_test.go b/pkg/util/containers/metrics/system/filter_container_test.go index 4ce436a40a80a..27dba224aed0d 100644 --- a/pkg/util/containers/metrics/system/filter_container_test.go +++ b/pkg/util/containers/metrics/system/filter_container_test.go @@ -13,7 +13,8 @@ import ( "time" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -91,7 +92,7 @@ func TestHandleUnsetEvent(t *testing.T) { func TestListenWorkloadmeta(t *testing.T) { wlm := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/util/fxutil/oneshot.go b/pkg/util/fxutil/oneshot.go index e4eb049158da4..e10900287fff9 100644 --- a/pkg/util/fxutil/oneshot.go +++ b/pkg/util/fxutil/oneshot.go @@ -34,7 +34,7 @@ func OneShot(oneShotFunc interface{}, opts ...fx.Option) error { opts = append(opts, delayedCall.option(), FxLoggingOption(), - fx.Provide(newFxLifecycleAdapter), + FxLifecycleAdapter(), ) // Temporarily increase timeout for all fxutil.OneShot calls until we can better characterize our // start time requirements. Prepend to opts so individual calls can override the timeout. diff --git a/pkg/util/fxutil/provide_comp.go b/pkg/util/fxutil/provide_comp.go index ae9f373f08151..a86a760e5ad28 100644 --- a/pkg/util/fxutil/provide_comp.go +++ b/pkg/util/fxutil/provide_comp.go @@ -299,6 +299,11 @@ type fxLifecycleAdapter struct { lc fx.Lifecycle } +// FxLifecycleAdapter create an fx.Option to convert fx.Lifecycle to compdef.Lifecycle when needed. +func FxLifecycleAdapter() fx.Option { + return fx.Provide(newFxLifecycleAdapter) +} + func newFxLifecycleAdapter(lc fx.Lifecycle) compdef.Lifecycle { return &fxLifecycleAdapter{lc: lc} } diff --git a/pkg/util/fxutil/run.go b/pkg/util/fxutil/run.go index 3fc9fed15c76b..f15cdd47fe5e3 100644 --- a/pkg/util/fxutil/run.go +++ b/pkg/util/fxutil/run.go @@ -21,7 +21,7 @@ func Run(opts ...fx.Option) error { return fxAppTestOverride(func() {}, opts) } - opts = append(opts, FxLoggingOption(), fx.Provide(newFxLifecycleAdapter)) + opts = append(opts, FxLoggingOption(), FxLifecycleAdapter()) // Temporarily increase timeout for all fxutil.Run calls until we can better characterize our // start time requirements. Prepend to opts so individual calls can override the timeout. opts = append( @@ -30,6 +30,10 @@ func Run(opts ...fx.Option) error { ) app := fx.New(opts...) + if err := app.Err(); err != nil { + return err + } + startCtx, cancel := context.WithTimeout(context.Background(), app.StartTimeout()) defer cancel() diff --git a/pkg/util/kubernetes/apiserver/controllers/metadata_controller_test.go b/pkg/util/kubernetes/apiserver/controllers/metadata_controller_test.go index e127b0f229154..3c2df511854ef 100644 --- a/pkg/util/kubernetes/apiserver/controllers/metadata_controller_test.go +++ b/pkg/util/kubernetes/apiserver/controllers/metadata_controller_test.go @@ -27,7 +27,8 @@ import ( "k8s.io/client-go/tools/cache" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -490,7 +491,7 @@ func newMockWorkloadMeta(t *testing.T) workloadmeta.Component { return fxutil.Test[workloadmetamock.Mock]( t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(workloadmeta.NewParams()), workloadmetafxmock.MockModule(), diff --git a/pkg/util/log/wrapper.go b/pkg/util/log/wrapper.go new file mode 100644 index 0000000000000..52ff4c0814e04 --- /dev/null +++ b/pkg/util/log/wrapper.go @@ -0,0 +1,77 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package log + +// Wrapper wraps all the logger function on a struct. This is meant to be used by the comp/core/log component to expose +// the logger functionnality to components. This should only be use by the log component. +type Wrapper struct { + stackDepth int +} + +// NewWrapper returns a new Wrapper. This should only be use by the log component. +func NewWrapper(stackDepth int) *Wrapper { + return &Wrapper{stackDepth: stackDepth} +} + +// Until the log migration to component is done, we use *StackDepth to pkglog. The log component add 1 layer to the call +// stack and *StackDepth add another. +// +// We check the current log level to avoid calling Sprintf when it's not needed (Sprintf from Tracef uses a lot a CPU) + +// Trace implements Component#Trace. +func (l *Wrapper) Trace(v ...interface{}) { TraceStackDepth(l.stackDepth, v...) } + +// Tracef implements Component#Tracef. +func (l *Wrapper) Tracef(format string, params ...interface{}) { + TracefStackDepth(l.stackDepth, format, params...) +} + +// Debug implements Component#Debug. +func (l *Wrapper) Debug(v ...interface{}) { DebugStackDepth(l.stackDepth, v...) } + +// Debugf implements Component#Debugf. +func (l *Wrapper) Debugf(format string, params ...interface{}) { + DebugfStackDepth(l.stackDepth, format, params...) +} + +// Info implements Component#Info. +func (l *Wrapper) Info(v ...interface{}) { InfoStackDepth(l.stackDepth, v...) } + +// Infof implements Component#Infof. +func (l *Wrapper) Infof(format string, params ...interface{}) { + InfofStackDepth(l.stackDepth, format, params...) +} + +// Warn implements Component#Warn. +func (l *Wrapper) Warn(v ...interface{}) error { return WarnStackDepth(l.stackDepth, v...) } + +// Warnf implements Component#Warnf. +func (l *Wrapper) Warnf(format string, params ...interface{}) error { + return WarnfStackDepth(l.stackDepth, format, params...) +} + +// Error implements Component#Error. +func (l *Wrapper) Error(v ...interface{}) error { return ErrorStackDepth(l.stackDepth, v...) } + +// Errorf implements Component#Errorf. +func (l *Wrapper) Errorf(format string, params ...interface{}) error { + return ErrorfStackDepth(l.stackDepth, format, params...) +} + +// Critical implements Component#Critical. +func (l *Wrapper) Critical(v ...interface{}) error { + return CriticalStackDepth(l.stackDepth, v...) +} + +// Criticalf implements Component#Criticalf. +func (l *Wrapper) Criticalf(format string, params ...interface{}) error { + return CriticalfStackDepth(l.stackDepth, format, params...) +} + +// Flush implements Component#Flush. +func (l *Wrapper) Flush() { + Flush() +} diff --git a/pkg/util/trivy/cache_test.go b/pkg/util/trivy/cache_test.go index d78d89e2d7f79..bf9e673e3ab6a 100644 --- a/pkg/util/trivy/cache_test.go +++ b/pkg/util/trivy/cache_test.go @@ -16,7 +16,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core" "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + log "github.com/DataDog/datadog-agent/comp/core/log/def" + logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" workloadmetafxmock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/fx-mock" workloadmetamock "github.com/DataDog/datadog-agent/comp/core/workloadmeta/mock" @@ -235,7 +236,7 @@ func TestCustomBoltCache_DiskSizeLimit(t *testing.T) { func TestCustomBoltCache_GarbageCollector(t *testing.T) { // Create a workload meta global store containing two images with a distinct artifactID/blobs and a shared blob workloadmetaStore := fxutil.Test[workloadmetamock.Mock](t, fx.Options( - logimpl.MockModule(), + fx.Provide(func() log.Component { return logmock.New(t) }), config.MockModule(), fx.Supply(context.Background()), fx.Supply(workloadmeta.NewParams()), diff --git a/pkg/util/trivy/trivy.go b/pkg/util/trivy/trivy.go index ea75175d9807d..1895a113b3d34 100644 --- a/pkg/util/trivy/trivy.go +++ b/pkg/util/trivy/trivy.go @@ -169,7 +169,12 @@ func DefaultDisabledCollectors(enabledAnalyzers []string) []analyzer.Type { if analyzersDisabled(TypeImageConfigSecret) { disabledAnalyzers = append(disabledAnalyzers, analyzer.TypeImageConfigSecret) } - + disabledAnalyzers = append(disabledAnalyzers, + analyzer.TypeExecutable, + analyzer.TypeRedHatContentManifestType, + analyzer.TypeRedHatDockerfileType, + analyzer.TypeSBOM, + analyzer.TypeUbuntuESM) return disabledAnalyzers } diff --git a/releasenotes/notes/cisco-sdwan-cloud-fix-unspecifed-ip-address-ea7f2cabe6981b5c.yaml b/releasenotes/notes/cisco-sdwan-cloud-fix-unspecifed-ip-address-ea7f2cabe6981b5c.yaml new file mode 100644 index 0000000000000..04cfa36caafe5 --- /dev/null +++ b/releasenotes/notes/cisco-sdwan-cloud-fix-unspecifed-ip-address-ea7f2cabe6981b5c.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +fixes: + - | + [Cisco SD-WAN] Do not collect unspecified IP addresses. diff --git a/releasenotes/notes/fix-missing-checks-metadata-a0fe0f878438bb6a.yaml b/releasenotes/notes/fix-missing-checks-metadata-a0fe0f878438bb6a.yaml new file mode 100644 index 0000000000000..efd639bbb0e74 --- /dev/null +++ b/releasenotes/notes/fix-missing-checks-metadata-a0fe0f878438bb6a.yaml @@ -0,0 +1,11 @@ +# Each section from every release note are combined when the +# CHANGELOG.rst is rendered. So the text needs to be worded so that +# it does not depend on any information only available in another +# section. This may mean repeating some details, but each section +# must be readable independently of the other. +# +# Each section note must be formatted as reStructuredText. +--- +fixes: + - | + Re-enable printing of checks metadata in the ``datadog-agent status`` collector section. \ No newline at end of file diff --git a/tasks/__init__.py b/tasks/__init__.py index 6ad3a7a15343a..6560e12e7d768 100644 --- a/tasks/__init__.py +++ b/tasks/__init__.py @@ -17,6 +17,7 @@ components, coverage, cws_instrumentation, + debug, devcontainer, diff, docker_tasks, @@ -193,6 +194,7 @@ ns.add_collection(omnibus) ns.add_collection(collector) ns.add_collection(invoke_unit_tests) +ns.add_collection(debug) ns.configure( { "run": { diff --git a/tasks/debug.py b/tasks/debug.py new file mode 100644 index 0000000000000..6b905f8213043 --- /dev/null +++ b/tasks/debug.py @@ -0,0 +1,38 @@ +import os +from pathlib import Path + +from invoke import task +from invoke.exceptions import Exit + +from tasks.libs.common.color import Color, color_message +from tasks.vscode import VSCODE_DIR, VSCODE_LAUNCH_FILE + + +@task(default=True) +def debug(_, wait=True, host='localhost', port=5678): + """ + Launch debugger to debug in vs-code or other IDEs using debugpy. + + Usage to debug `inv invoke-unit-tests.run`: + > inv debug invoke-unit-tests.run + > # In vscode, launch the debugger with the configuration "Remote Debug Tasks" + > # The debugger is attached ! + """ + try: + import debugpy + except ImportError as e: + raise Exit( + 'debugpy is not installed, you should update your requirements within tasks/requirements.txt', code=1 + ) from e + + os.environ['TASKS_DEBUG'] = '1' + + if not (Path(VSCODE_DIR) / VSCODE_LAUNCH_FILE).exists(): + print( + f"{color_message('warning:', Color.ORANGE)} {color_message('(For VS Code users)', Color.BLUE)} No launch.json file found, you should run `inv vscode.setup-launch` to have a debug configuration.", + ) + + debugpy.listen((host, port)) + if wait: + print(color_message('info:', Color.BLUE), f'Waiting for debugger to attach on port {port}...') + debugpy.wait_for_client() diff --git a/tasks/invoke_unit_tests.py b/tasks/invoke_unit_tests.py index 3bfdc8db4beb4..a71a591a438f3 100644 --- a/tasks/invoke_unit_tests.py +++ b/tasks/invoke_unit_tests.py @@ -1,4 +1,4 @@ -import sys +import os from invoke import task from invoke.exceptions import Exit @@ -18,9 +18,13 @@ @task(default=True) -def run(ctx, tests: str = '', flags: str = '-b'): +def run(ctx, tests: str = '', buffer: bool = True, verbosity: int = 1, debug: bool = True): """ Run the unit tests on the invoke tasks + + - buffer: Buffer stdout / stderr from tests, useful to avoid interleaving output from tests + - verbosity: Level of verbosity + - debug: If True, will propagate errors to the debugger """ tests = [test for test in tests.split(',') if test] @@ -33,8 +37,7 @@ def run(ctx, tests: str = '', flags: str = '-b'): print(color_message('Running tests from module', Color.BLUE), color_message(f'{test}_tests', Color.BOLD)) pattern = '*_tests.py' if len(tests) == 0 else test + '_tests.py' - command = f"'{sys.executable}' -m unittest discover {flags} -s tasks -p '{pattern}'" - if not run_unit_tests_command(ctx, command): + if not run_unit_tests(ctx, pattern, buffer, verbosity, debug): error = True # Throw error if more than one module fails @@ -44,14 +47,34 @@ def run(ctx, tests: str = '', flags: str = '-b'): else: raise Exit(code=1) else: - command = f"'{sys.executable}' -m unittest discover {flags} -s tasks -p '*_tests.py'" - if not run_unit_tests_command(ctx, command): + pattern = '*_tests.py' + if not run_unit_tests(ctx, pattern, buffer, verbosity, debug): raise Exit(code=1) -def run_unit_tests_command(ctx, command): - return ctx.run( - command, - env=TEST_ENV, - warn=True, - ) +def run_unit_tests(_, pattern, buffer, verbosity, debug): + import unittest + + old_environ = os.environ.copy() + + try: + # Update env + for key, value in TEST_ENV.items(): + if key not in os.environ: + os.environ[key] = value + + loader = unittest.TestLoader() + suite = loader.discover('.', pattern=pattern) + if debug and 'TASKS_DEBUG' in os.environ: + suite.debug() + + # Will raise an error if the tests fail + return True + else: + runner = unittest.TextTestRunner(buffer=buffer, verbosity=verbosity) + + return runner.run(suite).wasSuccessful() + finally: + # Restore env + os.environ.clear() + os.environ.update(old_environ) diff --git a/tasks/libs/ciproviders/gitlab_api.py b/tasks/libs/ciproviders/gitlab_api.py index 7d74cc0737346..5b98e72369526 100644 --- a/tasks/libs/ciproviders/gitlab_api.py +++ b/tasks/libs/ciproviders/gitlab_api.py @@ -18,6 +18,7 @@ from invoke.exceptions import Exit from tasks.libs.common.color import Color, color_message +from tasks.libs.common.git import get_common_ancestor, get_current_branch from tasks.libs.common.utils import retry_function BASE_URL = "https://gitlab.ddbuild.io" @@ -868,3 +869,58 @@ def retrieve_all_paths(yaml): elif isinstance(yaml, list): for item in yaml: yield from retrieve_all_paths(item) + + +def gitlab_configuration_is_modified(ctx): + branch = get_current_branch(ctx) + if branch == "main": + # We usually squash merge on main so comparing only to the last commit + diff = ctx.run("git diff HEAD^1..HEAD", hide=True).stdout.strip().splitlines() + else: + # On dev branch we compare all the new commits + ctx.run("git fetch origin main:main") + ancestor = get_common_ancestor(ctx, branch) + diff = ctx.run(f"git diff {ancestor}..HEAD", hide=True).stdout.strip().splitlines() + modified_files = re.compile(r"^diff --git a/(.*) b/(.*)") + changed_lines = re.compile(r"^@@ -\d+,\d+ \+(\d+),(\d+) @@") + leading_space = re.compile(r"^(\s*).*$") + in_config = False + for line in diff: + if line.startswith("diff --git"): + files = modified_files.match(line) + new_file = files.group(1) + # Third condition is only for testing purposes + if ( + new_file.startswith(".gitlab") and new_file.endswith(".yml") + ) or "testdata/yaml_configurations" in new_file: + in_config = True + print(f"Found a gitlab configuration file: {new_file}") + else: + in_config = False + if in_config and line.startswith("@@"): + lines = changed_lines.match(line) + start = int(lines.group(1)) + with open(new_file) as f: + content = f.readlines() + item = leading_space.match(content[start]) + if item: + for above_line in reversed(content[:start]): + current = leading_space.match(above_line) + if current[1] < item[1]: + if any(keyword in above_line for keyword in ["needs:", "dependencies:"]): + print(f"> Found a gitlab configuration change on line: {content[start]}") + return True + else: + break + if ( + in_config + and line.startswith("+") + and ( + (len(line) > 1 and line[1].isalpha()) + or any(keyword in line for keyword in ["needs:", "dependencies:", "!reference"]) + ) + ): + print(f"> Found a gitlab configuration change on line: {line}") + return True + + return False diff --git a/tasks/libs/common/git.py b/tasks/libs/common/git.py index 14348401f612e..fc85b12241629 100644 --- a/tasks/libs/common/git.py +++ b/tasks/libs/common/git.py @@ -54,6 +54,10 @@ def get_current_branch(ctx) -> str: return ctx.run("git rev-parse --abbrev-ref HEAD", hide=True).stdout.strip() +def get_common_ancestor(ctx, branch) -> str: + return ctx.run(f"git merge-base {branch} main", hide=True).stdout.strip() + + def check_uncommitted_changes(ctx): """ Checks if there are uncommitted changes in the local git repository. diff --git a/tasks/libs/pipeline/data.py b/tasks/libs/pipeline/data.py index 4a4bcb4209bbc..eedb71b07df32 100644 --- a/tasks/libs/pipeline/data.py +++ b/tasks/libs/pipeline/data.py @@ -1,7 +1,7 @@ import re from collections import defaultdict -from gitlab.v4.objects import ProjectJob, ProjectPipeline +from gitlab.v4.objects import ProjectJob, ProjectPipeline, ProjectPipelineBridge from tasks.libs.ciproviders.gitlab_api import get_gitlab_repo from tasks.libs.types.types import FailedJobReason, FailedJobs, FailedJobType @@ -13,6 +13,9 @@ def get_failed_jobs(pipeline: ProjectPipeline) -> FailedJobs: """ repo = get_gitlab_repo(pipeline.project_id) jobs = pipeline.jobs.list(per_page=100, all=True) + bridges = pipeline.bridges.list(per_page=100, all=True) + # Add bridge jobs to the list of jobs, as they can fail the pipeline + jobs.extend(bridges) # Get instances of failed jobs grouped by name failed_jobs = defaultdict(list) @@ -31,7 +34,7 @@ def get_failed_jobs(pipeline: ProjectPipeline) -> FailedJobs: job = jobs[-1] # Check the final job in the list: it contains the current status of the job # This excludes jobs that were retried and succeeded - trace = str(repo.jobs.get(job.id, lazy=True).trace(), 'utf-8') + trace = str(repo.jobs.get(job.id, lazy=True).trace(), 'utf-8') if isinstance(job, ProjectJob) else "" failure_type, failure_reason = get_job_failure_context(job, trace) final_status = ProjectJob( repo.manager, @@ -40,7 +43,7 @@ def get_failed_jobs(pipeline: ProjectPipeline) -> FailedJobs: "id": job.id, "stage": job.stage, "status": job.status, - "tag_list": job.tag_list, + "tag_list": job.tag_list if isinstance(job, ProjectJob) else [], "allow_failure": job.allow_failure, "web_url": job.web_url, "retry_summary": [ijob.status for ijob in jobs], @@ -125,11 +128,13 @@ def get_infra_failure_info(job_log: str): return type -def get_job_failure_context(job: ProjectJob, job_log: str): +def get_job_failure_context(job: ProjectJob | ProjectPipelineBridge, job_log: str): """ Parses job logs (provided as a string), and returns the type of failure (infra or job) as well as the precise reason why the job failed. """ + if isinstance(job, ProjectPipelineBridge): + return FailedJobType.BRIDGE_FAILURE, FailedJobReason.FAILED_BRIDGE_JOB infra_failure_reasons = FailedJobReason.get_infra_failure_mapping().keys() diff --git a/tasks/libs/types/types.py b/tasks/libs/types/types.py index bc581fbbc2124..cd8e13c9fa37f 100644 --- a/tasks/libs/types/types.py +++ b/tasks/libs/types/types.py @@ -43,6 +43,7 @@ def key(self): class FailedJobType(Enum): JOB_FAILURE = 1 INFRA_FAILURE = 2 + BRIDGE_FAILURE = 3 class FailedJobReason(Enum): @@ -53,6 +54,7 @@ class FailedJobReason(Enum): KITCHEN = 7 EC2_SPOT = 8 E2E_INFRA_FAILURE = 9 + FAILED_BRIDGE_JOB = 10 @staticmethod def get_infra_failure_mapping(): diff --git a/tasks/linter.py b/tasks/linter.py index 153c518a7262b..5b63225720ce4 100644 --- a/tasks/linter.py +++ b/tasks/linter.py @@ -16,6 +16,7 @@ from tasks.libs.ciproviders.gitlab_api import ( generate_gitlab_full_configuration, get_all_gitlab_ci_configurations, + get_gitlab_ci_configuration, get_gitlab_repo, get_preset_contexts, load_context, @@ -456,14 +457,104 @@ def update_go(_): @task(iterable=['job_files']) -def test_change_path(ctx, job_files=None): +def job_change_path(ctx, job_files=None): """ Verify that the jobs defined within job_files contain a change path rule. """ + + tests_without_change_path_allow_list = { + 'generate-flakes-finder-pipeline', + 'k8s-e2e-cspm-dev', + 'k8s-e2e-cspm-main', + 'k8s-e2e-otlp-dev', + 'k8s-e2e-otlp-main', + 'new-e2e-agent-platform-install-script-amazonlinux-a6-arm64', + 'new-e2e-agent-platform-install-script-amazonlinux-a6-x86_64', + 'new-e2e-agent-platform-install-script-amazonlinux-a7-arm64', + 'new-e2e-agent-platform-install-script-amazonlinux-a7-x64', + 'new-e2e-agent-platform-install-script-centos-a6-x86_64', + 'new-e2e-agent-platform-install-script-centos-a7-x86_64', + 'new-e2e-agent-platform-install-script-centos-dogstatsd-a7-x86_64', + 'new-e2e-agent-platform-install-script-centos-fips-a6-x86_64', + 'new-e2e-agent-platform-install-script-centos-fips-a7-x86_64', + 'new-e2e-agent-platform-install-script-centos-fips-dogstatsd-a7-x86_64', + 'new-e2e-agent-platform-install-script-centos-fips-iot-agent-a7-x86_64', + 'new-e2e-agent-platform-install-script-centos-iot-agent-a7-x86_64', + 'new-e2e-agent-platform-install-script-debian-a6-arm64', + 'new-e2e-agent-platform-install-script-debian-a6-x86_64', + 'new-e2e-agent-platform-install-script-debian-a7-arm64', + 'new-e2e-agent-platform-install-script-debian-a7-x86_64', + 'new-e2e-agent-platform-install-script-debian-dogstatsd-a7-x86_64', + 'new-e2e-agent-platform-install-script-debian-heroku-agent-a6-x86_64', + 'new-e2e-agent-platform-install-script-debian-heroku-agent-a7-x86_64', + 'new-e2e-agent-platform-install-script-debian-iot-agent-a7-x86_64', + 'new-e2e-agent-platform-install-script-suse-a6-x86_64', + 'new-e2e-agent-platform-install-script-suse-a7-arm64', + 'new-e2e-agent-platform-install-script-suse-a7-x86_64', + 'new-e2e-agent-platform-install-script-suse-dogstatsd-a7-x86_64', + 'new-e2e-agent-platform-install-script-suse-iot-agent-a7-x86_64', + 'new-e2e-agent-platform-install-script-ubuntu-a6-arm64', + 'new-e2e-agent-platform-install-script-ubuntu-a6-x86_64', + 'new-e2e-agent-platform-install-script-ubuntu-a7-arm64', + 'new-e2e-agent-platform-install-script-ubuntu-a7-x86_64', + 'new-e2e-agent-platform-install-script-ubuntu-dogstatsd-a7-x86_64', + 'new-e2e-agent-platform-install-script-ubuntu-heroku-agent-a6-x86_64', + 'new-e2e-agent-platform-install-script-ubuntu-heroku-agent-a7-x86_64', + 'new-e2e-agent-platform-install-script-ubuntu-iot-agent-a7-x86_64', + 'new-e2e-agent-platform-install-script-upgrade6-amazonlinux-x64', + 'new-e2e-agent-platform-install-script-upgrade6-centos-fips-x86_64', + 'new-e2e-agent-platform-install-script-upgrade6-centos-x86_64', + 'new-e2e-agent-platform-install-script-upgrade6-debian-x86_64', + 'new-e2e-agent-platform-install-script-upgrade6-suse-x86_64', + 'new-e2e-agent-platform-install-script-upgrade6-ubuntu-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-amazonlinux-iot-agent-x64', + 'new-e2e-agent-platform-install-script-upgrade7-amazonlinux-x64', + 'new-e2e-agent-platform-install-script-upgrade7-centos-fips-iot-agent-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-centos-fips-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-centos-iot-agent-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-centos-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-debian-iot-agent-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-debian-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-suse-iot-agent-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-suse-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-ubuntu-iot-agent-x86_64', + 'new-e2e-agent-platform-install-script-upgrade7-ubuntu-x86_64', + 'new-e2e-agent-platform-package-signing-amazonlinux-a6-x86_64', + 'new-e2e-agent-platform-package-signing-debian-a7-x86_64', + 'new-e2e-agent-platform-package-signing-suse-a7-x86_64', + 'new-e2e-agent-platform-rpm-centos6-a7-x86_64', + 'new-e2e-agent-platform-step-by-step-amazonlinux-a6-arm64', + 'new-e2e-agent-platform-step-by-step-amazonlinux-a6-x86_64', + 'new-e2e-agent-platform-step-by-step-amazonlinux-a7-arm64', + 'new-e2e-agent-platform-step-by-step-amazonlinux-a7-x64', + 'new-e2e-agent-platform-step-by-step-centos-a6-x86_64', + 'new-e2e-agent-platform-step-by-step-centos-a7-x86_64', + 'new-e2e-agent-platform-step-by-step-debian-a6-arm64', + 'new-e2e-agent-platform-step-by-step-debian-a6-x86_64', + 'new-e2e-agent-platform-step-by-step-debian-a7-arm64', + 'new-e2e-agent-platform-step-by-step-debian-a7-x64', + 'new-e2e-agent-platform-step-by-step-suse-a6-x86_64', + 'new-e2e-agent-platform-step-by-step-suse-a7-arm64', + 'new-e2e-agent-platform-step-by-step-suse-a7-x86_64', + 'new-e2e-agent-platform-step-by-step-ubuntu-a6-arm64', + 'new-e2e-agent-platform-step-by-step-ubuntu-a6-x86_64', + 'new-e2e-agent-platform-step-by-step-ubuntu-a7-arm64', + 'new-e2e-agent-platform-step-by-step-ubuntu-a7-x86_64', + 'new-e2e-agent-shared-components', + 'new-e2e-cws', + 'new-e2e-language-detection', + 'new-e2e-npm-docker', + 'new-e2e-npm-packages', + 'new-e2e-orchestrator', + 'new-e2e_windows_powershell_module_test', + 'trigger-flakes-finder', + } + job_files = job_files or (['.gitlab/e2e/e2e.yml'] + list(glob('.gitlab/kitchen_testing/new-e2e_testing/*.yml'))) - # Read gitlab config - config = generate_gitlab_full_configuration(ctx, ".gitlab-ci.yml", {}, return_dump=False, apply_postprocessing=True) + # Read and parse gitlab config + # The config is filtered to only include jobs + config = get_gitlab_ci_configuration(ctx, ".gitlab-ci.yml") # Fetch all test jobs test_config = read_includes(ctx, job_files, return_config=True, add_file_path=True) @@ -483,20 +574,40 @@ def contains_valid_change_rule(rule): # Verify that all tests contain a change path rule tests_without_change_path = defaultdict(list) + tests_without_change_path_allowed = defaultdict(list) for test, filepath in tests: if not any(contains_valid_change_rule(rule) for rule in config[test]['rules'] if isinstance(rule, dict)): - tests_without_change_path[filepath].append(test) + if test in tests_without_change_path_allow_list: + tests_without_change_path_allowed[filepath].append(test) + else: + tests_without_change_path[filepath].append(test) + + if len(tests_without_change_path_allowed) != 0: + with gitlab_section('Allow-listed jobs', collapsed=True): + print( + color_message( + 'warning: The following tests do not contain required change paths rule but are allowed:', + Color.ORANGE, + ) + ) + for filepath, tests in tests_without_change_path_allowed.items(): + print(f"- {color_message(filepath, Color.BLUE)}: {', '.join(tests)}") + print(color_message('warning: End of allow-listed jobs', Color.ORANGE)) + print() if len(tests_without_change_path) != 0: print(color_message("error: Tests without required change paths rule:", "red"), file=sys.stderr) for filepath, tests in tests_without_change_path.items(): - print(f"- {color_message(filepath, 'bold')}: {', '.join(tests)}", file=sys.stderr) + print(f"- {color_message(filepath, Color.BLUE)}: {', '.join(tests)}", file=sys.stderr) raise RuntimeError( - 'Some tests do not contain required change paths rule, they must contain at least one non-test path.' + color_message( + 'Some tests do not contain required change paths rule, they must contain at least one non-test path.', + Color.RED, + ) ) else: - print(color_message("success: All tests contain a change paths rule", "green")) + print(color_message("success: All tests contain a change paths rule or are allow-listed", "green")) @task diff --git a/tasks/modules.py b/tasks/modules.py index f60d8a0c77ed9..f1b76e73e0bc0 100644 --- a/tasks/modules.py +++ b/tasks/modules.py @@ -140,7 +140,10 @@ def dependency_path(self, agent_version): "comp/core/hostname/hostnameinterface": GoModule( "comp/core/hostname/hostnameinterface", independent=True, used_by_otel=True ), - "comp/core/log": GoModule("comp/core/log", independent=True, used_by_otel=True), + "comp/core/log/def": GoModule("comp/core/log/def", independent=True, used_by_otel=True), + "comp/core/log/impl": GoModule("comp/core/log/impl", independent=True, used_by_otel=True), + "comp/core/log/impl-trace": GoModule("comp/core/log/impl-trace", independent=True), + "comp/core/log/mock": GoModule("comp/core/log/mock", independent=True, used_by_otel=True), "comp/core/secrets": GoModule("comp/core/secrets", independent=True, used_by_otel=True), "comp/core/status": GoModule("comp/core/status", independent=True, used_by_otel=True), "comp/core/status/statusimpl": GoModule("comp/core/status/statusimpl", independent=True), diff --git a/tasks/pipeline.py b/tasks/pipeline.py index dd5205e5e6b15..ac7bb4808db89 100644 --- a/tasks/pipeline.py +++ b/tasks/pipeline.py @@ -12,8 +12,13 @@ from invoke.exceptions import Exit from tasks.libs.ciproviders.github_api import GithubAPI -from tasks.libs.ciproviders.gitlab_api import get_gitlab_bot_token, get_gitlab_repo, refresh_pipeline -from tasks.libs.common.color import color_message +from tasks.libs.ciproviders.gitlab_api import ( + get_gitlab_bot_token, + get_gitlab_repo, + gitlab_configuration_is_modified, + refresh_pipeline, +) +from tasks.libs.common.color import Color, color_message from tasks.libs.common.constants import DEFAULT_BRANCH, GITHUB_REPO_NAME from tasks.libs.common.git import check_clean_branch_state, get_commit_sha, get_current_branch from tasks.libs.common.utils import ( @@ -32,6 +37,8 @@ ) from tasks.libs.releasing.documentation import nightly_entry_for, release_entry_for +BOT_NAME = "github-actions[bot]" + class GitlabReference(yaml.YAMLObject): def __init__(self, refs): @@ -991,3 +998,74 @@ def test_merge_queue(ctx): ctx.run(f"git push origin :{test_main}", hide=True) if not success: raise Exit(message="Merge queue test failed", code=1) + + +@task +def compare_to_itself(ctx): + """ + Create a new branch with 'compare_to_itself' in gitlab-ci.yml and trigger a pipeline + """ + if not gitlab_configuration_is_modified(ctx): + print("No modification in the gitlab configuration, ignoring this test.") + return + agent = get_gitlab_repo() + gh = GithubAPI() + current_branch = os.environ["CI_COMMIT_REF_NAME"] + if current_branch.startswith("compare/"): + print("Branch already in compare_to_itself mode, ignoring this test to prevent infinite loop") + return + new_branch = f"compare/{current_branch}/{int(datetime.now(timezone.utc).timestamp())}" + ctx.run(f"git checkout -b {new_branch}", hide=True) + ctx.run( + f"git remote set-url origin https://x-access-token:{gh._auth.token}@github.com/DataDog/datadog-agent.git", + hide=True, + ) + ctx.run(f"git config --global user.name '{BOT_NAME}'") + ctx.run("git config --global user.email 'github-app[bot]@users.noreply.github.com'") + # The branch must exist in gitlab to be able to "compare_to" + ctx.run(f"git push origin {new_branch}", hide=True) + for file in ['.gitlab-ci.yml', '.gitlab/notify/notify.yml']: + with open(file) as f: + content = f.read() + with open(file, 'w') as f: + f.write(content.replace('compare_to: main', f'compare_to: {new_branch}')) + ctx.run("git commit -am 'Compare to itself'", hide=True) + ctx.run(f"git push origin {new_branch}", hide=True) + max_attempts = 6 + compare_to_pipeline = None + for attempt in range(max_attempts): + print(f"[{datetime.now()}] Waiting 30s for the pipelines to be created") + time.sleep(30) + pipelines = agent.pipelines.list(ref=new_branch, get_all=True) + for pipeline in pipelines: + commit = agent.commits.get(pipeline.sha) + if commit.author_name == BOT_NAME: + compare_to_pipeline = pipeline + print(f"Test pipeline found: {pipeline.web_url}") + if compare_to_pipeline: + break + if attempt == max_attempts - 1: + # Clean up the branch and possible pipelines + for pipeline in pipelines: + pipeline.cancel() + ctx.run(f"git checkout {current_branch}", hide=True) + ctx.run(f"git branch -D {new_branch}", hide=True) + ctx.run(f"git push origin :{new_branch}", hide=True) + raise RuntimeError(f"No pipeline found for {new_branch}") + try: + if len(compare_to_pipeline.jobs.list(get_all=False)) == 0: + print( + f"[{color_message('ERROR', Color.RED)}] Failed to generate a pipeline for {new_branch}, please check {compare_to_pipeline.web_url}" + ) + raise Exit(message="compare_to itself failed", code=1) + else: + print(f"Pipeline correctly created, {color_message('congrats', Color.GREEN)}") + finally: + # Clean up + print("Cleaning up the pipelines") + for pipeline in pipelines: + pipeline.cancel() + print("Cleaning up git") + ctx.run(f"git checkout {current_branch}", hide=True) + ctx.run(f"git branch -D {new_branch}", hide=True) + ctx.run(f"git push origin :{new_branch}", hide=True) diff --git a/tasks/requirements.txt b/tasks/requirements.txt index 93a0d2b163405..a56ac30a3177d 100644 --- a/tasks/requirements.txt +++ b/tasks/requirements.txt @@ -5,3 +5,4 @@ -r requirements_docs.txt python-gitlab==4.4.0 +debugpy==1.8.2 diff --git a/tasks/testwasher.py b/tasks/testwasher.py index 60e45077fdfe9..1523e1aa9c72e 100644 --- a/tasks/testwasher.py +++ b/tasks/testwasher.py @@ -171,7 +171,7 @@ def get_tests_family(self, test_name_list): return test_family -@task() +@task def generate_flake_finder_pipeline(ctx, n=3): """ Generate a child pipeline where jobs marked with SHOULD_RUN_IN_FLAKES_FINDER are run n times @@ -194,22 +194,18 @@ def generate_flake_finder_pipeline(ctx, n=3): continue kept_job[job] = job_details + deps_job = copy.deepcopy(config["go_e2e_deps"]) + # Remove needs, rules, extends and retry from the jobs - for job in kept_job: - if 'needs' in kept_job[job]: - del kept_job[job]["needs"] - if 'rules' in kept_job[job]: - del kept_job[job]["rules"] - if 'retry' in kept_job[job]: - del kept_job[job]["retry"] - if 'extends' in kept_job[job]: - del kept_job[job]["extends"] + for job in [deps_job] + list(kept_job.values()): + _clean_job(job) new_jobs = {} + new_jobs["go_e2e_deps"] = deps_job new_jobs['variables'] = copy.deepcopy(config['variables']) new_jobs['variables']['PARENT_PIPELINE_ID'] = 'undefined' new_jobs['variables']['PARENT_COMMIT_SHA'] = 'undefined' - new_jobs['stages'] = [f'flake-finder-{i}' for i in range(n)] + new_jobs['stages'] = [deps_job["stage"]] + [f'flake-finder-{i}' for i in range(n)] # Create n jobs with the same configuration for job in kept_job: @@ -229,6 +225,7 @@ def generate_flake_finder_pipeline(ctx, n=3): ): new_job['variables']['E2E_COMMIT_SHA'] = "$PARENT_COMMIT_SHA" new_job["rules"] = [{"when": "always"}] + new_job["needs"] = ["go_e2e_deps"] new_jobs[f"{job}-{i}"] = new_job with open("flake-finder-gitlab-ci.yml", "w") as f: @@ -236,3 +233,13 @@ def generate_flake_finder_pipeline(ctx, n=3): with gitlab_section("Flake finder generated pipeline", collapsed=True): print(yaml.safe_dump(new_jobs)) + + +def _clean_job(job): + """ + Remove the needs, rules, extends and retry from the job + """ + for step in ('needs', 'rules', 'extends', 'retry'): + if step in job: + del job[step] + return job diff --git a/tasks/unit_tests/commands/docker_tests.py b/tasks/unit_tests/commands/docker_tests.py index 5d6cf28e3a0fa..10744eee3408d 100644 --- a/tasks/unit_tests/commands/docker_tests.py +++ b/tasks/unit_tests/commands/docker_tests.py @@ -12,6 +12,13 @@ def setUp(self) -> None: @patch('invoke.run') def test_run_command(self, mock): self.interface.run_command(["echo", "Hello, World!"]) - mock.assert_called_once_with( - "docker exec -w /workspaces/datadog-agent my-container echo 'Hello, World!'", pty=True + mock.assert_called_once() + + # This test may be launched from a tty or not + self.assertIn( + mock.call_args[0][0], + [ + "docker exec -it -w /workspaces/datadog-agent my-container echo 'Hello, World!'", + "docker exec -w /workspaces/datadog-agent my-container echo 'Hello, World!'", + ], ) diff --git a/tasks/unit_tests/gitlab_api_tests.py b/tasks/unit_tests/gitlab_api_tests.py index 7c7c073b960eb..a200974805051 100644 --- a/tasks/unit_tests/gitlab_api_tests.py +++ b/tasks/unit_tests/gitlab_api_tests.py @@ -1,11 +1,13 @@ import unittest +from unittest.mock import MagicMock, patch -from invoke.context import MockContext +from invoke import MockContext, Result from tasks.libs.ciproviders.gitlab_api import ( GitlabCIDiff, clean_gitlab_ci_configuration, filter_gitlab_ci_configuration, + gitlab_configuration_is_modified, read_includes, retrieve_all_paths, ) @@ -195,3 +197,90 @@ def test_all_configs(self): 'hand_of_the_king', ] self.assertListEqual(paths, expected_paths) + + +class TestGitlabConfigurationIsModified(unittest.TestCase): + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_needs_one_line(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..e9a74219ba 100644\n--- a/{file}\n+++ b/{file}\n@@ -4,7 +4,7 @@\n \n .linux_tests:\n stage: source_test\n- needs: ["go_deps", "go_tools_deps"]\n+ needs: ["go_deps", "go_tools_deps", "new"]\n rules:\n - !reference [.except_disable_unit_tests]\n - !reference [.fast_on_dev_branch_only]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertTrue(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_reference_one_line(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..e9a74219ba 100644\n--- a/{file}\n+++ b/{file}\n@@ -4,7 +4,7 @@\n \n .linux_tests:\n stage: source_test\n needs: ["go_deps", "go_tools_deps"]\n rules:\n+ - !reference [.adding_new_reference]\n - !reference [.except_disable_unit_tests]\n - !reference [.fast_on_dev_branch_only]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertTrue(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_needs_removed(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..e9a74219ba 100644\n--- a/{file}\n+++ b/{file}\n@@ -4,6 +4,6 @@\n \n .linux_tests:\n stage: source_test\n- needs: ["go_deps", "go_tools_deps"]\n rules:\n - !reference [.except_disable_unit_tests]\n - !reference [.fast_on_dev_branch_only]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertFalse(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_artifacts_modified_and_needs_above(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..e9a74219ba 100644\n--- a/{file}\n+++ b/{file}\n@@ -12,6 +12,6 @@\n \n artifacts:\n expire_in: 2 years\n- when: always\n+ when: never\n paths:\n - none-shall-pass.txt' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertFalse(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_needs_multiple_lines(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_several_lines.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..e9a74219ba 100644\n--- a/{file}\n+++ b/{file}\n@@ -6,7 +6,7 @@\n \n - go_tools_deps\n - go_go_dancer\n - go_go_ackman\n+ - go_nagai\n rules:\n - !reference [.except_disable_unit_tests]\n - !reference [.fast_on_dev_branch_only]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertTrue(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_not_a_needs_multiple_lines(self): + file = "tasks/unit_tests/testdata/yaml_configurations/no_needs_several_lines.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..e9a74219ba 100644\n--- a/{file}\n+++ b/{file}\n@@ -6,7 +6,7 @@\n \n - go_tools_deps\n - go_go_dancer\n - go_go_ackman\n+ - go_nagai\n rules:\n - !reference [.except_disable_unit_tests]\n - !reference [.fast_on_dev_branch_only]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertFalse(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_new_reference(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..5e43218090 100644\n--- a/{file}\n+++ b/{file}\n@@ -1,4 +1,11 @@\n ---\n+.rtloader_tests:\n+ stage: source_test\n+ noods: ["go_deps"]\n+ before_script:\n+ - source /root/.bashrc && conda activate $CONDA_ENV\n+ script: ["# Skipping go tests"]\n+\n nerd_tests\n stage: source_test\n needs: ["go_deps"]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertFalse(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_new_reference_with_needs(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..5e43218090 100644\n--- a/{file}\n+++ b/{file}\n@@ -1,4 +1,11 @@\n ---\n+.rtloader_tests:\n+ stage: source_test\n+ needs: ["go_deps"]\n+ before_script:\n+ - source /root/.bashrc && conda activate $CONDA_ENV\n+ script: ["# Skipping go tests"]\n+\n nerd_tests\n stage: source_test\n needs: ["go_deps"]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertTrue(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_new_reference_with_dependencies(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..5e43218090 100644\n--- a/{file}\n+++ b/{file}\n@@ -1,4 +1,11 @@\n ---\n+.rtloader_tests:\n+ stage: source_test\n+ dependencies: ["go_deps"]\n+ before_script:\n+ - source /root/.bashrc && conda activate $CONDA_ENV\n+ script: ["# Skipping go tests"]\n+\n nerd_tests\n stage: source_test\n needs: ["go_deps"]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertTrue(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_new_job(self): + file = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..5e43218090 100644\n--- a/{file}\n+++ b/{file}\n@@ -1,4 +1,11 @@\n ---\n+rtloader_tests:\n+ stage: source_test\n+ noods: ["go_deps"]\n+ before_script:\n+ - source /root/.bashrc && conda activate $CONDA_ENV\n+ script: ["# Skipping go tests"]\n+\n nerd_tests\n stage: source_test\n needs: ["go_deps"]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertTrue(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_ignored_file(self): + file = "tasks/unit_tests/testdata/d.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..5e43218090 100644\n--- a/{file}\n+++ b/{file}\n@@ -1,4 +1,11 @@\n ---\n+rtloader_tests:\n+ stage: source_test\n+ needs: ["go_deps"]\n+ before_script:\n+ - source /root/.bashrc && conda activate $CONDA_ENV\n+ script: ["# Skipping go tests"]\n+\n nerd_tests\n stage: source_test\n needs: ["go_deps"]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertFalse(gitlab_configuration_is_modified(c)) + + @patch("tasks.libs.ciproviders.gitlab_api.get_current_branch", new=MagicMock(return_value="main")) + def test_two_modified_files(self): + file = "tasks/unit_tests/testdata/d.yml" + yaml = "tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml" + diff = f'diff --git a/{file} b/{file}\nindex 561eb1a201..5e43218090 100644\n--- a/{file}\n+++ b/{file}\n@@ -1,4 +1,11 @@\n ---\n+rtloader_tests:\n+ stage: source_test\n+ needs: ["go_deps"]\n+ before_script:\n+ - source /root/.bashrc && conda activate $CONDA_ENV\n+ script: ["# Skipping go tests"]\n+\n nerd_tests\n stage: source_test\n needs: ["go_deps"]\ndiff --git a/{yaml} b/{yaml}\nindex 561eb1a201..5e43218090 100644\n--- a/{yaml}\n+++ b/{yaml}\n@@ -1,4 +1,11 @@\n ---\n+rtloader_tests:\n+ stage: source_test\n+ noods: ["go_deps"]\n+ before_script:\n+ - source /root/.bashrc && conda activate $CONDA_ENV\n+ script: ["# Skipping go tests"]\n+\n nerd_tests\n stage: source_test\n needs: ["go_deps"]' + c = MockContext(run={"git diff HEAD^1..HEAD": Result(diff)}) + self.assertTrue(gitlab_configuration_is_modified(c)) diff --git a/tasks/unit_tests/pipeline_tests.py b/tasks/unit_tests/pipeline_tests.py index 1b39749b98688..ad3da9a10586a 100644 --- a/tasks/unit_tests/pipeline_tests.py +++ b/tasks/unit_tests/pipeline_tests.py @@ -1,5 +1,6 @@ import subprocess import unittest +from datetime import datetime, timezone from unittest.mock import MagicMock, patch import yaml @@ -96,3 +97,134 @@ def test_update_no_test(self): def test_raise(self): with self.assertRaises(RuntimeError): pipeline.update_circleci_config(self.erroneous_file, "1m4g3", test_version=False) + + +class TestCompareToItself(unittest.TestCase): + context = MockContext( + run={ + "git checkout -b compare/Football/900284400": Result(), + "git remote set-url origin https://x-access-token:zidane@github.com/DataDog/datadog-agent.git": Result(), + "git config --global user.name 'github-actions[bot]'": Result(), + "git config --global user.email 'github-app[bot]@users.noreply.github.com'": Result(), + "git push origin compare/Football/900284400": Result(), + "git commit -am 'Compare to itself'": Result(), + "git checkout Football": Result(), + "git branch -D compare/Football/900284400": Result(), + "git push origin :compare/Football/900284400": Result(), + } + ) + now = datetime(1998, 7, 12, 23, 0, 0, tzinfo=timezone.utc) + + @staticmethod + def side(x): + if x == "c0mm1t": + return MagicMock(author_name=pipeline.BOT_NAME) + else: + return MagicMock(author_name="Aimee Jaquet") + + def setUp(self) -> None: + self.gh = MagicMock() + self.gh._auth.token = "zidane" + self.commits = MagicMock() + self.commits.get.side_effect = self.side + + @patch('tasks.pipeline.gitlab_configuration_is_modified', new=MagicMock(return_value=True)) + @patch('builtins.open', new=MagicMock()) + @patch.dict('os.environ', {"CI_COMMIT_REF_NAME": "Football"}) + @patch('tasks.pipeline.time', new=MagicMock()) + @patch('tasks.pipeline.datetime') + @patch('tasks.pipeline.GithubAPI') + @patch('tasks.pipeline.get_gitlab_repo') + def test_nominal(self, repo_mock, gh_mock, dt_mock): + dt_mock.now.return_value = self.now + gh_mock.return_value = self.gh + pipelines = MagicMock() + compare_to = MagicMock(sha="c0mm1t") + compare_to.jobs.list.return_value = [1, 2, 3] + pipelines.list.side_effect = [[], [], [compare_to], [], [], []] + agent = MagicMock() + agent.pipelines = pipelines + agent.commits = self.commits + repo_mock.return_value = agent + pipeline.compare_to_itself(self.context) + self.assertEqual(3, agent.pipelines.list.call_count) + + @patch('tasks.pipeline.gitlab_configuration_is_modified', new=MagicMock(return_value=True)) + @patch('builtins.open', new=MagicMock()) + @patch.dict('os.environ', {"CI_COMMIT_REF_NAME": "Football"}) + @patch('tasks.pipeline.time', new=MagicMock()) + @patch('tasks.pipeline.datetime') + @patch('tasks.pipeline.GithubAPI') + @patch('tasks.pipeline.get_gitlab_repo') + def test_no_pipeline_found(self, repo_mock, gh_mock, dt_mock): + dt_mock.now.return_value = self.now + gh_mock.return_value = self.gh + pipelines = MagicMock() + pipelines.list.side_effect = [[], [], [], [], [], []] + agent = MagicMock() + agent.pipelines = pipelines + agent.commits = self.commits + repo_mock.return_value = agent + with self.assertRaises(RuntimeError): + pipeline.compare_to_itself(self.context) + + @patch('tasks.pipeline.gitlab_configuration_is_modified', new=MagicMock(return_value=True)) + @patch('builtins.open', new=MagicMock()) + @patch.dict('os.environ', {"CI_COMMIT_REF_NAME": "Football"}) + @patch('tasks.pipeline.time', new=MagicMock()) + @patch('tasks.pipeline.datetime') + @patch('tasks.pipeline.GithubAPI') + @patch('tasks.pipeline.get_gitlab_repo') + def test_no_pipeline_found_again(self, repo_mock, gh_mock, dt_mock): + dt_mock.now.return_value = self.now + gh_mock.return_value = self.gh + pipelines = MagicMock() + compare_to = MagicMock(sha="w4lo0") + compare_to.jobs.list.return_value = [1, 2, 3] + pipelines.list.side_effect = [[], [], [compare_to], [], [], []] + agent = MagicMock() + agent.pipelines = pipelines + agent.commits = self.commits + repo_mock.return_value = agent + with self.assertRaises(RuntimeError): + pipeline.compare_to_itself(self.context) + + @patch('tasks.pipeline.gitlab_configuration_is_modified', new=MagicMock(return_value=True)) + @patch('builtins.open', new=MagicMock()) + @patch.dict('os.environ', {"CI_COMMIT_REF_NAME": "Football"}) + @patch('tasks.pipeline.time', new=MagicMock()) + @patch('tasks.pipeline.datetime') + @patch('tasks.pipeline.GithubAPI') + @patch('tasks.pipeline.get_gitlab_repo') + def test_pipeline_with_no_jobs(self, repo_mock, gh_mock, dt_mock): + dt_mock.now.return_value = self.now + gh_mock.return_value = self.gh + pipelines = MagicMock() + compare_to = MagicMock(sha="c0mm1t") + pipelines.list.side_effect = [[], [], [compare_to], [], [], []] + agent = MagicMock() + agent.pipelines = pipelines + agent.commits = self.commits + repo_mock.return_value = agent + with self.assertRaises(Exit): + pipeline.compare_to_itself(self.context) + + @patch('tasks.pipeline.gitlab_configuration_is_modified', new=MagicMock(return_value=True)) + @patch('builtins.open', new=MagicMock()) + @patch.dict('os.environ', {"CI_COMMIT_REF_NAME": "compare/Football"}) + @patch('tasks.pipeline.time', new=MagicMock()) + @patch('tasks.pipeline.datetime') + @patch('tasks.pipeline.GithubAPI') + @patch('tasks.pipeline.get_gitlab_repo') + def test_prevent_loop(self, repo_mock, gh_mock, dt_mock): + dt_mock.now.return_value = self.now + gh_mock.return_value = self.gh + pipelines = MagicMock() + compare_to = MagicMock(sha="c0mm1t") + pipelines.list.side_effect = [[], [], [compare_to], [], [], []] + agent = MagicMock() + agent.pipelines = pipelines + agent.commits = self.commits + repo_mock.return_value = agent + pipeline.compare_to_itself(self.context) + agent.pipelines.list.assert_not_called() diff --git a/tasks/unit_tests/testdata/d.yml b/tasks/unit_tests/testdata/d.yml new file mode 100644 index 0000000000000..7f71fd2b26494 --- /dev/null +++ b/tasks/unit_tests/testdata/d.yml @@ -0,0 +1,5 @@ +--- +new_job: + stage: wembley + needs: queen + rules: 1985 diff --git a/tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml b/tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml new file mode 100644 index 0000000000000..aa299ac8f499a --- /dev/null +++ b/tasks/unit_tests/testdata/yaml_configurations/needs_one_line.yml @@ -0,0 +1,20 @@ +--- +nerd_tests: + stage: source_test + needs: ["go_deps", "go_tools_deps"] + rules: + - !reference [.except_disable_unit_tests] + - !reference [.fast_on_dev_branch_only] + variables: + FLAVORS: '--flavor base' + script: + - inv -e need.do-i-really-need-to-test || true + artifacts: + expire_in: 2 years + when: always + paths: + - none-shall-pass.txt + reports: + junit: "*.xml" + annotations: + - $EXTERNAL_LINKS_PATH diff --git a/tasks/unit_tests/testdata/yaml_configurations/needs_several_lines.yml b/tasks/unit_tests/testdata/yaml_configurations/needs_several_lines.yml new file mode 100644 index 0000000000000..cc61236439ed5 --- /dev/null +++ b/tasks/unit_tests/testdata/yaml_configurations/needs_several_lines.yml @@ -0,0 +1,25 @@ +--- +nerd_tests: + stage: source_test + needs: + - go_deps + - go_tools_deps + - go_go_dancer + - go_go_ackman + - go_nagai + rules: + - !reference [.except_disable_unit_tests] + - !reference [.fast_on_dev_branch_only] + variables: + FLAVORS: '--flavor base' + script: + - inv -e need.do-i-really-need-to-test || true + artifacts: + expire_in: 2 years + when: always + paths: + - none-shall-pass.txt + reports: + junit: "*.xml" + annotations: + - $EXTERNAL_LINKS_PATH diff --git a/tasks/unit_tests/testdata/yaml_configurations/no_needs_several_lines.yml b/tasks/unit_tests/testdata/yaml_configurations/no_needs_several_lines.yml new file mode 100644 index 0000000000000..3abe7511b9835 --- /dev/null +++ b/tasks/unit_tests/testdata/yaml_configurations/no_needs_several_lines.yml @@ -0,0 +1,25 @@ +--- +nerd_tests: + stage: source_test + noods: + - go_deps + - go_tools_deps + - go_go_dancer + - go_go_ackman + - go_nagai + rules: + - !reference [.except_disable_unit_tests] + - !reference [.fast_on_dev_branch_only] + variables: + FLAVORS: '--flavor base' + script: + - inv -e need.do-i-really-need-to-test || true + artifacts: + expire_in: 2 years + when: always + paths: + - none-shall-pass.txt + reports: + junit: "*.xml" + annotations: + - $EXTERNAL_LINKS_PATH \ No newline at end of file diff --git a/tasks/vscode.py b/tasks/vscode.py index b91c8226d06a0..e528d188e1c79 100644 --- a/tasks/vscode.py +++ b/tasks/vscode.py @@ -22,11 +22,14 @@ from tasks.libs.json import JSONWithCommentsDecoder VSCODE_DIR = ".vscode" +VSCODE_LAUNCH_FILE = "launch.json" +VSCODE_LAUNCH_TEMPLATE = "launch.json.template" VSCODE_SETTINGS_FILE = "settings.json" VSCODE_SETTINGS_TEMPLATE = "settings.json.template" VSCODE_TASKS_FILE = "tasks.json" VSCODE_TASKS_TEMPLATE = "tasks.json.template" VSCODE_EXTENSIONS_FILE = "extensions.json" +VSCODE_PYTHON_ENV_FILE = ".env" @task @@ -40,9 +43,12 @@ def setup(ctx, force=False): setup_extensions(ctx) print(color_message("* Setting up tasks", Color.BOLD)) setup_tasks(ctx, force) + print(color_message("* Setting up tests", Color.BOLD)) + setup_tasks(ctx, force) print(color_message("* Setting up settings", Color.BOLD)) setup_settings(ctx, force) - # TODO: setup_launch (see #27508) + print(color_message("* Setting up launch settings", Color.BOLD)) + setup_launch(ctx, force) @task( @@ -134,6 +140,31 @@ def setup_extensions(ctx: Context): ctx.run(f"code --install-extension {extension} --force") +@task +def setup_tests(_, force=False): + """ + Setup the tests tab for vscode + + - Documentation: https://datadoghq.atlassian.net/wiki/x/z4Jf6 + """ + from invoke_unit_tests import TEST_ENV + + env = Path(VSCODE_PYTHON_ENV_FILE) + + print(color_message("Creating initial python environment file...", Color.BLUE)) + if env.exists(): + message = 'overriding current file' if force else 'skipping...' + print(color_message("warning:", Color.ORANGE), 'VSCode python environment file already exists,', message) + if not force: + return + + with open('.env', 'w') as f: + for key, value in TEST_ENV.items(): + print(f'{key}={value}', file=f) + + print(color_message('The .env file has been created', Color.GREEN)) + + @task def setup_tasks(_, force=False): """ @@ -185,3 +216,25 @@ def setup_settings(_, force=False): ).replace("'", '"') ) print(color_message("VSCode settings file created successfully.", Color.GREEN)) + + +@task +def setup_launch(_: Context, force=False): + """ + This creates the `.vscode/launch.json` file based on the `.vscode/launch.json.template` file + + - force: Force file override + """ + file = Path(VSCODE_DIR) / VSCODE_LAUNCH_FILE + template = Path(VSCODE_DIR) / VSCODE_LAUNCH_TEMPLATE + + print(color_message("Creating initial VSCode launch file...", Color.BLUE)) + if file.exists(): + message = 'overriding current file' if force else 'skipping...' + print(color_message("warning:", Color.ORANGE), 'VSCode launch file already exists,', message) + if not force: + return + + shutil.copy(template, file) + + print(color_message('Launch config created, open Run and Debug tab in VSCode to start debugging', Color.GREEN)) diff --git a/test/e2e/cws-tests/requirements.txt b/test/e2e/cws-tests/requirements.txt index a09b175f220f0..4a4ecbbbcc29e 100644 --- a/test/e2e/cws-tests/requirements.txt +++ b/test/e2e/cws-tests/requirements.txt @@ -1,6 +1,6 @@ kubernetes==30.1.0 datadog-api-client==2.26.0 -pyaml==24.4.0 +pyaml==24.7.0 docker==7.1.0 retry==0.9.2 emoji==2.12.1 diff --git a/test/fakeintake/server/redact.go b/test/fakeintake/server/redact.go new file mode 100644 index 0000000000000..722cb310a058b --- /dev/null +++ b/test/fakeintake/server/redact.go @@ -0,0 +1,37 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// Package server implements a dummy http Datadog intake, meant to be used with integration and e2e tests. +// It runs an catch-all http server that stores submitted payloads into a dictionary of [api.Payloads], indexed by the route +// It implements 3 testing endpoints: +// - /fakeintake/payloads/ returns any received payloads on the specified route as [api.Payload]s +// - /fakeintake/health returns current fakeintake server health +// - /fakeintake/routestats returns stats for collected payloads, by route +// - /fakeintake/flushPayloads returns all stored payloads and clear them up +// +// [api.Payloads]: https://pkg.go.dev/github.com/DataDog/datadog-agent@main/test/fakeintake/api#Payload +package server + +import ( + "net/http" + "strings" +) + +func redactHeader(header http.Header) http.Header { + if header == nil { + return header + } + safeHeader := make(http.Header, len(header)) + for key, values := range header { + if !strings.Contains(strings.ToLower(key), "key") { + for _, value := range values { + safeHeader.Add(key, value) + } + continue + } + safeHeader.Add(strings.ToLower(key), "") + } + return safeHeader +} diff --git a/test/fakeintake/server/redact_test.go b/test/fakeintake/server/redact_test.go new file mode 100644 index 0000000000000..f93610c35100b --- /dev/null +++ b/test/fakeintake/server/redact_test.go @@ -0,0 +1,46 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +// TODO investigate flaky unit tests on windows +//go:build !windows + +package server + +import ( + _ "embed" + "net/http" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRedactHeader(t *testing.T) { + header := http.Header{ + "Foo": []string{"bar"}, + "Key": []string{"AAAAAAA"}, + "appkEy": []string{"BBBBBBB"}, + "other-KeY": []string{"CCCCCCC", "DDDDDDD"}, + } + redactedHeader := redactHeader(header) + expectedHeader := http.Header{ + "Foo": []string{"bar"}, + "Key": []string{""}, + "Appkey": []string{""}, + "Other-Key": []string{""}, + } + expectedKeys := []string{} + for key, expectedValues := range expectedHeader { + redactedValues := redactedHeader[key] + assert.Equal(t, expectedValues, redactedValues, "unexpected value at key %s", key) + expectedKeys = append(expectedKeys, key) + } + redactedKeys := []string{} + for key, redactedValues := range redactedHeader { + expectedValues := expectedHeader[key] + assert.Equal(t, expectedValues, redactedValues, "unexpected value at key %s", key) + redactedKeys = append(redactedKeys, key) + } + assert.Equal(t, len(expectedKeys), len(redactedKeys), "unexpected length in keys") +} diff --git a/test/fakeintake/server/server.go b/test/fakeintake/server/server.go index da1ac29805f90..ee4cd8e523d48 100644 --- a/test/fakeintake/server/server.go +++ b/test/fakeintake/server/server.go @@ -343,7 +343,7 @@ func (fi *Server) handleDatadogRequest(w http.ResponseWriter, req *http.Request) return } - log.Printf("Handling Datadog %s request to %s, header %v", req.Method, req.URL.Path, req.Header) + log.Printf("Handling Datadog %s request to %s, header %v", req.Method, req.URL.Path, redactHeader(req.Header)) switch req.Method { case http.MethodPost: @@ -423,6 +423,7 @@ func (fi *Server) handleDatadogPostRequest(w http.ResponseWriter, req *http.Requ err = fi.store.AppendPayload(req.URL.Path, payload, encoding, fi.clock.Now().UTC()) if err != nil { + log.Printf("Error adding payload to store: %v", err) response := buildErrorResponse(err) writeHTTPResponse(w, response) return nil diff --git a/test/integration/corechecks/docker/main_test.go b/test/integration/corechecks/docker/main_test.go index 954c6f7bd15bc..a4bb2d9dec566 100644 --- a/test/integration/corechecks/docker/main_test.go +++ b/test/integration/corechecks/docker/main_test.go @@ -18,7 +18,8 @@ import ( "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" compcfg "github.com/DataDog/datadog-agent/comp/core/config" - "github.com/DataDog/datadog-agent/comp/core/log/logimpl" + logdef "github.com/DataDog/datadog-agent/comp/core/log/def" + logfx "github.com/DataDog/datadog-agent/comp/core/log/fx" "github.com/DataDog/datadog-agent/comp/core/secrets" "github.com/DataDog/datadog-agent/comp/core/tagger" "github.com/DataDog/datadog-agent/comp/core/tagger/taggerimpl" @@ -128,8 +129,8 @@ func setup() (workloadmeta.Component, error) { "", compcfg.WithConfigMissingOK(true))), compcfg.Module(), fx.Supply(optional.NewNoneOption[secrets.Component]()), - fx.Supply(logimpl.ForOneShot("TEST", "info", false)), - logimpl.Module(), + fx.Supply(logdef.ForOneShot("TEST", "info", false)), + logfx.Module(), fx.Supply(workloadmeta.NewParams()), collectors.GetCatalog(), workloadmetafx.Module(), diff --git a/test/integration/serverless_perf/compute.sh b/test/integration/serverless_perf/compute.sh index eaf6f91971043..c8421c24a84c9 100755 --- a/test/integration/serverless_perf/compute.sh +++ b/test/integration/serverless_perf/compute.sh @@ -2,7 +2,7 @@ set -o pipefail -STARTUP_TIME_THRESHOLD=20 +STARTUP_TIME_THRESHOLD=25 calculate_median() { local sorted=($(printf "%s\n" "${@}" | sort -n)) diff --git a/test/new-e2e/pkg/environments/aws/kubernetes/eks.go b/test/new-e2e/pkg/environments/aws/kubernetes/eks.go index 1979357b2e069..42e15142639f1 100644 --- a/test/new-e2e/pkg/environments/aws/kubernetes/eks.go +++ b/test/new-e2e/pkg/environments/aws/kubernetes/eks.go @@ -163,6 +163,9 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi linuxNodeRole, }, ServiceRole: clusterRole, + ProviderCredentialOpts: &eks.KubeconfigOptionsArgs{ + ProfileName: pulumi.String(awsEnv.Profile()), + }, }, pulumi.Timeouts(&pulumi.CustomTimeouts{ Create: "30m", Update: "30m", @@ -172,9 +175,16 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi return err } + kubeConfig, err := cluster.GetKubeconfig(ctx, &eks.ClusterGetKubeconfigArgs{ + ProfileName: pulumi.String(awsEnv.Profile()), + }) + if err != nil { + return err + } + // Building Kubernetes provider eksKubeProvider, err := kubernetes.NewProvider(awsEnv.Ctx(), awsEnv.Namer.ResourceName("k8s-provider"), &kubernetes.ProviderArgs{ - Kubeconfig: cluster.KubeconfigJson, + Kubeconfig: kubeConfig, EnableServerSideApply: pulumi.BoolPtr(true), DeleteUnreachable: pulumi.BoolPtr(true), }, awsEnv.WithProviders(config.ProviderAWS)) @@ -184,7 +194,7 @@ func EKSRunFunc(ctx *pulumi.Context, env *environments.Kubernetes, params *Provi // Filling Kubernetes component from EKS cluster comp.ClusterName = cluster.EksCluster.Name() - comp.KubeConfig = cluster.KubeconfigJson + comp.KubeConfig = kubeConfig comp.KubeProvider = eksKubeProvider // Create configuration for POD subnets if any diff --git a/test/new-e2e/tests/agent-platform/common/bound-port/boundport.go b/test/new-e2e/tests/agent-platform/common/bound-port/boundport.go index 3b3e1660fed77..ff2b79d9183c6 100644 --- a/test/new-e2e/tests/agent-platform/common/bound-port/boundport.go +++ b/test/new-e2e/tests/agent-platform/common/bound-port/boundport.go @@ -16,6 +16,10 @@ import ( componentos "github.com/DataDog/test-infra-definitions/components/os" ) +var ( + ssUserRegex = regexp.MustCompile(`(\("(?P[^"]+)",pid=(?P\d+),fd=\d+\),?)`) +) + // BoundPort represents a port that is bound to a process type BoundPort interface { LocalAddress() string @@ -133,25 +137,26 @@ func FromSs(output string) ([]BoundPort, error) { // EXAMPLE: users:(("node",pid=15296,fd=18)) program := parts[5] - re := regexp.MustCompile(`users:\(\("(?P[^"]+)",pid=(?P\d+),fd=\d+\)\)`) - matches := re.FindStringSubmatch(program) - if len(matches) != 3 { - return nil, fmt.Errorf("unexpected ss output: %s", line) - } - processIndex := re.SubexpIndex("Process") - pidIndex := re.SubexpIndex("PID") - process := matches[processIndex] - pid, err := strconv.Atoi(matches[pidIndex]) - if err != nil { - return nil, fmt.Errorf("unexpected ss output: %s", line) + matches := ssUserRegex.FindAllStringSubmatch(program, -1) + processIndex := ssUserRegex.SubexpIndex("Process") + pidIndex := ssUserRegex.SubexpIndex("PID") + for _, match := range matches { + if len(match) < 3 { + return nil, fmt.Errorf("unexpected ss output: %s", line) + } + process := match[processIndex] + pid, err := strconv.Atoi(match[pidIndex]) + if err != nil { + return nil, fmt.Errorf("unexpected ss output: %s", line) + } + + ports = append(ports, &boundPort{ + localAddress: address, + localPort: port, + processName: process, + pid: pid, + }) } - - ports = append(ports, &boundPort{ - localAddress: address, - localPort: port, - processName: process, - pid: pid, - }) } return ports, nil } diff --git a/test/new-e2e/tests/agent-platform/common/bound-port/boundport_test.go b/test/new-e2e/tests/agent-platform/common/bound-port/boundport_test.go new file mode 100644 index 0000000000000..e999d5dfe4079 --- /dev/null +++ b/test/new-e2e/tests/agent-platform/common/bound-port/boundport_test.go @@ -0,0 +1,67 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. +// Package boundport provides utilies for getting bound port information +package boundport + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFromSS(t *testing.T) { + testCases := []struct { + name string + input string + expected []BoundPort + }{ + { + name: "single process on port 22", + input: `LISTEN 0 4096 *:22 *:* users:(("sshd",pid=726,fd=3))`, + expected: []BoundPort{ + &boundPort{ + localAddress: "*", + localPort: 22, + processName: "sshd", + pid: 726, + }, + }, + }, + { + name: "multiple processes on port 22", + input: `LISTEN 0 4096 *:22 *:* users:(("sshd",pid=726,fd=3),("systemd",pid=1,fd=118))`, + expected: []BoundPort{ + &boundPort{ + localAddress: "*", + localPort: 22, + processName: "sshd", + pid: 726, + }, + &boundPort{ + localAddress: "*", + localPort: 22, + processName: "systemd", + pid: 1, + }, + }, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + res, err := FromSs(tc.input) + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(tc.expected), len(res), "expected and result length should be equal") + for i := range tc.expected { + assert.Equal(t, tc.expected[i].LocalPort(), res[i].LocalPort()) + assert.Equal(t, tc.expected[i].LocalAddress(), res[i].LocalAddress()) + assert.Equal(t, tc.expected[i].Process(), res[i].Process()) + assert.Equal(t, tc.expected[i].PID(), res[i].PID()) + } + }) + } +} diff --git a/test/new-e2e/tests/agent-platform/platforms/platforms.json b/test/new-e2e/tests/agent-platform/platforms/platforms.json index dcdea63046f7a..29959651ba647 100644 --- a/test/new-e2e/tests/agent-platform/platforms/platforms.json +++ b/test/new-e2e/tests/agent-platform/platforms/platforms.json @@ -20,7 +20,8 @@ "ubuntu-20-04": "ami-0ffb8e1df897204c4", "ubuntu-22-04": "ami-02e99c6973f5a184a", "ubuntu-23-04": "ami-09c5d86a379ab69a5", - "ubuntu-23-10": "ami-0949b45ef274e55a1" + "ubuntu-23-10": "ami-0949b45ef274e55a1", + "ubuntu-24-04": "ami-0bfc0c74356d9b384" }, "arm64": { "ubuntu-18-04": "ami-002c0df0f55a14f82", @@ -29,7 +30,8 @@ "ubuntu-21-04": "ami-044f0ceee8e885e87", "ubuntu-22-04": "ami-0f1d4680f8b775120", "ubuntu-23-04": "ami-05fab5da2d7fe0b0b", - "ubuntu-23-10": "ami-0dea732dd5f1da0a8" + "ubuntu-23-10": "ami-0dea732dd5f1da0a8", + "ubuntu-24-04": "ami-0e879a1b306fffb22" } }, "amazonlinux": { diff --git a/test/new-e2e/tests/agent-shared-components/api/api_test.go b/test/new-e2e/tests/agent-shared-components/api/api_test.go index f8c6842d4a7e2..000ecde2c9476 100644 --- a/test/new-e2e/tests/agent-shared-components/api/api_test.go +++ b/test/new-e2e/tests/agent-shared-components/api/api_test.go @@ -6,10 +6,13 @@ package api import ( + "bytes" _ "embed" "encoding/json" "fmt" + "io" "net" + "net/http" "net/url" "path/filepath" "strconv" @@ -55,31 +58,24 @@ func (endpointInfo *agentEndpointInfo) url() *url.URL { } } -func (endpointInfo *agentEndpointInfo) fetchCommand(authtoken string) string { - data := endpointInfo.data - if len(endpointInfo.data) == 0 { - data = "{}" +func (endpointInfo *agentEndpointInfo) httpRequest(authtoken string) (*http.Request, error) { + payload := bytes.NewBufferString(endpointInfo.data) + + req, err := http.NewRequest(endpointInfo.method, endpointInfo.url().String(), payload) + if err != nil { + return nil, err } - // -s: silent so we don't show auth token in output - // -k: allow insecure server connections since we self-sign the TLS cert - // -H: add a header with the auth token - // -X: http request method - // -d: request data (json) - return fmt.Sprintf( - `curl -s -k -H "authorization: Bearer %s" -X %s "%s" -d "%s"`, - authtoken, - endpointInfo.method, - endpointInfo.url().String(), - data, - ) + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authtoken)) + return req, nil } func (v *apiSuite) TestDefaultAgentAPIEndpoints() { testcases := []struct { agentEndpointInfo - name string - assert func(*assert.CollectT, agentEndpointInfo, string) + name string + expectedCode int + assert func(*assert.CollectT, agentEndpointInfo, *http.Response) }{ { name: "version", @@ -90,15 +86,20 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Version struct { Major int } var have Version - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) want := Version{Major: 7} - assert.Equal(ct, have, want, "%s %s returned: %s, wanted: %v", e.method, e.endpoint, resp, want) + assert.Equal(ct, have, want, "%s %s returned: %s, wanted: %v", e.method, e.endpoint, body, want) }, }, { @@ -110,9 +111,14 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { want := v.Env().Agent.Client.Hostname() - assert.Contains(ct, resp, want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, resp, want) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + assert.Contains(ct, string(body), want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, string(body), want) }, }, { @@ -124,14 +130,19 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type HealthCheck struct { Healthy []string } var have HealthCheck - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.Healthy, "%s %s returned: %s, expected Healthy not to be empty", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.Healthy, "%s %s returned: %s, expected Healthy not to be empty", e.method, e.endpoint, body) }, }, { @@ -143,10 +154,15 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { // this returns text output want := `api_key: '*******` - assert.Contains(ct, resp, want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, resp, want) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + assert.Contains(ct, string(body), want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, string(body), want) }, }, { @@ -158,14 +174,19 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Config struct { DogstatsdCaptureDuration interface{} `json:"dogstatsd_capture_duration"` } var have Config - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.DogstatsdCaptureDuration, "%s %s returned: %s, expected dogstatsd_capture_duration key", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.DogstatsdCaptureDuration, "%s %s returned: %s, expected dogstatsd_capture_duration key", e.method, e.endpoint, body) }, }, { @@ -177,15 +198,20 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, + expectedCode: 200, // TODO: can we set up a jmx environment - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Config struct { JMXConfig interface{} `json:"configs"` } var have Config - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.Equal(ct, have.JMXConfig, make(map[string]interface{}), "%s %s returned: %s, expected jmx configs to be empty", e.method, e.endpoint, resp) + assert.Equal(ct, have.JMXConfig, make(map[string]interface{}), "%s %s returned: %s, expected jmx configs to be empty", e.method, e.endpoint, body) }, }, { @@ -197,14 +223,19 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Config struct { Checks []interface{} `json:"configs"` } var have Config - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.Checks, "%s %s returned: %s, expected \"configs\" checks to be present", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.Checks, "%s %s returned: %s, expected \"configs\" checks to be present", e.method, e.endpoint, body) }, }, { @@ -216,9 +247,14 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "POST", data: "{}", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { want := `/tmp/datadog-agent-` - assert.Contains(ct, resp, want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, resp, want) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + assert.Contains(ct, string(body), want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, string(body), want) }, }, { @@ -230,9 +266,14 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { want := `secrets feature is not enabled` - assert.Contains(ct, resp, want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, resp, want) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + assert.Contains(ct, string(body), want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, string(body), want) }, }, { @@ -244,15 +285,20 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, + expectedCode: 200, // TODO: there isn't a configuration to enable this, it needs a dedicated environment setup - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Tagger struct { Entities interface{} `json:"entities"` } var have Tagger - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.Equal(ct, have.Entities, make(map[string]interface{}), "%s %s returned: %s, expected entities to be empty", e.method, e.endpoint, resp) + assert.Equal(ct, have.Entities, make(map[string]interface{}), "%s %s returned: %s, expected entities to be empty", e.method, e.endpoint, body) }, }, { @@ -264,14 +310,19 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "GET", data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Workload struct { Entities interface{} `json:"entities"` } var have Workload - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.Equal(ct, have.Entities, make(map[string]interface{}), "%s %s returned: %s, expected entities to be empty", e.method, e.endpoint, resp) + assert.Equal(ct, have.Entities, make(map[string]interface{}), "%s %s returned: %s, expected entities to be empty", e.method, e.endpoint, body) }, }, { @@ -281,16 +332,21 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { port: agentCmdPort, endpoint: "/agent/metadata/gohai", method: "GET", - data: "{}", + data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Metadata struct { Gohai interface{} `json:"gohai"` } var have Metadata - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.Gohai, "%s %s returned: %s, expected \"gohai\" fields to be present", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.Gohai, "%s %s returned: %s, expected \"gohai\" fields to be present", e.method, e.endpoint, body) }, }, { @@ -300,16 +356,21 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { port: agentCmdPort, endpoint: "/agent/metadata/v5", method: "GET", - data: "{}", + data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Metadata struct { Version string `json:"agentVersion"` } var have Metadata - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.Version, "%s %s returned: %s, expected \"agentVersion\" to be present", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.Version, "%s %s returned: %s, expected \"agentVersion\" to be present", e.method, e.endpoint, body) }, }, { @@ -319,16 +380,21 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { port: agentCmdPort, endpoint: "/agent/metadata/inventory-checks", method: "GET", - data: "{}", + data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Metadata struct { Check interface{} `json:"check_metadata"` } var have Metadata - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.Check, "%s %s returned: %s, expected \"check_metadata\" fields to be present", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.Check, "%s %s returned: %s, expected \"check_metadata\" fields to be present", e.method, e.endpoint, body) }, }, { @@ -338,16 +404,21 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { port: agentCmdPort, endpoint: "/agent/metadata/inventory-agent", method: "GET", - data: "{}", + data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Metadata struct { Agent interface{} `json:"agent_metadata"` } var have Metadata - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.Agent, "%s %s returned: %s, expected \"agent_metadata\" fields to be present", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.Agent, "%s %s returned: %s, expected \"agent_metadata\" fields to be present", e.method, e.endpoint, body) }, }, { @@ -357,16 +428,21 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { port: agentCmdPort, endpoint: "/agent/metadata/inventory-host", method: "GET", - data: "{}", + data: "", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Metadata struct { Host interface{} `json:"host_metadata"` } var have Metadata - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotEmpty(ct, have.Host, "%s %s returned: %s, expected \"host_metadata\" fields to be present", e.method, e.endpoint, resp) + assert.NotEmpty(ct, have.Host, "%s %s returned: %s, expected \"host_metadata\" fields to be present", e.method, e.endpoint, body) }, }, // TODO: figure out how to make this work @@ -390,14 +466,19 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { method: "POST", data: "{}", }, - assert: func(ct *assert.CollectT, e agentEndpointInfo, resp string) { + expectedCode: 200, + assert: func(ct *assert.CollectT, e agentEndpointInfo, resp *http.Response) { type Diagnose struct { Suite string `json:"SuiteName"` } var have []Diagnose - err := json.Unmarshal([]byte(resp), &have) + + body, err := io.ReadAll(resp.Body) + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) assert.NoError(ct, err) - assert.NotZero(ct, len(have), "%s %s returned: %s, expected diagnose suites to be present", e.method, e.endpoint, resp) + assert.NotZero(ct, len(have), "%s %s returned: %s, expected diagnose suites to be present", e.method, e.endpoint, body) }, }, } @@ -406,15 +487,20 @@ func (v *apiSuite) TestDefaultAgentAPIEndpoints() { authtokenContent := v.Env().RemoteHost.MustExecute("sudo cat " + authTokenFilePath) authtoken := strings.TrimSpace(authtokenContent) + hostHTTPClient := v.Env().RemoteHost.NewHTTPClient() for _, testcase := range testcases { - cmd := testcase.fetchCommand(authtoken) - host := v.Env().RemoteHost v.T().Run(fmt.Sprintf("API - %s test", testcase.name), func(t *testing.T) { + req, err := testcase.httpRequest(authtoken) + assert.NoError(t, err, "failed to create request") + require.EventuallyWithT(t, func(ct *assert.CollectT) { - resp, err := host.Execute(cmd) - if assert.NoError(ct, err) { - testcase.assert(ct, testcase.agentEndpointInfo, resp) - } + resp, err := hostHTTPClient.Do(req) + assert.NoError(ct, err, "failed to send request") + defer resp.Body.Close() + + endpoint := testcase.agentEndpointInfo + assert.Equal(ct, testcase.expectedCode, resp.StatusCode, "%s %s returned: %s, expected %s", endpoint.method, endpoint.endpoint, resp.StatusCode, testcase.expectedCode) + testcase.assert(ct, endpoint, resp) }, 2*time.Minute, 10*time.Second) }) } @@ -459,13 +545,20 @@ hostname: ENC[hostname]` authtokenContent := v.Env().RemoteHost.MustExecute("sudo cat " + authTokenFilePath) authtoken := strings.TrimSpace(authtokenContent) - cmd := e.fetchCommand(authtoken) + req, err := e.httpRequest(authtoken) + assert.NoError(v.T(), err, "failed to create request") + host := v.Env().RemoteHost + hostHTTPClient := host.NewHTTPClient() require.EventuallyWithT(v.T(), func(ct *assert.CollectT) { - resp, err := v.Env().RemoteHost.Execute(cmd) - if assert.NoError(ct, err) { - assert.Contains(ct, resp, want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, resp, want) - } + resp, err := hostHTTPClient.Do(req) + assert.NoError(ct, err, "failed to send request") + + body, err := io.ReadAll(resp.Body) + resp.Body.Close() + assert.NoError(ct, err, "failed to read body from request") + + assert.Contains(ct, string(body), want, "%s %s returned: %s, wanted: %s", e.method, e.endpoint, body, want) }, 2*time.Minute, 10*time.Second) } @@ -499,8 +592,10 @@ log_level: debug authtokenContent := v.Env().RemoteHost.MustExecute("sudo cat " + authTokenFilePath) authtoken := strings.TrimSpace(authtokenContent) - cmd := e.fetchCommand(authtoken) + req, err := e.httpRequest(authtoken) + assert.NoError(v.T(), err, "failed to create request") host := v.Env().RemoteHost + hostHTTPClient := host.NewHTTPClient() require.EventuallyWithT(v.T(), func(ct *assert.CollectT) { type Workload struct { @@ -508,11 +603,16 @@ log_level: debug } var have Workload - resp, err := host.Execute(cmd) - if assert.NoError(ct, err) { - err := json.Unmarshal([]byte(resp), &have) - assert.NoError(ct, err) - assert.NotEmpty(ct, have.Entities, "%s %s returned: %s, expected workload entities to be present", e.method, e.endpoint, resp) - } + resp, err := hostHTTPClient.Do(req) + assert.NoError(ct, err, "failed to send request") + + body, err := io.ReadAll(resp.Body) + resp.Body.Close() + assert.NoError(ct, err, "failed to read body from request") + + err = json.Unmarshal(body, &have) + assert.NoError(ct, err) + + assert.NotEmpty(ct, have.Entities, "%s %s returned: %s, expected workload entities to be present", e.method, e.endpoint, body) }, 2*time.Minute, 10*time.Second) } diff --git a/test/new-e2e/tests/cws/windows_test.go b/test/new-e2e/tests/cws/windows_test.go index 33bcaee6de5ba..4533befdf1653 100644 --- a/test/new-e2e/tests/cws/windows_test.go +++ b/test/new-e2e/tests/cws/windows_test.go @@ -96,6 +96,7 @@ func (a *agentSuiteWindows) Test01RulesetLoadedDefaultRC() { } func (a *agentSuiteWindows) Test02Selftests() { + time.Sleep(time.Minute) assert.EventuallyWithT(a.T(), func(c *assert.CollectT) { testSelftestsEvent(c, a, func(event *api.SelftestsEvent) { assert.Contains(c, event.SucceededTests, "datadog_agent_cws_self_test_rule_windows_create_file", "missing selftest result") @@ -162,6 +163,9 @@ func (a *agentSuiteWindows) Test03CreateFileSignal() { assert.Contains(c, output, securityStartLog, "security-agent could not start") }, 30*time.Second, 1*time.Second) + // Wait for host tags + time.Sleep(3 * time.Minute) + // Download policies apiKey, err := runner.GetProfile().SecretStore().Get(parameters.APIKey) require.NoError(a.T(), err, "Could not get API KEY") diff --git a/test/new-e2e/tests/installer/host/host.go b/test/new-e2e/tests/installer/host/host.go index f7e0d8e28ebf3..83554f6cb1679 100644 --- a/test/new-e2e/tests/installer/host/host.go +++ b/test/new-e2e/tests/installer/host/host.go @@ -399,6 +399,23 @@ func (h *Host) getSystemdUnitInfo() map[string]SystemdUnitInfo { return units } +// SetUmask set the default umask for commands +func (h *Host) SetUmask(mask string) (oldmask string) { + oldmask = strings.TrimSpace(h.remote.MustExecute("umask")) + if _, err := h.remote.Execute("cat ~/.bashrc | grep umask"); err != nil { + // There are different default bashrc files for different distros. In some cases + // the umask must be at the first instruction as other instructions are skipped for non-interactive sessions + // and in others the umask must be at the bottom as it is overridden somewhere in the bashrc file. + // Thus we set it in both places. + h.remote.MustExecute(fmt.Sprintf("echo 'umask %s' | cat - ~/.bashrc > temp && mv temp ~/.bashrc", mask)) + h.remote.MustExecute(fmt.Sprintf("echo 'umask %s' | tee -a ~/.bashrc", mask)) + } else { + h.remote.MustExecute(fmt.Sprintf("sed -i -E 's/umask %s/umask %s/g' ~/.bashrc", oldmask, mask)) + } + h.remote.MustExecute(fmt.Sprintf("umask | grep -q %s", mask)) // Correctness check + return oldmask +} + // LoadState is the load state of a systemd unit. type LoadState string diff --git a/test/new-e2e/tests/installer/package_apm_inject_test.go b/test/new-e2e/tests/installer/package_apm_inject_test.go index 4694f4c3c4c3d..931fc8996c4c7 100644 --- a/test/new-e2e/tests/installer/package_apm_inject_test.go +++ b/test/new-e2e/tests/installer/package_apm_inject_test.go @@ -414,6 +414,12 @@ func (s *packageApmInjectSuite) TestDefaultPackageVersion() { s.host.AssertPackagePrefix("datadog-apm-library-python", "2") } +func (s *packageApmInjectSuite) TestInstallWithUmask() { + oldmask := s.host.SetUmask("0027") + defer s.host.SetUmask(oldmask) + s.TestInstall() +} + func (s *packageApmInjectSuite) assertTraceReceived(traceID uint64) { found := assert.Eventually(s.T(), func() bool { tracePayloads, err := s.Env().FakeIntake.Client().GetTraces() diff --git a/test/new-e2e/tests/installer/package_installer_test.go b/test/new-e2e/tests/installer/package_installer_test.go index 502f219bb7459..d20648b8bae71 100644 --- a/test/new-e2e/tests/installer/package_installer_test.go +++ b/test/new-e2e/tests/installer/package_installer_test.go @@ -121,3 +121,9 @@ func (s *packageInstallerSuite) TestUpdateInstallerOCI() { version = s.Env().RemoteHost.MustExecute("/opt/datadog-packages/datadog-installer/stable/bin/installer/installer version") assert.NotEqual(s.T(), "7.55.0-installer-0.2.1\n", version) } + +func (s *packageInstallerSuite) TestInstallWithUmask() { + oldmask := s.host.SetUmask("0027") + defer s.host.SetUmask(oldmask) + s.TestInstall() +} diff --git a/test/new-e2e/tests/installer/upgrade_scenario_test.go b/test/new-e2e/tests/installer/upgrade_scenario_test.go index e632ee14a6e9d..da5a263f9e3c9 100644 --- a/test/new-e2e/tests/installer/upgrade_scenario_test.go +++ b/test/new-e2e/tests/installer/upgrade_scenario_test.go @@ -356,6 +356,13 @@ func (s *upgradeScenarioSuite) TestInstallerAgentFailure() { s.executeInstallerGoldenPath() } +func (s *upgradeScenarioSuite) TestUpgradeSuccessfulWithUmask() { + oldmask := s.host.SetUmask("0027") + defer s.host.SetUmask(oldmask) + + s.TestUpgradeSuccessful() +} + func (s *upgradeScenarioSuite) startExperiment(pkg packageName, version string) (string, error) { cmd := fmt.Sprintf("sudo datadog-installer daemon start-experiment %s %s > /tmp/start_experiment.log 2>&1", pkg, version) s.T().Logf("Running start command: %s", cmd) diff --git a/test/new-e2e/tests/process/k8s_test.go b/test/new-e2e/tests/process/k8s_test.go index e898e01f337a6..ff83538291f3d 100644 --- a/test/new-e2e/tests/process/k8s_test.go +++ b/test/new-e2e/tests/process/k8s_test.go @@ -153,7 +153,9 @@ func (s *K8sSuite) TestManualContainerCheck() { func execProcessAgentCheck(t *testing.T, cluster *components.KubernetesCluster, check string) string { agent := getAgentPod(t, cluster.Client()) - cmd := fmt.Sprintf("DD_LOG_LEVEL=OFF process-agent check %s -w 5s --json", check) + // set the wait interval as workloadmeta takes some time to initialize for container data + // https://datadoghq.atlassian.net/browse/PROCS-4157 + cmd := fmt.Sprintf("DD_LOG_LEVEL=OFF process-agent check %s -w 10s --json", check) // The log level needs to be overridden as the pod has an ENV var set. // This is so we get just json back from the check diff --git a/test/otel/dependencies.go.fake b/test/otel/dependencies.go.fake index 02cc8a350842d..ae0196cb1915d 100644 --- a/test/otel/dependencies.go.fake +++ b/test/otel/dependencies.go.fake @@ -8,7 +8,7 @@ package main import ( "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface" - "github.com/DataDog/datadog-agent/comp/core/log" + log "github.com/DataDog/datadog-agent/comp/core/log/def" "github.com/DataDog/datadog-agent/comp/otelcol/logsagentpipeline" "github.com/DataDog/datadog-agent/comp/otelcol/logsagentpipeline/logsagentpipelineimpl" "github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/exporter/datadogexporter" diff --git a/test/otel/go.mod.fake b/test/otel/go.mod.fake index 614181a00cd73..71d585a3a394f 100644 --- a/test/otel/go.mod.fake +++ b/test/otel/go.mod.fake @@ -9,7 +9,8 @@ replace ( github.com/DataDog/datadog-agent/comp/core/flare/builder => ./../../comp/core/flare/builder github.com/DataDog/datadog-agent/comp/core/flare/types => ./../../comp/core/flare/types github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface => ./../../comp/core/hostname/hostnameinterface - github.com/DataDog/datadog-agent/comp/core/log => ./../../comp/core/log + github.com/DataDog/datadog-agent/comp/core/log/def => ./../../comp/core/log/def + github.com/DataDog/datadog-agent/comp/core/log/mock => ./../../comp/core/log/mock github.com/DataDog/datadog-agent/comp/core/secrets => ./../../comp/core/secrets github.com/DataDog/datadog-agent/comp/core/telemetry => ./../../comp/core/telemetry github.com/DataDog/datadog-agent/comp/def => ./../../comp/def @@ -89,7 +90,7 @@ replace ( require ( github.com/DataDog/datadog-agent/comp/core/config v0.56.0-rc.1 github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface v0.56.0-rc.1 - github.com/DataDog/datadog-agent/comp/core/log v0.56.0-rc.1 + github.com/DataDog/datadog-agent/comp/core/log/def v0.56.0-rc.1 github.com/DataDog/datadog-agent/comp/otelcol/logsagentpipeline v0.56.0-rc.1 github.com/DataDog/datadog-agent/comp/otelcol/logsagentpipeline/logsagentpipelineimpl v0.56.0-rc.1 github.com/DataDog/datadog-agent/comp/otelcol/otlp/components/exporter/datadogexporter v0.56.0-rc.1