variables:
  BENCHMARKS_CI_IMAGE: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/benchmarking-platform:go-go-prof-app-and-serviceextensions-and-haproxy-0003

.on-graphite-never: &on-graphite-never
  if: $CI_COMMIT_BRANCH =~ /^graphite-base\/.*$/
  when: never

.on-mq-never: &on-mq-never
  if: $CI_COMMIT_BRANCH =~ /^mq-working-branch\/.*$/
  when: never

.on-main-or-release-always-and-not-interruptible: &on-main-or-release-always-and-not-interruptible
  if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release-v[0-9]+.*$/
  when: always
  interruptible: false

.macrobenchmarks-rules: &macrobenchmarks-rules
  - <<: *on-graphite-never
  - <<: *on-mq-never
  - <<: *on-main-or-release-always-and-not-interruptible
  - when: manual
    interruptible: true

.pre-release-performance-quality-gates-rules: &pre-release-performance-quality-gates-rules
  - <<: *on-graphite-never
  - <<: *on-mq-never
  - <<: *on-main-or-release-always-and-not-interruptible
  # Unlike in "main" or release branches, in development branches there's
  # no strict requirement to run the check unconditionally with "when: always".
  - interruptible: true

#
# Default macrobenchmarks
# 

.benchmarks-default:
  stage: macrobenchmarks
  needs: []
  tags: ["runner:apm-k8s-same-cpu"]
  timeout: 1h
  rules: *macrobenchmarks-rules
  # If you have a problem with Gitlab cache, see Troubleshooting section in Benchmarking Platform docs
  image: $BENCHMARKS_CI_IMAGE
  script:
    - git clone --branch go/go-prof-app https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/benchmarking-platform platform && cd platform
    - "./generate-run-plan-and-run-benchmarks.sh"
  artifacts:
    name: "artifacts"
    when: always
    paths:
      - platform/artifacts/
    expire_in: 3 months
  variables:
    DD_INSTRUMENTATION_TELEMETRY_ENABLED: "true"
    DD_INSTRUMENTATION_TELEMETRY_DEBUG: "true"
    GOEXPERIMENT: "synctest" # TODO: remove once go1.25 is the minimum supported version
    # Used to build the SUT
    GO_PROF_APP_BUILD_VARIANT: "candidate"
    DD_TRACE_GO_VERSION: "latest"

    LOAD_TESTS: io-bound,cpu-bound,cgo-cpu-bound,cpu-bound-x-client-ip-enabled
    PARALLELIZE: "true"

  # Workaround: Currently we're not running the benchmarks on every PR, but GitHub still shows them as pending.
  # By marking the benchmarks as allow_failure, this should go away. (This workaround should be removed once the
  # benchmarks get changed to run on every PR)
  # Note: Setting allow_failure to false does not stop check-slo-breaches
  # from running if benchmarks fail, since it has "when: always". It can be 
  # safely set to false once the workaround is removed.
  allow_failure: true

  retry:
    max: 2
    when:
      - unknown_failure
      - data_integrity_failure
      - runner_system_failure
      - scheduler_failure
      - api_failure


#
# Please read next before updating Go version in this file!
#
# In order to update Go version, you need to include it in benchmarks Docker image first:
# 1. Update version in Dockerfile https://github.com/DataDog/benchmarking-platform/blob/go/go-prof-app/container/Dockerfile#L5
# 2. Rebuild image in Gitlab CI (build-images CI job in https://gitlab.ddbuild.io/DataDog/apm-reliability/benchmarking-platform/-/pipelines?page=1&scope=all&ref=go%2Fgo-prof-app)
#

.go-stable-benchmarks:
  extends: .benchmarks-default
  variables:
    GO_VERSION: "1.25.0"

.go-oldstable-benchmarks:
  extends: .benchmarks-default
  variables:
    GO_VERSION: "1.24.6"

#
# Specific macrobenchmark configurations extending 
# .go-(stable|oldstable)-benchmarks are below
#

go-oldstable-baseline:
  extends: .go-oldstable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "false"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-oldstable-only-trace:
  extends: .go-oldstable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-oldstable-only-trace-with-runtime-metrics:
  extends: .go-oldstable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
    DD_RUNTIME_METRICS_ENABLED: "true"

go-oldstable-only-profile:
  extends: .go-oldstable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "false"
    ENABLE_PROFILING: "true"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-oldstable-profile-trace:
  extends: .go-oldstable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "true"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-oldstable-trace-asm:
  extends: .go-oldstable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "true"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-oldstable-profile-trace-asm:
  extends: .go-oldstable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "true"
    ENABLE_APPSEC: "true"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-stable-baseline:
  extends: .go-stable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "false"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-stable-only-trace:
  extends: .go-stable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-stable-only-trace-with-runtime-metrics:
  extends: .go-stable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
    DD_RUNTIME_METRICS_ENABLED: "true"

go-stable-only-profile:
  extends: .go-stable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "false"
    ENABLE_PROFILING: "true"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-stable-profile-trace:
  extends: .go-stable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "true"
    ENABLE_APPSEC: "false"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-stable-trace-asm:
  extends: .go-stable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "false"
    ENABLE_APPSEC: "true"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

go-stable-profile-trace-asm:
  extends: .go-stable-benchmarks
  variables:
    ENABLE_DDPROF: "false"
    ENABLE_TRACING: "true"
    ENABLE_PROFILING: "true"
    ENABLE_APPSEC: "true"
    DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"

# This repository is using pre-release performance quality gates.
# On release branches, verify that the latest CI pipeline passed the check-slo-breaches job.
# If any SLO is breached, your release will be blocked.
# If bypassing is necessary, see https://datadoghq.atlassian.net/wiki/x/8YFzMwE for more details.
check-slo-breaches:
  extends: .check-slo-breaches
  stage: gates
  needs: [
    "go-oldstable-baseline",
    "go-oldstable-only-trace",
    "go-oldstable-only-trace-with-runtime-metrics",
    "go-oldstable-only-profile",
    "go-oldstable-profile-trace",
    "go-oldstable-trace-asm",
    "go-oldstable-profile-trace-asm",
    "go-stable-baseline",
    "go-stable-only-trace",
    "go-stable-only-trace-with-runtime-metrics",
    "go-stable-only-profile",
    "go-stable-profile-trace",
    "go-stable-trace-asm",
    "go-stable-profile-trace-asm",
  ]
  rules: *pre-release-performance-quality-gates-rules
  variables:
    DDOCTOSTS_POLICY: "gitlab.github-access.slo-change-tracking.contents-read"
    ARTIFACTS_DIR: "platform/artifacts"
    SLO_FILE: ".gitlab/bp-runner.fail-on-breach.yml"
  artifacts:
    name: "artifacts"
    when: always
    paths:
      - platform/artifacts/
    expire_in: 3 months

include:
  - project: 'DataDog/benchmarking-platform-tools'
    file: 'images/templates/gitlab/check-slo-breaches.template.yml'
  - project: 'DataDog/benchmarking-platform-tools'
    file: 'images/templates/gitlab/notify-slo-breaches.template.yml'

notify-slo-breaches:
  extends: .notify-slo-breaches
  stage: gates
  needs: ["check-slo-breaches"]
  rules: *pre-release-performance-quality-gates-rules
  variables:
    CHANNEL: "guild-dd-trace-go-notifications"

#
# Macrobenchmarks for Service Extensions (using Envoy External Processing)
#

.benchmarks-serviceextensions:
  stage: macrobenchmarks
  needs: []
  tags: ["runner:apm-k8s-same-cpu"]
  timeout: 1h
  rules: *macrobenchmarks-rules
  # If you have a problem with Gitlab cache, see Troubleshooting section in Benchmarking Platform docs
  image: $BENCHMARKS_CI_IMAGE
  script:
    - git clone --branch go/go-prof-app https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/benchmarking-platform platform && cd platform
    - bp-runner bp-runner.envoy_serviceextension.yml --debug
  artifacts:
    name: "artifacts"
    when: always
    paths:
      - platform/artifacts-se/
    expire_in: 3 months
  variables:
    GO_VERSION: "1.25.0" # It needs to be at the latest stable release
    ARTIFACTS_DIR: "./artifacts-se"
    SERVICE_EXTENSION: "true"

  # Workaround: Currently we're not running the benchmarks on every PR, but GitHub still shows them as pending.
  # By marking the benchmarks as allow_failure, this should go away. (This workaround should be removed once the
  # benchmarks get changed to run on every PR)
  allow_failure: true

  retry:
    max: 2
    when:
      - unknown_failure
      - data_integrity_failure
      - runner_system_failure
      - scheduler_failure
      - api_failure

# Scenario with external processor, webserver without tracer
se-ext_proc-appsec:
  extends: .benchmarks-serviceextensions
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: true
    EXT_PROC_BODY: false
    TRACER: false

se-ext_proc-body-appsec:
  extends: .benchmarks-serviceextensions
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: true
    TRACER: false

se-ext_proc-only-tracing:
  extends: .benchmarks-serviceextensions
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: false
    EXT_PROC_BODY: false
    TRACER: false

se-ext_proc-body-only-tracing:
  extends: .benchmarks-serviceextensions
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: false
    TRACER: false

# Scenarios without external processor, webserver with tracer
se-tracer-no-ext_proc-appsec:
  extends: .benchmarks-serviceextensions
  variables:
    EXT_PROC: false
    ENABLE_APPSEC: true
    EXT_PROC_BODY: false
    TRACER: true

se-tracer-no-ext_proc-only-tracing:
  extends: .benchmarks-serviceextensions
  variables:
    EXT_PROC: false
    ENABLE_APPSEC: false
    EXT_PROC_BODY: false
    TRACER: true

# Scenario without tracer, only direct connection through envoy to the webserver
se-no-tracer-no-ext_proc:
  extends: .benchmarks-serviceextensions
  variables:
    EXT_PROC: false
    EXT_PROC_BODY: false
    TRACER: false

#
# Macro benchmarks for HAProxy
# (using Stream Processing Offload Agent)
#
.benchmarks-haproxy_spoa:
  stage: macrobenchmarks
  needs: []
  tags: ["runner:apm-k8s-same-cpu"]
  timeout: 1h
  rules: *macrobenchmarks-rules
  # If you have a problem with Gitlab cache, see Troubleshooting section in Benchmarking Platform docs
  image: $BENCHMARKS_CI_IMAGE
  script:
    - git clone --branch go/go-prof-app https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/benchmarking-platform platform && cd platform
    - bp-runner bp-runner.haproxy_spoa.yml --debug
  artifacts:
    name: "artifacts"
    when: always
    paths:
      - platform/artifacts-haproxy_spoa/
    expire_in: 3 months
  variables:
    GO_VERSION: "1.25.0" # It needs to be at the latest stable release
    ARTIFACTS_DIR: "./artifacts-haproxy_spoa"
    HAPROXY_SPOA: "true"

  # Workaround: Currently we're not running the benchmarks on every PR, but GitHub still shows them as pending.
  # By marking the benchmarks as allow_failure, this should go away. (This workaround should be removed once the
  # benchmarks get changed to run on every PR)
  allow_failure: true

  retry:
    max: 2
    when:
      - unknown_failure
      - data_integrity_failure
      - runner_system_failure
      - scheduler_failure
      - api_failure

# Scenario with SPOA, webserver without tracer
haproxy-spoa-appsec:
  extends: .benchmarks-haproxy_spoa
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: true
    EXT_PROC_BODY: false
    TRACER: false

haproxy-spoa-body-appsec:
  extends: .benchmarks-haproxy_spoa
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: true
    TRACER: false

haproxy-spoa-only-tracing:
  extends: .benchmarks-haproxy_spoa
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: false
    EXT_PROC_BODY: false
    TRACER: false

haproxy-spoa-body-only-tracing:
  extends: .benchmarks-haproxy_spoa
  variables:
    EXT_PROC: true
    ENABLE_APPSEC: false
    TRACER: false

# Scenarios without SPOA, webserver with tracer
haproxy-tracer-no-spoa-appsec:
  extends: .benchmarks-haproxy_spoa
  variables:
    EXT_PROC: false
    ENABLE_APPSEC: true
    EXT_PROC_BODY: false
    TRACER: true

haproxy-tracer-no-spoa-only-tracing:
  extends: .benchmarks-haproxy_spoa
  variables:
    EXT_PROC: false
    ENABLE_APPSEC: false
    EXT_PROC_BODY: false
    TRACER: true

# Scenario without tracer, only direct connection through HAProxy to the webserver
haproxy-no-tracer-no-spoa:
  extends: .benchmarks-haproxy_spoa
  variables:
    EXT_PROC: false
    EXT_PROC_BODY: false
    TRACER: false
